module RSpec::Core::Let::ExampleGroupMethods
def let(name, &block)
- Note: - `let` uses an `||=` conditional that has the potential to
Note: - `let` _can_ enhance readability when used sparingly (1,2, or
def let(name, &block) define_method(name) do __memoized.fetch(name) {|k| __memoized[k] = instance_eval(&block) } end end
def let!(name, &block)
end
end
Thing.count.should eq(1)
thing
it "returns memoized version on first invocation" do
end
Thing.count.should eq(1)
it "is invoked implicitly" do
let!(:thing) { Thing.new }
context "using let!" do
end
end
Thing.count.should eq(1)
thing
it "can be invoked explicitly" do
end
Thing.count.should eq(0)
it "is not invoked implicitly" do
let(:thing) { Thing.new }
context "using let" do
after(:each) { Thing.reset_count }
describe Thing do
end
end
self.class.count += 1
def initialize
end
@count = 0
def self.reset_count
end
@count += val
def self.count=(val)
end
@count ||= 0
def self.count
class Thing
@example
memoized reference to that state.
hook. This serves a dual purpose of setting up state and providing a
Just like `let`, except the block is invoked by an implicit `before`
def let!(name, &block) let(name, &block) before { __send__(name) } end