I am using your excellent tutorial (have worked through 1st ed, 2nd Ed with Blueprint, and now this one). Seeing an error only on Lion which I discovered when I cloned your repo to my MacBook Pro doesn't occur when running these tests. There is a post on StackOverflow but the solution does not work for me. Initially I thought it was my coding as I am modifying to use name instead of email as the login(signin) credential.
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "error messages" do
before { click_button submit }
it { should have_selector('title', text: 'Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('[email protected]') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Sign out') }
end
end
end
My code looks as follows:
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup" do
before { visit user_registration_path }
let(:submit) { "Create User" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "error messages" do
before { click_button submit }
it { should have_selector('title', text: 'User Registration') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
# fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_name('Example User') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
# it { should have_link('Sign out') }
end
end
end
end
The SO link is:
http://stackoverflow.com/questions/9986477/rails-tutorial-chapter-7-exercise-4
I have tried both solutions and am using your git repo which I downloaded today as my reference. I neither does this work. But its only on my iMac running OSX Lion. The other machine where it passes is running Snow Leopard.
Both are under RVM with ruby 1.9.3-p125 and running Rails 3.2.5 as per the Gemfile.
The only way I can get this to work on Lion (for the reference) is changing the following:
let(:user) { User.find_by_email('[email protected]') }
it { should have_selector('title', text: user.name) }
<= change to ('title', text: :user)
<= or
<= ('title', text: user) just user without .name on end of it
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Sign out') }
It passes but I want to make sure its valid and more importantly understand how these are valid. Also why this fails only on my Lion machine.
I tried the SO suggestion of making let(:user) into let(user) but this failed.
Your comment at front says if this doesn't pass then its our machines. But how do I track it down?
If you are thinking of extending your screencasts/pdf I would appreciate some answers to some of the harder exercises, specifically around sessions/cookies.
Having watched the video following redownloading since they were updated, I notice that at the 1h 2mins you have a failure which is caused by not having the click button call, and then following this all the tests pass.
What version of Mac OSX are you running? Given thats the only difference between my two machines I am assuming its related partly to this.
Keep up the great work you do Michael.