Skip to content
This repository

example group: register global hooks before individual config #845

Merged
merged 2 commits into from about 1 year ago

4 participants

Michi Huber Jon Rowe Myron Marston Tejas Dinkar
This page is out of date. Refresh to see the latest.
2  lib/rspec/core/example_group.rb
@@ -287,8 +287,8 @@ def self.set_it_up(*args)
287 287
         args << build_metadata_hash_from(args)
288 288
         args.unshift(symbol_description) if symbol_description
289 289
         @metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
290  
-        world.configure_group(self)
291 290
         hooks.register_globals(self, RSpec.configuration.hooks)
  291
+        world.configure_group(self)
292 292
       end
293 293
 
294 294
       # @private
20  spec/rspec/core/shared_context_spec.rb
@@ -34,6 +34,26 @@
34 34
     expect(after_all_hook).to be_true
35 35
   end
36 36
 
  37
+  it "runs the before each hooks in configuration before those of the shared context" do
  38
+    ordered_hooks = []
  39
+    RSpec.configure do |c|
  40
+      c.before(:each) { ordered_hooks << "config" }
  41
+    end
  42
+
  43
+    shared_context("before each stuff", :example => :before_each_hook_order) do
  44
+      before(:each) { ordered_hooks << "shared_context"}
  45
+    end
  46
+
  47
+    group = RSpec::Core::ExampleGroup.describe :example => :before_each_hook_order do
  48
+      before(:each) { ordered_hooks << "example_group" }
  49
+      example {}
  50
+    end
  51
+
  52
+    group.run
  53
+
  54
+    expect(ordered_hooks).to be == ["config", "shared_context", "example_group"]
  55
+  end
  56
+
37 57
   it "supports let" do
38 58
     shared = Module.new do
39 59
       extend RSpec::SharedContext
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.