我正在爲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>
我不知道如何解決這個問題。我安裝了水豚,並且我所有的其他測試都能正常工作。
有什麼建議嗎?
和我的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
請增加這個問題的細節。像鏈接到章節的一些更多的代碼。這有點含糊。 –