Ruby on Rails TDD;测试时出错



我正在努力学习TDD on Rails教程,该教程可在在线获得

在测试第一个应用程序时,我遇到了一个错误。

我的spec.rb代码是这样的:

require 'spec_helper'
describe "Static pages" do
  describe "Home page" do
    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      page.should have_content('Sample App')
    end
  end
end

运行测试后,我得到了这个错误:

Failure/Error: visit '/static_pages/home'
 NoMethodError:
   undefined method `visit' for #    <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa833e5c># ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

我将非常感谢你的帮助。

visit方法不是RSpec的一部分,它是由水豚提供的。只需将此添加到您的Gemfile:

gem 'capybara'

尝试添加:

require 'rails_helper'
require 'spec_helper'

到您的spec.rb和:

require 'capybara'
RSpec.configure do |config|
  config.include Capybara::DSL 
....

至spec_helper.rb

和gem‘capybara’,‘2.2.0’到gemfile

最新更新