我正在为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: "user@example.com"
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
答案 0 :(得分:1)
关于Hartl这本书的其他问题,你错过了吗?
let(:submit) { "Sign up" }
你不应该通过学习Capybara来学习Rails - &gt;黄瓜,但这就是现在的时尚......