Capybara 方法未定义 [英] Capybara methods are undefined

查看:22
本文介绍了Capybara 方法未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让水豚工作.我使用的是水豚 2.0.0

I cannot get capybara to work. I am using capybara 2.0.0

我收到此错误

Failure/Error: visit "/users/sign_in"
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_21:0x007fdda4c6eba0>

关于这个规范

spec/requests/forgot_password_spec.rb

spec/requests/forgot_password_spec.rb

describe "forgot password" do
  it "redirects user to users firms subdomain" do
    visit "/users/sign_in"  
  end
end

我没有收到任何无法找到水豚的错误,它包含在 spec_helper.rb 中

I do not get any errors that it cannot find capybara and it's included in the spec_helper.rb

spec_helper.rb

spec_helper.rb

require 'rubygems'
require 'spork'
require 'database_cleaner'
Spork.prefork do
 ENV["RAILS_ENV"] ||= 'test'
 require File.expand_path("../../config/environment", __FILE__)
 require 'rspec/rails' 
 require 'capybara/rspec'
 require 'rspec/autorun'
 require 'factory_girl'


 Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

 RSpec.configure do |config|
   config.include Devise::TestHelpers, :type => :controller
   config.extend ControllerMacros, :type => :controller
   config.include RequestMacros, :type => :request
   config.mock_with :rspec

   config.use_transactional_fixtures = false

   config.before(:suite) do
     DatabaseCleaner.strategy = :truncation
   end

   config.before(:each) do
     DatabaseCleaner.start
   end

   config.after(:each) do
     DatabaseCleaner.clean
   end
   config.infer_base_class_for_anonymous_controllers = false
 end
 Spork.each_run do
   FactoryGirl.reload  
 end
 end

有没有其他人遇到过这种情况?

Has anybody else encountered this?

推荐答案

如果你有 >= 2.0 版本,任何使用 Capybara 方法的测试,如 visit应该位于 spec/features 目录下,而不是 spec/requests 目录下,它们通常位于 Capybara 1.1.2 中.

If you've got version >= 2.0, any tests that use Capybara methods like visit should go under a spec/features directory, and not under spec/requests, where they'd normally reside in Capybara 1.1.2.

查看以下链接了解更多信息:

Have a look at the following links for more information:

如果您不想使用 spec/features 目录,您应该能够通过以下方式将测试标记为 feature 并使用 Capybara 方法工作:

If you don't want to use a spec/features directory, you should be able to mark a test as a feature in the following way and have Capybara methods work:

describe "Some action", type: :feature do
  before do
    visit "/users/sign_in"
    # ...
  end
  # ...
end

这篇关于Capybara 方法未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆