Permalink
Browse files

Pass in step_definitions for on_tag

Sometimes I may want to call a method, do something about the
step_definitions in the on_tag hook.
  • Loading branch information...
1 parent 823985d commit 344283f1a4a47827ed45ab716b9d68e83a95bf03 @ywen2 ywen2 committed May 10, 2012
Showing with 15 additions and 3 deletions.
  1. +2 −2 lib/spinach/hooks.rb
  2. +13 −1 test/spinach/hooks_test.rb
View
@@ -147,10 +147,10 @@ class Hooks
# # change capybara driver
# end
def on_tag(tag)
- before_scenario do |scenario|
+ before_scenario do |scenario, step_definitions|
tags = scenario.tags
next unless tags.any?
- yield(scenario) if tags.include? tag.to_s
+ yield(scenario, step_definitions) if tags.include? tag.to_s
end
end
end
View
@@ -31,16 +31,28 @@
let(:scenario) do
stub(tags: ['javascript', 'capture'])
end
+ let(:step_definitions) do
+ stub(something: "step_definitions")
+ end
it "calls the block if the scenario includes the tag" do
assertion = false
subject.on_tag('javascript') do
assertion = true
end
- subject.run_before_scenario(scenario)
+ subject.run_before_scenario(scenario, step_definitions)
assertion.must_equal true
end
+ it "passes in both scenario and step_definitions" do
+ assertion = false
+ subject.on_tag('javascript') do |scenario, step_definitions|
+ assertion = step_definitions.something
+ end
+ subject.run_before_scenario(scenario, step_definitions)
+ assertion.must_equal "step_definitions"
+ end
+
it "doesn't call the block if the scenario doesn't include the tag" do
assertion = false
subject.on_tag('screenshot') do

0 comments on commit 344283f

Please sign in to comment.