我正在尝试使用辅助模块中的方法,但 rspec 似乎无法识别辅助程序以进行测试spec/features
。请注意,唯一的更改是spec_helper.rb
正在添加require 'capybara/rspec'
.
我尝试移动helper.rb
to spec/support
, spec/helpers
, and spec/features
(包含我的测试的目录),但没有运气。测试一直表明辅助方法未定义。
让它“工作”的唯一方法是将我的测试移动到不同的目录,例如spec/integration
。但现在水豚不行了(visit undefined
)因为它不在spec/features
.
这是我的帮助模块(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
将此帮助文件放在spec/support/中
和这一行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 }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)