Nadal
2010-Nov-03 01:55 UTC
[rspec-users] Not sure why let is not doing the same thing as traditional test
Here is my test which passes. before do @page = Factory(:page) @note = Factory(:note, :page => @page, :title => ''super cool'') end it ''has size 1'' do @page.notes.size.should == 1 end I read rspec book and wanted to use let. Here is my implementation. And it fails let(:page) { Factory(:page) } let(:note) { Factory(:note, :page => page, :title => ''super cool'') } it ''has size 1'' do page.notes.size.should == 1 end In the log I noticed that when I switched to using let then no note record is being created. Here is relevant gem file group :development, :test do gem ''mongrel'' gem ''capistrano'', ">= 2.5.19" gem ''capistrano-ext'' gem "factory_girl_rails" gem "database_cleaner" gem "shoulda" gem "rspec-rails", ">= 2.0.1" gem "cucumber-rails", ">= 0.3.2" gem "capybara", "= 0.4.0" gem "launchy" gem "redgreen" gem "faker" gem "mongrel" end Is let lazy? It seems since I am not using note the record is not being created. The book said that output is memoized. Nothing more than that.
Justin Ko
2010-Nov-03 02:13 UTC
[rspec-users] Not sure why let is not doing the same thing as traditional test
I''m under the weather so I won''t be able to give you a thorough answer. #let - The block is executed when you call it. #let! - The block is "wrapped" in a before(:each) filter. So, you want to use #let! On Nov 2, 7:55?pm, Nadal <node.j... at gmail.com> wrote:> Here is my test which passes. > > ? ?before do > ? ? ? ? @page = Factory(:page) > ? ? ? ? @note = Factory(:note, :page => @page, :title => ''super cool'') > ? ? ? end > ? ? ? it ''has size 1'' do > ? ? ? ? @page.notes.size.should == 1 > ? ? ? end > > I read rspec book and wanted to use let. Here is my implementation. > And it fails > > ? ? ?let(:page) { Factory(:page) } > ? ? ? let(:note) { Factory(:note, :page => page, :title => ''super > cool'') } > ? ? ? it ''has size 1'' do > ? ? ? ? page.notes.size.should == 1 > ? ? ? end > > In the log I noticed that when I switched to using let then no note > record is being created. > > Here is relevant gem file > > group :development, :test do > ? gem ''mongrel'' > ? gem ''capistrano'', ">= 2.5.19" > ? gem ''capistrano-ext'' > > ? gem "factory_girl_rails" > > ? gem "database_cleaner" > ? gem "shoulda" > > ? gem "rspec-rails", ">= 2.0.1" > ? gem "cucumber-rails", ">= 0.3.2" > ? gem "capybara", "= 0.4.0" > ? gem "launchy" > ? gem "redgreen" > ? gem "faker" > ? gem "mongrel" > end > > Is let lazy? It seems since I am not using note the record is not > being created. > > The book said that output is memoized. Nothing more than that. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Nadal
2010-Nov-03 08:52 UTC
[rspec-users] Not sure why let is not doing the same thing as traditional test
That worked. Thanks a lot. Wish you speedy recovery Justin. take care. On Nov 2, 10:13?pm, Justin Ko <jko... at gmail.com> wrote:> I''m under the weather so I won''t be able to give you a thorough > answer. > > #let - The block is executed when you call it. > #let! - The block is "wrapped" in a before(:each) filter. > > So, you want to use #let! > > On Nov 2, 7:55?pm, Nadal <node.j... at gmail.com> wrote: > > > > > > > > > Here is my test which passes. > > > ? ?before do > > ? ? ? ? @page = Factory(:page) > > ? ? ? ? @note = Factory(:note, :page => @page, :title => ''super cool'') > > ? ? ? end > > ? ? ? it ''has size 1'' do > > ? ? ? ? @page.notes.size.should == 1 > > ? ? ? end > > > I read rspec book and wanted to use let. Here is my implementation. > > And it fails > > > ? ? ?let(:page) { Factory(:page) } > > ? ? ? let(:note) { Factory(:note, :page => page, :title => ''super > > cool'') } > > ? ? ? it ''has size 1'' do > > ? ? ? ? page.notes.size.should == 1 > > ? ? ? end > > > In the log I noticed that when I switched to using let then no note > > record is being created. > > > Here is relevant gem file > > > group :development, :test do > > ? gem ''mongrel'' > > ? gem ''capistrano'', ">= 2.5.19" > > ? gem ''capistrano-ext'' > > > ? gem "factory_girl_rails" > > > ? gem "database_cleaner" > > ? gem "shoulda" > > > ? gem "rspec-rails", ">= 2.0.1" > > ? gem "cucumber-rails", ">= 0.3.2" > > ? gem "capybara", "= 0.4.0" > > ? gem "launchy" > > ? gem "redgreen" > > ? gem "faker" > > ? gem "mongrel" > > end > > > Is let lazy? It seems since I am not using note the record is not > > being created. > > > The book said that output is memoized. Nothing more than that. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users