Permalink
Browse files

Fix inverted Given! issue.

  • Loading branch information...
1 parent a951728 commit 967a498f4ea412b8a61626d979aed8dfdb67e5a0 @jimweirich committed Sep 4, 2012
Showing with 19 additions and 0 deletions.
  1. +12 −0 examples/integration/given_spec.rb
  2. +7 −0 lib/rspec/given/extensions.rb
@@ -49,3 +49,15 @@
Then { value.should == :ok }
end
end
+
+describe "Non-Lazy Givens" do
+ Given(:info) { [] }
+
+ When { info << :when }
+
+ context "inner" do
+ Given!(:a) { info << :given; "A VALUE" }
+ Then { info.should == [:given, :when] }
+ end
+
+end
@@ -46,6 +46,12 @@ def _rg_invariants # :nodoc:
@_rg_invariants ||= []
end
+ # Trigger the evaluation of a Given! block by referencing its
+ # name.
+ def _rg_trigger_given(name) # :nodoc:
+ Proc.new { send(name) }
+ end
+
# *DEPRECATED:*
#
# The Scenario command is deprecated. Using Scenario in a spec
@@ -95,6 +101,7 @@ def Given(*args, &block)
# Given!(:name) { ... code ... }
def Given!(name, &block)
let!(name, &block)
+ _rg_givens << _rg_trigger_given(name)
end
# Declare the code that is under test.

0 comments on commit 967a498

Please sign in to comment.