Permalink
Browse files

added let!, which is not lazy like let. workaround for ordering

side-effects with let
  • Loading branch information...
1 parent 05196bd commit 01f9e475a2cf9442bbb9ed6d0c1735b790115b45 @njackson njackson committed with dchelimsky Apr 12, 2010
Showing with 24 additions and 0 deletions.
  1. +5 −0 lib/rspec/core/let.rb
  2. +19 −0 spec/rspec/core/example_group_spec.rb
View
@@ -9,6 +9,11 @@ def let(name, &block)
__memoized[name] ||= instance_eval(&block)
end
end
+
+ def let!(name, &block)
+ let(name, &block)
+ before { __send__(name) }
+ end
end
module InstanceMethods
@@ -339,6 +339,25 @@ def count
end
end
+ describe "#let!" do
+ let!(:creator) do
+ class Creator
+ @count = 0
+ def self.count
+ @count += 1
+ end
+ end
+ end
+
+ it "evaluates the value non-lazily" do
+ lambda { Creator.count }.should_not raise_error
+ end
+
+ it "does not interfere between tests" do
+ Creator.count.should == 1
+ end
+ end
+
describe "#around" do
around(:each) do |example|

0 comments on commit 01f9e47

Please sign in to comment.