[rspec-users] Not sure why let is not doing the same thing as traditional test

Nadal node.js99 at gmail.com
Tue Nov 2 21:55:18 EDT 2010


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.


More information about the rspec-users mailing list