我正在将一个旧的粗糙的应用程序升级到Rails 3.1。该公司一直在使用RSpec和Capybara进行验收测试。我们在spec/acceptance
下有一些验收测试失败,并显示以下消息:
Failure/Error: get @url
NoMethodError:
undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007feb7c0abf58>
下面是其中一个测试的示例(来自文件的顶部):
require_relative 'acceptance_helper'
feature 'Catalog' do
before do
Settings.use_catalog_navigation = true
end
context 'with a Vendor' do
before do
@vendor = create(:vendor, slug: 'abc')
@product = create(:product_with_variants, vendor: @vendor)
@non_vendor_product = create(:product_with_variants)
@invisible_product = create(:product_with_variants,
vendor: @vendor,
visible: false)
@non_available_product = create(:product_with_variants,
vendor: @vendor,
available: false)
@url = "/#{@vendor.slug}"
end
it 'sets @vendor' do # <- FIRST FAILING TEST
get @url
assigns(:vendor).should == @vendor
end
...
在咨询oracle时,我不断遇到提到'visit'方法的问题,例如:https://github.com/jnicklas/capybara/issues/814
我也不断看到与这篇文章相关的帖子:http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html
我不确定我是否有同样的问题。如果我的spec_helper.rb
和acceptance_helper.rb
有用的话,我可以把它们贴出来。
我想值得注意的是,这些规范在我更新spec_rails和capybara之前就通过了。
我的直觉是,也许respect -rails正在破坏一些capybara的方法,或者一些capybara的方法根本不再被加载。这是问题所在吗?
尝试在配置块内的spec_helper.rb
中添加config.include Capybara::DSL
。像这样:
RSpec.configure do |config|
config.include Capybara::DSL