水豚方法未定义 [英] Capybara methods are undefined
问题描述
我无法让水豚工作。我正在使用水豚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>
根据此规范
规范/要求/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
还有其他人遇到过吗?
推荐答案
如果您的版本为> = 2.0
,则任何使用Capybara方法的测试,例如 visit
应该放在 spec / features 目录下,而不是在通常位于Capybara 1.1的 spec / requests 下。 .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:
- < a href = http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html rel = noreferrer> rspec- rails和capybara 2.0:您需要了解的内容
- rspec-rails gem Capybara页面
- rspec-rails and capybara 2.0: what you need to know
- rspec-rails gem Capybara page
如果您不想使用在 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
这篇关于水豚方法未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!