RSpec makes a mistake

In my specifications / models / user _spec.rb I have the following:

require 'spec_helper' describe User do before { 5.times { FactoryGirl.create(:sport) } } before { let(:user) { FactoryGirl.create(:user) } } ... end 

But when running my user_spec.rb, I get this error:

 Failure/Error: before { let(:user) { FactoryGirl.create(:user) } } NoMethodError: undefined method `let' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001043033b0> 

Which is strange, because my specifications worked so far, and I haven’t changed anything ...

Here is my gemfile: https://gist.github.com/4690919

Here is my spec_helper.rb: https://gist.github.com/4690935

I would be grateful for any help, thanks

+6
source share
1 answer

I don't know why it worked before, but you should never have a let block inside a before block. It should be called from the describe (or context ) block, for example:

 describe User do let(:user) { FactoryGirl.create(:user) } before { 5.times { FactoryGirl.create(:sport) } } .... 

See the documentation for more details.

+17
source

All Articles