On Sep 30, 2011, at 2:48 PM, Patrick J. Collins wrote:
> Am I correct in understanding that the point of using let is that it can
> minimize database calls due to memoization?
>
> describe "#something" do
>
> let(:something) = Something.groovy_scope
>
> it "does x" do
> something.first.x.should have_coolness
> end
>
> it "does y" do
> something.first.y.should_not have_coolness
> end
>
> end
>
> vs.
>
> describe "#something" do
>
> before :each do
> @something = Something.groovy_scope
> end
>
> it "does x" do
> @something.first.x.should_not have_coolness
> end
>
> it "does y" do
> @something.first.y.should_not have_coolness
> end
>
> end
>
> ...
>
> Is that the proper usage?
Proper usage, sure, but the memoization is only within each example - not
across examples. That way you can do this:
let(:thing) { Thing.new }
it "does something" do
thing.blah
thing.whatever
thing.yet_again
end
In that case each reference to thing returns the same object.
Make sense?
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users