2013-12-10 22 views
0

我正在爲Michael Hartls Rails教程做第7章7.6節的練習。我試圖做出「提交後」的測試,但得到錯誤:測試失敗:「提交後」 - 未定義的局部變量或方法'提交'

Failure/Error: before { click_button submit } 
    NameError: 
     undefined local variable or method `submit' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_4:0x007f8289dede70> 

我不知道如何解決這個問題。我安裝了水豚,並且我所有的其他測試都能正常工作。

有什麼建議嗎?

Here is a link to the chapter

和我的RSpec的代碼:

require 'spec_helper' 

describe "UserPages" do 
    subject { page } 

    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 
    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 
    end 
    end 

    describe "after submission" do 
    before { visit signup_path } 
    before { click_button submit } 

    it { should have_title('Sign up') } 
    it { should have_content('error') } 
    end 
end 
+1

請增加這個問題的細節。像鏈接到章節的一些更多的代碼。這有點含糊。 –

回答

1

,約每此段哈特爾這本書的其他問題,是否缺少

let(:submit) { "Sign up" } 

而且你不應該通過學習水豚學習的Rails - >黃瓜,但這是時尚這些天...

+0

我讓((提交){「創建我的帳戶」) – user3018744

+0

在'click_button submit'上放置一個斷點(或者在其上放置一個'sleep 100'),運行它並查看瀏覽器。它是否有一個與該文本完全一樣的按鈕?你也必須發佈你的'

'...... – Phlip

相關問題