2013-12-14 74 views
-1

任何已完成此練習的人都能幫助我嗎?Ruby on Rails失敗/錯誤教程第9章

這是我第一次使用這種編程語言,並沒有太多的,但我需要完成,直到第10章是最終評估。

1) User pages edit with valid information 
    Failure/Error: describe "page" do 
    NoMethodError: 
     undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc283f8c> 
    # ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>' 

    2) User pages edit with valid information 
    Failure/Error: describe "page" do 
    NoMethodError: 
     undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xb67b1cc> 
    # ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>' 

    3) User pages edit with valid information 
    Failure/Error: describe "page" do 
    NoMethodError: 
     undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc224244> 
    # ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>' 

    4) User pages edit with valid information 
    Failure/Error: describe "page" do 
    NoMethodError: 
     undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc562690> 
    # ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>' 

    5) User pages edit with valid information 
    Failure/Error: describe "page" do 
    NoMethodError: 
     undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc0559a4> 
    # ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>' 

    6) User pages index 
    Failure/Error: visit users_path 
    ActionView::Template::Error: 
     undefined method `each' for nil:NilClass 
    # ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840' 
    # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>' 

    7) User pages index 
    Failure/Error: visit users_path 
    ActionView::Template::Error: 
     undefined method `each' for nil:NilClass 
    # ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840' 
    # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>' 

    8) User pages index should list each user 
    Failure/Error: visit users_path 
    ActionView::Template::Error: 
     undefined method `each' for nil:NilClass 
    # ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840' 
    # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>' 

    9) Authentication authorization after signing in should render the desired protected page 
    Failure/Error: expect(page).to have_title('Edit user') 
     expected #has_title?("Edit user") to return true, got false 
    # ./spec/requests/authentication_pages_spec.rb:84:in `block (4 levels) in <top (required)>' 

Finished in 2.25 seconds 
72 examples, 9 failures 

Failed examples: 

rspec ./spec/requests/user_pages_spec.rb:114 # User pages edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:115 # User pages edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:112 # User pages edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:113 # User pages edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:111 # User pages edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:15 # User pages index 
rspec ./spec/requests/user_pages_spec.rb:16 # User pages index 
rspec ./spec/requests/user_pages_spec.rb:18 # User pages index should list each user 
rspec ./spec/requests/authentication_pages_spec.rb:83 # Authentication authorization after signing in should render the desired protected page 

編輯

這裏是我的代碼:

require 'spec_helper' 

describe "User pages" do 

    subject { page } 

    describe "index" do 
    before do 
     sign_in FactoryGirl.create(:user) 
     FactoryGirl.create(:user, name: "Bob", email: "[email protected]") 
     FactoryGirl.create(:user, name: "Ben", email: "[email protected]") 
     visit users_path 
    end 

    it { should have_title('All users') } 
    it { should have_content('All users') } 

    it "should list each user" do 
     User.all.each do |user| 
     expect(page).to 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_content(user.name) } 
    it { should have_title(user.name) } 
    end 

    describe "signup page" do 
    before { visit signup_path } 

    it { should have_content('Sign up') } 
    it { should have_title(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_title('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_link('Sign out') } 
     it { should have_title(user.name) } 
     it { should have_selector('div.alert.alert-success', text: 'Welcome') } 
     end 
    end 
    end 

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

    describe "page" do 
     it { should have_content("Update your profile") } 
     it { should have_title("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 
    end 

    describe "with valid information" do 
     let(:new_name) { "New Name" } 
     let(:new_email) { "[email protected]" } 
     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_title(new_name) } 
     it { should have_selector('div.alert.alert-success') } 
     it { should have_link('Sign out', href: signout_path) } 
     specify { expect(user.reload.name).to eq new_name } 
     specify { expect(user.reload.email).to eq new_email } 
    end 
    end 
end 
+1

如果您不提供任何代碼並且未指定如何運行它,我們無法幫助您修復代碼。 – Johnsyweb

+0

我標記的錯誤是兩個類user_pages_spec – user3100662

+0

您似乎已發佈[示例代碼從教程](https://github.com/railstutorial/sample_app_2nd_ed/blob/master/spec/requests/user_pages_spec.rb),但沒有給出任何細節,你已經做了什麼或者你如何運行代碼。 – Johnsyweb

回答

1

如果您的代碼格式如下:

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

describe "page" do 
    it { should have_content("Update your profile") } 
    it { should have_title("Edit user") } 
    it { should have_link('change', href: 'http://gravatar.com/emails') } 
end 

我可以看到,它可能打破沒有讀你的任何代碼。

所有的代碼塊是否正確關閉?看起來不是這樣的!

+0

是的,謝謝你,我解決了這個問題,我描述了一個不好的問題,我修改並完全運行 – user3100662

+0

,所以,將答案標記爲已解決! – phoet

0

除了未閉合塊是phoet指出,這是造成你的「未定義的方法描述了」錯誤,你要在/app/views/users/index.html.erb線錯誤5.錯誤是undefined method `each' for nil:NilClass這意味着有在該行的變量,你'variable.each,但是你要麼沒有設置該變量,要麼當你設置它時,它將被設置爲nil

一般來說,成功解決此問題的方法是閱讀錯誤消息並嘗試解決他們所抱怨的問題。如果您單獨搜索每條錯誤消息,則會發現有關可幫助您的特定問題的堆棧溢出問題。

相關問題