diff --git a/Changelog.md b/Changelog.md index 009cb16d73..53c6ee2ac3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,14 @@ +### 3.8.2 / 2019-06-29 +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.8.1...v3.8.2) + +Bug Fixes: + +* Fix `config.define_derived_metadata` so that cascades are not triggered + until metadata has been assigned to the example or example group + (Myron Marston, #2635). + ### 3.8.1 / 2019-06-13 -[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.8.0...3-8-maintenance) +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.8.0...3.8.1) Bug Fixes: diff --git a/lib/rspec/core/example.rb b/lib/rspec/core/example.rb index e4706aea52..ffa54a5ca7 100644 --- a/lib/rspec/core/example.rb +++ b/lib/rspec/core/example.rb @@ -203,10 +203,13 @@ def initialize(example_group_class, description, user_metadata, example_block=ni description, example_block ) + config = RSpec.configuration + config.apply_derived_metadata_to(@metadata) + # This should perhaps be done in `Metadata::ExampleHash.create`, # but the logic there has no knowledge of `RSpec.world` and we # want to keep it that way. It's easier to just assign it here. - @metadata[:last_run_status] = RSpec.configuration.last_run_statuses[id] + @metadata[:last_run_status] = config.last_run_statuses[id] @example_group_instance = @exception = nil @clock = RSpec::Core::Time diff --git a/lib/rspec/core/example_group.rb b/lib/rspec/core/example_group.rb index 3bd48b170e..97765956f6 100644 --- a/lib/rspec/core/example_group.rb +++ b/lib/rspec/core/example_group.rb @@ -424,11 +424,15 @@ def self.set_it_up(description, args, registration_collection, &example_group_bl superclass.method(:next_runnable_index_for), description, *args, &example_group_block ) + + config = RSpec.configuration + config.apply_derived_metadata_to(@metadata) + ExampleGroups.assign_const(self) @currently_executing_a_context_hook = false - RSpec.configuration.configure_group(self) + config.configure_group(self) end # @private diff --git a/lib/rspec/core/metadata.rb b/lib/rspec/core/metadata.rb index e20a3b5ef3..1a06ec55d4 100644 --- a/lib/rspec/core/metadata.rb +++ b/lib/rspec/core/metadata.rb @@ -136,7 +136,6 @@ def populate populate_location_attributes metadata.update(user_metadata) - RSpec.configuration.apply_derived_metadata_to(metadata) end private diff --git a/lib/rspec/core/version.rb b/lib/rspec/core/version.rb index 1fc6750d4c..9a258fb796 100644 --- a/lib/rspec/core/version.rb +++ b/lib/rspec/core/version.rb @@ -3,7 +3,7 @@ module Core # Version information for RSpec Core. module Version # Current version of RSpec Core, in semantic versioning format. - STRING = '3.8.1' + STRING = '3.8.2' end end end diff --git a/spec/rspec/core/shared_example_group_spec.rb b/spec/rspec/core/shared_example_group_spec.rb index 3bf96d1079..6b897c395e 100644 --- a/spec/rspec/core/shared_example_group_spec.rb +++ b/spec/rspec/core/shared_example_group_spec.rb @@ -286,6 +286,21 @@ def self.bar; 'bar'; end expect(host_ex_metadata[:foo]).to eq :host expect(shared_ex_metadata[:foo]).to eq :shared end + + it "applies metadata from the shared group to the including group, when the shared group itself is loaded and included via metadata" do + RSpec.configure do |config| + config.when_first_matching_example_defined(:controller) do + define_top_level_shared_group("controller support", :capture_logging) { } + + config.include_context "controller support", :controller + end + end + + group = RSpec.describe("group", :controller) + ex = group.it + + expect(ex.metadata).to include(:controller => true, :capture_logging => true) + end end context "when the group is included via `config.include_context` and matching metadata" do