1

我正在尝试遵循 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)>'

我将非常感谢您的帮助。

4

2 回答 2

3

visit方法不是 RSpec 的一部分 - 它由capybara提供。只需将其添加到您的 Gemfile 中:

gem 'capybara'
于 2012-03-08T11:54:17.297 回答
0

尝试添加:

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

于 2014-11-30T08:18:40.060 回答