Capybara 2.0和rspec-rails - 帮助程序在规范/功能中不起作用

时间:2013-05-22 12:20:07

标签: ruby-on-rails ruby rspec capybara helper

我正在尝试使用辅助模块中的方法,但是rspec似乎不能识别spec/features下的测试帮助程序。请注意,spec_helper.rb的唯一更改是添加require 'capybara/rspec'

我尝试将helper.rb移动到spec/supportspec/helpersspec/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

1 个答案:

答案 0 :(得分:0)

将此帮助文件放在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 }