似乎所有的capybaras方法都是神奇的未定义。我试图对TDD进行一些测试,并编写了以下测试:
it "sign in and fail" do
click_link "login"
fill_in "User Name", :with => "Test"
fill_in "Password", :with => "test"
click_button "sign in"
page.should have_content("User does not exist. Pleae try registering in.")
end
它应该在click_link上吓坏了,只是因为没有这样的链接,而是它吓坏了说:
NoMethodError:
undefined method `click_link'
所以我检查了我的宝石文件:
gem "rspec-rails", :group => [:test, :development]
group :test do
gem "factory_girl_rails"
gem "capybara"
gem "guard-rspec"
gem 'database_cleaner'
gem "launchy"
end
然后我检查了我的pec助手,是的,我有:
require 'capybara/rspec'
require 'capybara/rails'
那么当守卫运行时,未定义的方法错误是什么?它应该告诉我“嗯,没有链接让我点击......”而不是“我不知道click_link是什么”。它在访问,click_button,包含等等时都很烦人。
据我所知,水豚的安装正确....
答案 0 :(得分:1)
尝试将其放入env.rb:
include Capybara::DSL
然后运行测试