Topic: spec/requests/user_pages_spec.rb
http://ruby.railstutorial.org/chapters/ -users#top
i am doing this tutorial and i think that many people have done it
i just completed caper 9 and this test should be passing
i don't know if any one would have a clean copy of this file
spec/requests/user_pages_spec.rb
mine looks like
require 'spec_helper'
describe "User pages" do
subject { page }
describe "index" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit users_path
end
it { should have_selector('title', text: 'All users') }
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
let(:first_page) { User.paginate(page: 1) }
let(:second_page) { User.paginate(page: 2) }
it "should list the first page of users" do
first_page.each do |user|
page.should have_selector('li', text: user.name)
end
end
it "should not list the second page of users" do
second_page.each do |user|
page.should_not have_selector('li', text: user.name)
end
end
describe "showing the second page" do
before { visit users_path(page: 2) }
it "should list the second page of users" do
second_page.each do |user|
page.should have_selector('li', text: user.name)
end
end
end
it { should have_link('Next') }
its(:html) { should match('>2</a>') }
it "should list each user" do
User.all[0..2].each do |user|
page.should have_selector('li', text: user.name)
end
end
end
describe "delete links" do
it { should_not have_link('delete') }
describe "as an admin user" do
let(:admin) { FactoryGirl.create(:admin) }
before do
sign_in admin
visit users_path
end
it { should have_link('delete', href: user_path(User.first)) }
it "should be able to delete another user" do
expect { click_link('delete') }.to change(User, :count).by(-1)
end
it { should_not have_link('delete', href: user_path(admin)) }
end
end
it "should list each user" do
User.all.each do |user|
page.should have_selector('li', text: user.name)
end
end
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
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 "after submission" 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: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: user.password
end
it "should create a user 123" 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('user@example.com') }
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
#EDIT USER TEST
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before { visit edit_user_path(user) }
describe "page" do
it { should have_selector('h1', text: "Update your profile") }
it { should have_selector('title', text: "Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
before do
sign_in user
visit edit_user_path(user)
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new@example.com" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_selector('title', text: new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', href: signout_path) }
specify { user.reload.name.should == new_name }
specify { user.reload.email.should == new_email }
end
end
endoutput
bundle exec rspec spec/requests/user_pages_spec.rb
No DRb server is running. Running in local process instead ...
...................FFFF...FFFFFF
Failures:
1) User pages signup with valid information should create a user 123
Failure/Error: fill_in "Confirmation", with: user.password
NameError:
undefined local variable or method `user' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4::Nested_2:0x007fbd8c936e20>
# ./spec/requests/user_pages_spec.rb:123:in `block (4 levels) in <top (required)>'
2) User pages signup with valid information after saving the user
Failure/Error: fill_in "Confirmation", with: user.password
NoMethodError:
undefined method `password' for nil:NilClass
# ./spec/requests/user_pages_spec.rb:123:in `block (4 levels) in <top (required)>'
3) User pages signup with valid information after saving the user
Failure/Error: fill_in "Confirmation", with: user.password
NoMethodError:
undefined method `password' for nil:NilClass
# ./spec/requests/user_pages_spec.rb:123:in `block (4 levels) in <top (required)>'
4) User pages signup with valid information after saving the user
Failure/Error: fill_in "Confirmation", with: user.password
NoMethodError:
undefined method `password' for nil:NilClass
# ./spec/requests/user_pages_spec.rb:123:in `block (4 levels) in <top (required)>'
5) User pages edit with invalid information
Failure/Error: before { click_button "Save changes" }
Capybara::ElementNotFound:
no button with value or id or text 'Save changes' found
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:155:in `block (4 levels) in <top (required)>'
6) User pages edit with valid information
Failure/Error: click_button "Save changes"
Capybara::ElementNotFound:
no button with value or id or text 'Save changes' found
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:173:in `block (4 levels) in <top (required)>'
7) User pages edit with valid information
Failure/Error: click_button "Save changes"
Capybara::ElementNotFound:
no button with value or id or text 'Save changes' found
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:173:in `block (4 levels) in <top (required)>'
8) User pages edit with valid information
Failure/Error: click_button "Save changes"
Capybara::ElementNotFound:
no button with value or id or text 'Save changes' found
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:173:in `block (4 levels) in <top (required)>'
9) User pages edit with valid information
Failure/Error: click_button "Save changes"
Capybara::ElementNotFound:
no button with value or id or text 'Save changes' found
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:173:in `block (4 levels) in <top (required)>'
10) User pages edit with valid information
Failure/Error: click_button "Save changes"
Capybara::ElementNotFound:
no button with value or id or text 'Save changes' found
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:173:in `block (4 levels) in <top (required)>'
Finished in 2.16 seconds
32 examples, 10 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:126 # User pages signup with valid information should create a user 123
rspec ./spec/requests/user_pages_spec.rb:134 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:135 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:136 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:157 # User pages edit with invalid information
rspec ./spec/requests/user_pages_spec.rb:176 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:177 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:178 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:179 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:180 # User pages edit with valid information
Last edited by moiseszaragoza (2012-05-17 15:01:18)