2013-04-10 88 views
1

在Rails中我是新手,我正在閱讀Michael Hartl的RubyOnRails教程...我已閱讀了有關第9章類似的問題,但我沒有解決我自己的問題,所以這裏是我的github存儲庫,失敗的測試......也許有人能幫助我,非常感謝;)第9章測試失敗Ruby on rails教程

https://github.com/AntonioCortinaL/sample_app

1) UserPages edit page 
Failure/Error: it { should have_selector('h1',  text: "Update your profile") } 
    expected css "h1" with text "Update your profile" to return something 
# ./spec/requests/user_pages_spec.rb:61:in `block (4 levels) in <top (required)>' 

2) UserPages edit page 
Failure/Error: it { should have_selector('title', text: "Edit user") } 
    expected css "title" with text "Edit user" to return something 
# ./spec/requests/user_pages_spec.rb:62:in `block (4 levels) in <top (required)>' 

3) UserPages edit page 
Failure/Error: it { should have_link('change', href: 'http://gravatar.com/emails') } 
    expected link "change" to return something 
# ./spec/requests/user_pages_spec.rb:63:in `block (4 levels) in <top (required)>' 

4) UserPages 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:67:in `block (4 levels) in <top (required)>' 

5) UserPages edit with valid information 
Failure/Error: fill_in "Name",    with: new_name 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Name' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>' 

6) UserPages edit with valid information 
Failure/Error: fill_in "Name",    with: new_name 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Name' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>' 

7) UserPages edit with valid information 
Failure/Error: fill_in "Name",    with: new_name 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Name' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>' 

8) UserPages edit with valid information 
Failure/Error: fill_in "Name",    with: new_name 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Name' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>' 

9) UserPages edit with valid information 
Failure/Error: fill_in "Name",    with: new_name 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Name' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:76:in `block (4 levels) in <top (required)>' 

編輯保羅·菲奧拉萬蒂回答後:

好的,謝謝...我改了這個:

before do 
    sign_in user 
    visit edit_user_path(user) 
end 

現在,它的5個錯誤

1) UserPages edit with valid information 
Failure/Error: fill_in "Confirm Password", with: user.password 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>' 

2) UserPages edit with valid information 
Failure/Error: fill_in "Confirm Password", with: user.password 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>' 

3) UserPages edit with valid information 
Failure/Error: fill_in "Confirm Password", with: user.password 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>' 

4) UserPages edit with valid information 
Failure/Error: fill_in "Confirm Password", with: user.password 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>' 

5) UserPages edit with valid information 
Failure/Error: fill_in "Confirm Password", with: user.password 
Capybara::ElementNotFound: 
    cannot fill in, no text field, text area or password field with id, name, or label 'Confirm Password' found 
# (eval):2:in `fill_in' 
# ./spec/requests/user_pages_spec.rb:81:in `block (4 levels) in <top (required)>' 

回答

1

Your user_pages_spec.rb test說:

describe "edit" do 
    let(:user) { FactoryGirl.create(:user) } 
    before { visit edit_user_path(user) } 
    # ... 
end 

你忘了sign_invisit之前荷蘭國際集團的edit_user_path

Here's the tutorial's equivalent spec

編輯

至於你的第二個問題,看到了Rails教程here相當於鏈接。比較你user_pages_spec.rbherehere:你可以看到你正在試圖fill_in一個"Confirm Password"場和"Confirmation"場,其中只有一個在您的應用程序確實存在......

+0

感謝您的回覆,我已更正,但仍有5個錯誤。我比較了你給我的代碼,我認爲是正確的。 – manguiti 2013-04-10 17:28:54

+0

請參閱編輯問題;你可能只是有一個錯字。 – 2013-04-10 23:47:52

0

確保你給每個用戶在運行測試套件之前使用rails控制檯的有效記憶令牌。遵循8.2.4的精確說明。

相關問題