I'm doing railstutorial, now chapter 11.
why this error?
WARNING: let declaration
another_user
accessed in abefore(:all)
hook at:
/Users/xxx/Documents/rails_projects/sample_app_2/spec/requests/micropost_pages_spec.rb:49:in `block (4 levels) in 'This is deprecated behavior that will not be supported in RSpec 3.
let
andsubject
declarations are not intended to be called in abefore(:all)
hook, as they exist to define state that is reset between each example, whilebefore(:all)
exists to define state that is shared across examples in an example group. WARNING: let declarationanother_user
accessed in abefore(:all)
hook at:
/Users/xxx/Documents/rails_projects/sample_app_2/spec/requests/micropost_pages_spec.rb:49:in `block (4 levels) in '
my file is here. enter link description here
You're getting the error because you have the following code:
let(:another_user) { FactoryGirl.create(:user) }
before(:all) do
10.times { FactoryGirl.create(:micropost, user: another_user, content: "Foooo") }
end
in which your before(:all)
code makes use of the another_user
variable, defined by let
.
You can eliminate the warning by changing your before(:all)
call to:
before(:all) do
user = FactoryGirl.create(:user)
10.times { FactoryGirl.create(:micropost, user: user, content: "Foooo") }
end
Note that the tutorial as currently defined at railstutorial.org does not include any code which violates the restriction.