Michael Hartl的Ruby on Rails教程。第8.29章中的测试失败

时间:2012-06-06 13:16:28

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

我是通过Hartl工作的新手。到了第8章的结尾,当我检查我的浏览器登录/注销时,每件事情都是AOK。但是,当我运行此测试时:

$ bundle exec spec spec/

返回

sis-macbook-pro:sample_app Lagaspi$ bundle exec rspec spec/ 
..............................F

Failures:

1) User pages signup with valid information after saving the user 
 Failure/Error: it { should have_link('Sign out') }
   expected link "Sign out" to return something
 # ./spec/requests/user_pages_spec.rb:48:in `block (5 levels) in <top (required)>'

Finished in 0.60715 seconds
31 examples, 1 failure

Failed examples:

rspec ./spec/requests/user_pages_spec.rb:48 # User pages signup with valid information after saving the user 

我有个主意,但我不确定。所以这是我的user_pages_spec.rb文件:

require 'spec_helper'

describe "User pages" do

subject { page }

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 "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" 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
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: "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 }
it { should have_link('Sign out') }
  end
 end
end
end

2 个答案:

答案 0 :(得分:1)

转到http://ruby.railstutorial.org/chapters/sign-up?version=3.2#code-after_save_tests,然后将这些行添加到您的规范中。

答案 1 :(得分:0)

你可以发布你的观点文件吗?没有它,就很难分辨出什么是错的。从我所看到的,它只是说你没有链接。