[英]Capybara 2.0 and rspec-rails — helpers don't work in spec/features
I'm trying to use a method from a helper module, but rspec doesn't seem to recognize helpers for tests under spec/features
. 我正在尝试使用辅助模块中的方法,但rspec似乎没有识别
spec/features
下的测试帮助程序。 Note that the only change to spec_helper.rb
was adding require 'capybara/rspec'
. 请注意,对
spec_helper.rb
的唯一更改是添加spec_helper.rb
require 'capybara/rspec'
。
I tried moving helper.rb
to spec/support
, spec/helpers
, and spec/features
(the directory that contains my tests), but no luck. 我尝试将
helper.rb
移动到spec/support
, spec/helpers
和spec/features
(包含我的测试的目录),但没有运气。 The test keeps indicating that the helper method is undefined. 测试始终指示辅助方法未定义。
The only way to get it to "work" was by moving my test to a different directory, such as spec/integration
. 让它“工作”的唯一方法是将我的测试移动到另一个目录,例如
spec/integration
。 But now capybara won't work ( visit undefined
) because it's not in spec/features
. 但是现在水豚将无法工作(
visit undefined
),因为它不符合spec/features
。
Here's my helper module ( authentication_helper.rb
): 这是我的帮助模块(
authentication_helper.rb
):
module AuthenticationHelper
def sign_in_as!(user)
visit '/users/sign_in'
fill_in "Email", with: user.email
fill_in "Password", with: "password"
click_button "Sign in"
page.should have_content("Signed in successfully.")
end
end
RSpec.configure do |c|
c.include AuthenticationHelper, type: :request
end
put this helper file in spec/support/ 把这个帮助文件放在spec / support /中
and this line spec_helper.rb 这行spec_helper.rb
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.