-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Update fixture support #1372
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
Merged
Merged
Update fixture support #1372
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11ba7f7
Fix load order :bug:
cupakromer b78356f
Update spec to remove hooks.
cupakromer b81f6de
Add specs around existing settings
cupakromer fd00f38
Prep for removal of fixture support globally.
cupakromer 98c161f
Use default `.rspec` configuration.
cupakromer 278972d
Note updates in changelog.
cupakromer 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 hidden or 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,3 @@ | ||
--color | ||
--warnings | ||
--color | ||
--require spec_helper |
This file contains hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
example_app_generator/spec/__verify_fixture_load_order_spec.rb
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This spec needs to be run before `rails_helper` is loaded to check the issue | ||
RSpec.describe "Verify issue rspec/rspec-rails#1355" do | ||
it "passes" do | ||
expect(1).to eq 1 | ||
end | ||
end | ||
require 'rails_helper' |
This file contains hidden or 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 hidden or 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 hidden or 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,26 +1,233 @@ | ||
require "spec_helper" | ||
require 'rspec/support/spec/in_sub_process' | ||
|
||
RSpec.describe "Configuration" do | ||
|
||
include RSpec::Support::InSubProcess | ||
|
||
subject(:config) { RSpec::Core::Configuration.new } | ||
|
||
describe "configuration" do | ||
before do | ||
@orig_render_views = RSpec.configuration.render_views? | ||
RSpec::Rails.initialize_configuration(config) | ||
end | ||
|
||
it "adds 'vendor/' to the backtrace exclusions" do | ||
expect(config.backtrace_exclusion_patterns).to include(/vendor\//) | ||
end | ||
|
||
it "adds 'lib/rspec/rails' to the backtrace exclusions" do | ||
expect( | ||
config.backtrace_exclusion_patterns | ||
).to include(%r{ lib/rspec/rails }) | ||
end | ||
|
||
shared_examples_for "adds setting" do |accessor, opts| | ||
opts ||= {} | ||
default_value = opts[:default] | ||
alias_setting = opts[:alias_with] | ||
query_method = "#{accessor}?".to_sym | ||
command_method = "#{accessor}=".to_sym | ||
|
||
specify "`##{query_method}` is `#{default_value.inspect}` by default" do | ||
expect(config.send(query_method)).to be(default_value) | ||
end | ||
|
||
describe "`##{command_method}`" do | ||
it "changes `#{query_method}` to the provided value" do | ||
expect { | ||
config.send(command_method, :a_value) | ||
}.to change { config.send(query_method) }.to(:a_value) | ||
end | ||
|
||
it "sets `#{accessor}` to the provided value" do | ||
expect { | ||
config.send(command_method, :a_value) | ||
}.to change { | ||
config.send(accessor) | ||
}.from(default_value).to(:a_value) | ||
end | ||
end | ||
|
||
if alias_setting | ||
specify "`##{alias_setting}` is an alias for `#{accessor}`" do | ||
expect { | ||
config.send(command_method, :a_value) | ||
}.to change { config.send(alias_setting) }.to(:a_value) | ||
end | ||
end | ||
end | ||
|
||
after do | ||
RSpec.configuration.render_views = @orig_render_views | ||
context "adds settings" do | ||
include_examples "adds setting", | ||
:infer_base_class_for_anonymous_controllers, | ||
:default => true | ||
|
||
include_examples "adds setting", | ||
:use_transactional_fixtures, | ||
:alias_with => :use_transactional_examples | ||
|
||
include_examples "adds setting", :use_instantiated_fixtures | ||
|
||
include_examples "adds setting", :global_fixtures | ||
|
||
include_examples "adds setting", :fixture_path | ||
|
||
include_examples "adds setting", :rendering_views | ||
|
||
specify "`#render_views?` is falsey by default" do | ||
expect(config.render_views?).to be_falsey | ||
end | ||
|
||
specify "`#render_views` sets `render_views?` to `true`" do | ||
expect { | ||
config.render_views | ||
}.to change { config.render_views? }.to be(true) | ||
end | ||
|
||
describe "`#render_views=`" do | ||
it "sets `render_views?` to the provided value" do | ||
expect { | ||
config.render_views = false | ||
}.to change { config.render_views? }.from(nil).to(false) | ||
end | ||
|
||
it "sets `render_views` to the provided value" do | ||
expect { | ||
config.render_views = :a_value | ||
}.to change { config.render_views? }.to(:a_value) | ||
end | ||
end | ||
end | ||
|
||
describe "#infer_spec_type_from_file_location!" do | ||
def in_inferring_type_from_location_environment | ||
in_sub_process do | ||
RSpec.configuration.infer_spec_type_from_file_location! | ||
yield | ||
end | ||
end | ||
|
||
shared_examples_for "infers type from location" do |type, location| | ||
it "sets the type to `#{type.inspect}` for file path `#{location}`" do | ||
in_inferring_type_from_location_environment do | ||
allow(RSpec::Core::Metadata).to receive(:relative_path).and_return( | ||
"./#{location}/foos_spec.rb" | ||
) | ||
group = RSpec.describe("Arbitrary Description") | ||
expect(group.metadata).to include(:type => type) | ||
end | ||
end | ||
end | ||
|
||
include_examples "infers type from location", | ||
:controller, | ||
"spec/controllers" | ||
include_examples "infers type from location", :helper, "spec/helpers" | ||
include_examples "infers type from location", :mailer, "spec/mailers" | ||
include_examples "infers type from location", :model, "spec/models" | ||
include_examples "infers type from location", :request, "spec/requests" | ||
include_examples "infers type from location", :request, "spec/integration" | ||
include_examples "infers type from location", :request, "spec/api" | ||
include_examples "infers type from location", :routing, "spec/routing" | ||
include_examples "infers type from location", :view, "spec/views" | ||
include_examples "infers type from location", :feature, "spec/features" | ||
end | ||
|
||
describe "#render_views?" do | ||
it "is false by default" do | ||
expect(RSpec.configuration.render_views?).to be_falsey | ||
it "fixture support is included with metadata `:use_fixtures`" do | ||
in_sub_process do | ||
RSpec.configuration.global_fixtures = [:foo] | ||
RSpec.configuration.fixture_path = "custom/path" | ||
|
||
group = RSpec.describe("Arbitrary Description", :use_fixtures) | ||
|
||
expect(group).to respond_to(:fixture_path) | ||
expect(group.fixture_path).to eq("custom/path") | ||
expect(group.new.respond_to?(:foo, true)).to be(true) | ||
end | ||
end | ||
|
||
describe "#render_views" do | ||
it "sets render_views? to return true" do | ||
RSpec.configuration.render_views = false | ||
RSpec.configuration.render_views | ||
it "metadata `:type => :controller` sets up controller example groups" do | ||
a_controller_class = Class.new | ||
stub_const "SomeController", a_controller_class | ||
|
||
group = RSpec.describe(SomeController, :type => :controller) | ||
|
||
expect(group.controller_class).to be(a_controller_class) | ||
expect(group.new).to be_a(RSpec::Rails::ControllerExampleGroup) | ||
end | ||
|
||
it "metadata `:type => :helper` sets up helper example groups" do | ||
a_helper_module = Module.new | ||
stub_const "SomeHelper", a_helper_module | ||
|
||
group = RSpec.describe(SomeHelper, :type => :helper) | ||
|
||
expect( | ||
group.determine_default_helper_class(:ignored) | ||
).to be(a_helper_module) | ||
expect(group.new).to be_a(RSpec::Rails::HelperExampleGroup) | ||
end | ||
|
||
it "metadata `:type => :model` sets up model example groups" do | ||
a_model_class = Class.new | ||
stub_const "SomeModel", a_model_class | ||
|
||
group = RSpec.describe(SomeModel, :type => :model) | ||
|
||
expect(group.new).to be_a(RSpec::Rails::ModelExampleGroup) | ||
end | ||
|
||
it "metadata `:type => :request` sets up request example groups" do | ||
a_rails_app = double("Rails application") | ||
the_rails_module = double("Rails module", :application => a_rails_app) | ||
stub_const "Rails", the_rails_module | ||
|
||
expect(RSpec.configuration.render_views?).to be_truthy | ||
group = RSpec.describe("Some Request API", :type => :request) | ||
|
||
expect(group.new.app).to be(a_rails_app) | ||
expect(group.new).to be_a(RSpec::Rails::RequestExampleGroup) | ||
end | ||
|
||
it "metadata `:type => :routing` sets up routing example groups" do | ||
a_controller_class = Class.new | ||
stub_const "SomeController", a_controller_class | ||
|
||
group = RSpec.describe(SomeController, :type => :routing) | ||
|
||
expect(group).to respond_to(:routes) | ||
expect(group.new).to be_a(RSpec::Rails::RoutingExampleGroup) | ||
end | ||
|
||
it "metadata `:type => :view` sets up view example groups" do | ||
a_helper_module = Module.new | ||
stub_const "SomeControllerHelper", a_helper_module | ||
|
||
group = RSpec.describe("some_controller/action.html.erb", :type => :view) | ||
|
||
expect(group._default_helper).to be(a_helper_module) | ||
expect(group.new).to be_a(RSpec::Rails::ViewExampleGroup) | ||
end | ||
|
||
it "metadata `:type => :feature` sets up feature example groups" do | ||
a_rails_app = double("Rails application") | ||
the_rails_module = double("Rails module", :application => a_rails_app) | ||
stub_const "Rails", the_rails_module | ||
|
||
group = RSpec.describe("Some feature description", :type => :feature) | ||
example = group.new | ||
|
||
expect(example).to respond_to(:visit) | ||
expect(example).to be_a(RSpec::Rails::FeatureExampleGroup) | ||
end | ||
|
||
if defined?(ActionMailer) | ||
it "metadata `:type => :mailer` sets up mailer example groups" do | ||
a_mailer_class = Class.new | ||
stub_const "SomeMailer", a_mailer_class | ||
group = RSpec.describe(SomeMailer, :type => :mailer) | ||
expect(group.mailer_class).to be(a_mailer_class) | ||
expect(group.new).to be_a(RSpec::Rails::MailerExampleGroup) | ||
end | ||
end | ||
|
||
end |
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.
What does it mean to tag a line of code as deprecated rather than a method or class? Will users see this deprecation in the YARD docs? And why are you including the module above and here?
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.
It was mostly a note for myself and others for 3.99. Line 72 is us globally patching fixture support onto all specs. Due to semver we can't just remove it. So this was a reminder that we need to warn users in 3.99.
I've added fixture support to the
RSpec::Rails:RailsExampleGroup
base module. So all Rails related specs which people expect fixtures to be available for will have it. Line 63 above provides an option for people to selectively include fixture support onto any example/group via metadata.