Skip to content

Commit

Permalink
Stop mutating metadata.
Browse files Browse the repository at this point in the history
There's no need to anymore, and it created some surprising
bugs (such as #825: `before(:all)` hooks would not properly
be applied because they were registered before the modules
were included).
  • Loading branch information
myronmarston committed Apr 22, 2014
1 parent 0387ff2 commit 7971bef
Show file tree
Hide file tree
Showing 17 changed files with 6 additions and 70 deletions.
2 changes: 0 additions & 2 deletions lib/rspec/rails/example/controller_example_group.rb
Expand Up @@ -151,8 +151,6 @@ def method_missing(method, *args, &block)
included do
subject { controller }

metadata[:type] = :controller

before do
self.routes = ::Rails.application.routes
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/rails/example/feature_example_group.rb
Expand Up @@ -6,8 +6,6 @@ module FeatureExampleGroup
DEFAULT_HOST = "www.example.com"

included do
metadata[:type] = :feature

app = ::Rails.application
if app.respond_to?(:routes)
include app.routes.url_helpers if app.routes.respond_to?(:url_helpers)
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/rails/example/helper_example_group.rb
Expand Up @@ -30,8 +30,6 @@ def _controller_path(example)
end

included do
metadata[:type] = :helper

before do |example|
controller.controller_path = _controller_path(example)
end
Expand Down
1 change: 0 additions & 1 deletion lib/rspec/rails/example/mailer_example_group.rb
Expand Up @@ -6,7 +6,6 @@ module MailerExampleGroup
include ActionMailer::TestCase::Behavior

included do
metadata[:type] = :mailer
include ::Rails.application.routes.url_helpers
options = ::Rails.configuration.action_mailer.default_url_options
options.each { |key, value| default_url_options[key] = value } if options
Expand Down
4 changes: 0 additions & 4 deletions lib/rspec/rails/example/model_example_group.rb
Expand Up @@ -2,9 +2,5 @@ module RSpec::Rails
module ModelExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup

included do
metadata[:type] = :model
end
end
end
2 changes: 0 additions & 2 deletions lib/rspec/rails/example/request_example_group.rb
Expand Up @@ -13,8 +13,6 @@ def app
end

included do
metadata[:type] = :request

before do
@routes = ::Rails.application.routes
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/rails/example/routing_example_group.rb
Expand Up @@ -30,8 +30,6 @@ def routes(&blk)
end

included do
metadata[:type] = :routing

before do
self.routes = ::Rails.application.routes
end
Expand Down
1 change: 0 additions & 1 deletion lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -142,7 +142,6 @@ def _include_controller_helpers
included do
include ExampleMethods

metadata[:type] = :view
helper(*_default_helpers)

before do
Expand Down
4 changes: 0 additions & 4 deletions spec/rspec/rails/example/controller_example_group_spec.rb
Expand Up @@ -19,10 +19,6 @@ module RSpec::Rails
expect(group.included_modules).to include(RSpec::Rails::Matchers::RoutingMatchers)
end

it "adds :type => :controller to the metadata" do
expect(group.metadata[:type]).to eq(:controller)
end

context "with implicit subject" do
it "uses the controller as the subject" do
controller = double('controller')
Expand Down
8 changes: 0 additions & 8 deletions spec/rspec/rails/example/feature_example_group_spec.rb
Expand Up @@ -5,14 +5,6 @@ module RSpec::Rails
it_behaves_like "an rspec-rails example group mixin", :feature,
'./spec/features/', '.\\spec\\features\\'

it "adds :type => :feature to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include FeatureExampleGroup
end

expect(group.metadata[:type]).to eq(:feature)
end

it "includes Rails route helpers" do
with_isolated_stderr do
Rails.application.routes.draw do
Expand Down
7 changes: 0 additions & 7 deletions spec/rspec/rails/example/helper_example_group_spec.rb
Expand Up @@ -16,13 +16,6 @@ module ::FoosHelper; end
expect(helper_spec.__send__(:_controller_path, example)).to eq("foos")
end

it "adds :type => :helper to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include HelperExampleGroup
end
expect(group.metadata[:type]).to eq(:helper)
end

describe "#helper" do
it "returns the instance of AV::Base provided by AV::TC::Behavior" do
helper_spec = Object.new.extend HelperExampleGroup
Expand Down
7 changes: 0 additions & 7 deletions spec/rspec/rails/example/mailer_example_group_spec.rb
Expand Up @@ -10,12 +10,5 @@ module ::Rails; end

it_behaves_like "an rspec-rails example group mixin", :mailer,
'./spec/mailers/', '.\\spec\\mailers\\'

it "adds :type => :mailer to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include MailerExampleGroup
end
expect(group.metadata[:type]).to eq(:mailer)
end
end
end
7 changes: 0 additions & 7 deletions spec/rspec/rails/example/model_example_group_spec.rb
Expand Up @@ -4,12 +4,5 @@ module RSpec::Rails
describe ModelExampleGroup do
it_behaves_like "an rspec-rails example group mixin", :model,
'./spec/models/', '.\\spec\\models\\'

it "adds :type => :model to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include ModelExampleGroup
end
expect(group.metadata[:type]).to eq(:model)
end
end
end
7 changes: 0 additions & 7 deletions spec/rspec/rails/example/request_example_group_spec.rb
Expand Up @@ -6,12 +6,5 @@ module RSpec::Rails
'./spec/requests/', '.\\spec\\requests\\',
'./spec/integration/', '.\\spec\\integration\\',
'./spec/api/', '.\\spec\\api\\'

it "adds :type => :request to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include RequestExampleGroup
end
expect(group.metadata[:type]).to eq(:request)
end
end
end
7 changes: 0 additions & 7 deletions spec/rspec/rails/example/routing_example_group_spec.rb
Expand Up @@ -5,13 +5,6 @@ module RSpec::Rails
it_behaves_like "an rspec-rails example group mixin", :routing,
'./spec/routing/', '.\\spec\\routing\\'

it "adds :type => :routing to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include RoutingExampleGroup
end
expect(group.metadata[:type]).to eq(:routing)
end

describe "named routes" do
it "delegates them to the route_set" do
group = RSpec::Core::ExampleGroup.describe do
Expand Down
7 changes: 0 additions & 7 deletions spec/rspec/rails/example/view_example_group_spec.rb
Expand Up @@ -5,13 +5,6 @@ module RSpec::Rails
it_behaves_like "an rspec-rails example group mixin", :view,
'./spec/views/', '.\\spec\\views\\'

it "adds :type => :view to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
include ViewExampleGroup
end
expect(group.metadata[:type]).to eq(:view)
end

describe 'automatic inclusion of helpers' do
module ::ThingsHelper; end
module ::Namespaced; module ThingsHelper; end; end
Expand Down
6 changes: 6 additions & 0 deletions spec/support/shared_examples.rb
Expand Up @@ -31,6 +31,12 @@ def define_group_in(path, group_definition)
with_isolated_config(&ex)
end

it "adds does not add `:type` metadata on inclusion" do
mixin = self.mixin
group = RSpec.describe { include mixin }
expect(group.metadata).not_to include(:type)
end

context 'when `infer_spec_type_from_file_location!` is configured' do
before { RSpec.configuration.infer_spec_type_from_file_location! }

Expand Down

0 comments on commit 7971bef

Please sign in to comment.