Ruby 1.9.3, Rails 3.2.2 I'm trying to write an Rpsec (Capybara) to test if my page is properly pluralizing the word "Post". I get an error when running my Rspec that states:
c:/.../my_app/spec/requests/user_pages_spec.rb:58: in `block (3 levels) in ': undefined local variable or method 'user' for ... (NameError)
Here's the relevant test:
describe "profile page" do
let(:user){FactoryGirl.create(:user)}
let!(:m1){FactoryGirl.create(:micropost, user: user, content: "Food")}
let!(:m2){FactoryGirl.create(:micropost, user: user, content: "Bar")}
before {visit user_path(user)}
it {should have_selector('h1', text: user.name)}
it {should have_selector('title', text: user.name)}
describe "pagination" do
before(:all){40.times {FactoryGirl.create(:micropost, user: user, content: "Food")}}
after(:all){User.delete_all}
it {should have_selector('div.pagination')}
end
describe "microposts" do
it {should have_content(m1.content)}
it {should have_content(m2.content)}
it {should have_content(user.microposts.count)}
before do
sign_in user
visit root_path
User.delete_all
end
it "should pluralize post numbers" do
FactoryGirl.create(:micropost, user: user, content: "Food")
page.should have_content("1 micropost")
2.times {FactoryGirl.create(:micropost, user: user, content: "Food")}
page.should have_content("2 microposts")
end
I'm not sure if I'm going about testing for pluralization of posts the right way either, but I'm mainly stumped about why that block can't "see" the users object since the line right after my if statement can see it. if I comment out the if block everything runs fine.