Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 10a6942

Browse files
myronmarstonJonRowe
authored andcommitted
Merge pull request #2635 from rspec/myron/fix-shared-context-metadata-bug
Assign `@metadata` before we apply derived metadata hooks.
1 parent 8709aab commit 10a6942

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

Changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Bug Fixes:
88
* When defining `let` methods that overwrite an existing method, prevent
99
a warning being issued by removing the old definition. (Jon Rowe, #2593)
1010
* Prevent warning on Ruby 2.6.0-rc1 (Keiji Yoshimi, #2582)
11-
* Fix `config.define_derived_metadata` so that it supports cascades.
12-
(Myron Marston, #2630).
11+
* Fix `config.define_derived_metadata` so that it supports cascades and
12+
is not triggered until metadata has been assigned to the example or
13+
example group (Myron Marston, #2630, #2635).
1314

1415
### 3.8.0 / 2018-08-04
1516
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.7.1...v3.8.0)

lib/rspec/core/example.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,13 @@ def initialize(example_group_class, description, user_metadata, example_block=ni
203203
description, example_block
204204
)
205205

206+
config = RSpec.configuration
207+
config.apply_derived_metadata_to(@metadata)
208+
206209
# This should perhaps be done in `Metadata::ExampleHash.create`,
207210
# but the logic there has no knowledge of `RSpec.world` and we
208211
# want to keep it that way. It's easier to just assign it here.
209-
@metadata[:last_run_status] = RSpec.configuration.last_run_statuses[id]
212+
@metadata[:last_run_status] = config.last_run_statuses[id]
210213

211214
@example_group_instance = @exception = nil
212215
@clock = RSpec::Core::Time

lib/rspec/core/example_group.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,15 @@ def self.set_it_up(description, args, registration_collection, &example_group_bl
424424
superclass.method(:next_runnable_index_for),
425425
description, *args, &example_group_block
426426
)
427+
428+
config = RSpec.configuration
429+
config.apply_derived_metadata_to(@metadata)
430+
427431
ExampleGroups.assign_const(self)
428432

429433
@currently_executing_a_context_hook = false
430434

431-
RSpec.configuration.configure_group(self)
435+
config.configure_group(self)
432436
end
433437

434438
# @private

lib/rspec/core/metadata.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def populate
136136

137137
populate_location_attributes
138138
metadata.update(user_metadata)
139-
RSpec.configuration.apply_derived_metadata_to(metadata)
140139
end
141140

142141
private

spec/rspec/core/shared_example_group_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,21 @@ def self.bar; 'bar'; end
286286
expect(host_ex_metadata[:foo]).to eq :host
287287
expect(shared_ex_metadata[:foo]).to eq :shared
288288
end
289+
290+
it "applies metadata from the shared group to the including group, when the shared group itself is loaded and included via metadata" do
291+
RSpec.configure do |config|
292+
config.when_first_matching_example_defined(:controller) do
293+
define_top_level_shared_group("controller support", :capture_logging) { }
294+
295+
config.include_context "controller support", :controller
296+
end
297+
end
298+
299+
group = RSpec.describe("group", :controller)
300+
ex = group.it
301+
302+
expect(ex.metadata).to include(:controller => true, :capture_logging => true)
303+
end
289304
end
290305

291306
context "when the group is included via `config.include_context` and matching metadata" do

0 commit comments

Comments
 (0)