2012-06-06 97 views
1

我是通過Hartl工作的新手。到了第8章的最後,當我檢查我的瀏覽器登錄/註銷時,每件事情都顯得AOK。然而,當我運行這個測試:Ruby on Rails教程Michael Hartl。第8.29章失敗測試

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

capybara有一個名爲save_and_open_page的方法,您可以在「it」之前插入,以便在測試運行者看到它時打開頁面。使這樣的調試更容易一些。 –

回答

0

你能發佈你的視圖文件嗎?沒有它,很難說出什麼問題。從我所看到的情況來看,它只是說你沒有鏈接。

+0

很抱歉,您沒有權限查看該文件嗎?哪裏是? –

+0

對不起也不明白水豚評語!我是新來的! –

+0

請有人可以幫忙嗎? –

相關問題