-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix spec type inferrence #1002
Merged
+256
−349
Merged
Fix spec type inferrence #1002
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33c3c73
Centralized config API extensions into a method.
myronmarston 2fec960
Improve example group mixin testing.
myronmarston 0387ff2
Fix spec type inference.
myronmarston 7971bef
Stop mutating metadata.
myronmarston 7f3032e
No need to mutate metadata for `render_views` state.
myronmarston b458d21
Don't mutate `described_class` metadata.
myronmarston b03ad1e
No need to infer spec type in our spec_helper.
myronmarston 3de5975
Deal with odd 1.9.2 warning on Travis.
myronmarston 88efc45
Update changelog.
myronmarston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
require 'rspec/rails/without_filetype_infer' | ||
require 'rspec/core' | ||
require 'rspec/collection_matchers' | ||
require 'rails/version' | ||
require 'rspec/rails/extensions' | ||
require 'rspec/rails/view_rendering' | ||
require 'rspec/rails/adapters' | ||
require 'rspec/rails/matchers' | ||
require 'rspec/rails/fixture_support' | ||
require 'rspec/rails/example' | ||
require 'rspec/rails/vendor/capybara' | ||
require 'rspec/rails/configuration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,72 @@ | ||
RSpec::configure do |c| | ||
def c.escaped_path(*parts) | ||
Regexp.compile(parts.join('[\\\/]') + '[\\\/]') | ||
end | ||
module RSpec | ||
module Rails | ||
# @private | ||
def self.initialize_configuration(config) | ||
config.backtrace_exclusion_patterns << /vendor\// | ||
config.backtrace_exclusion_patterns << /lib\/rspec\/rails/ | ||
|
||
controller_path_regex = c.escaped_path(%w[spec controllers]) | ||
c.include RSpec::Rails::ControllerExampleGroup, | ||
:type => :controller, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && controller_path_regex =~ file_path | ||
} | ||
|
||
helper_path_regex = c.escaped_path(%w[spec helpers]) | ||
c.include RSpec::Rails::HelperExampleGroup, | ||
:type => :helper, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && helper_path_regex =~ file_path | ||
} | ||
|
||
mailer_path_regex = c.escaped_path(%w[spec mailers]) | ||
if defined?(RSpec::Rails::MailerExampleGroup) | ||
c.include RSpec::Rails::MailerExampleGroup, | ||
:type => :mailer, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && mailer_path_regex =~ file_path | ||
} | ||
end | ||
config.include RSpec::Rails::ControllerExampleGroup, :type => :controller | ||
config.include RSpec::Rails::HelperExampleGroup, :type => :helper | ||
config.include RSpec::Rails::ModelExampleGroup, :type => :model | ||
config.include RSpec::Rails::RequestExampleGroup, :type => :request | ||
config.include RSpec::Rails::RoutingExampleGroup, :type => :routing | ||
config.include RSpec::Rails::ViewExampleGroup, :type => :view | ||
config.include RSpec::Rails::FeatureExampleGroup, :type => :feature | ||
|
||
if defined?(RSpec::Rails::MailerExampleGroup) | ||
config.include RSpec::Rails::MailerExampleGroup, :type => :mailer | ||
end | ||
|
||
# controller settings | ||
config.add_setting :infer_base_class_for_anonymous_controllers, :default => true | ||
|
||
# fixture support | ||
config.include RSpec::Rails::FixtureSupport | ||
config.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples | ||
config.add_setting :use_instantiated_fixtures | ||
config.add_setting :global_fixtures | ||
config.add_setting :fixture_path | ||
|
||
# view rendering settings | ||
# This allows us to expose `render_views` as a config option even though it | ||
# breaks the convention of other options by using `render_views` as a | ||
# command (i.e. render_views = true), where it would normally be used as a | ||
# getter. This makes it easier for rspec-rails users because we use | ||
# `render_views` directly in example groups, so this aligns the two APIs, | ||
# but requires this workaround: | ||
config.add_setting :rendering_views, :default => false | ||
|
||
model_path_regex = c.escaped_path(%w[spec models]) | ||
c.include RSpec::Rails::ModelExampleGroup, | ||
:type => :model, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && model_path_regex =~ file_path | ||
} | ||
|
||
request_path_regex = c.escaped_path(%w[spec (requests|integration|api)]) | ||
c.include RSpec::Rails::RequestExampleGroup, | ||
:type => :request, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && request_path_regex =~ file_path | ||
} | ||
|
||
routing_path_regex = c.escaped_path(%w[spec routing]) | ||
c.include RSpec::Rails::RoutingExampleGroup, | ||
:type => :routing, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && routing_path_regex =~ file_path | ||
} | ||
|
||
view_path_regex = c.escaped_path(%w[spec views]) | ||
c.include RSpec::Rails::ViewExampleGroup, | ||
:type => :view, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && view_path_regex =~ file_path | ||
} | ||
|
||
feature_example_regex = c.escaped_path(%w[spec features]) | ||
c.include RSpec::Rails::FeatureExampleGroup, | ||
:type => :feature, | ||
:file_path => lambda { |file_path, metadata| | ||
metadata[:type].nil? && feature_example_regex =~ file_path | ||
} | ||
def config.render_views=(val) | ||
self.rendering_views = val | ||
end | ||
|
||
def config.render_views | ||
self.rendering_views = true | ||
end | ||
|
||
def config.render_views? | ||
rendering_views | ||
end | ||
|
||
def config.infer_spec_type_from_file_location! | ||
{ | ||
:controller => %w[spec controllers], | ||
:helper => %w[spec helpers], | ||
:mailer => %w[spec mailers], | ||
:model => %w[spec models], | ||
:request => %w[spec (requests|integration|api)], | ||
:routing => %w[spec routing], | ||
:view => %w[spec views], | ||
:feature => %w[spec features] | ||
}.each do |type, dir_parts| | ||
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]') | ||
define_derived_metadata(:file_path => escaped_path) do |metadata| | ||
metadata[:type] ||= type | ||
end | ||
end | ||
end | ||
end | ||
|
||
initialize_configuration RSpec.configuration | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we relying on autoload for these before or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, spotted.