在何处/如何包含用于水豚集成测试的辅助方法 [英] Where/how to include helper methods for capybara integration tests

查看:17
本文介绍了在何处/如何包含用于水豚集成测试的辅助方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用水豚进行集成/验收测试.它们位于 /spec/requests/ 文件夹中.现在我有一些在验收测试中使用的辅助方法.一个例子是register_user 看起来像这样

I"m using capybara for my integration/acceptance tests. They're in /spec/requests/ folder. Now I have a few helper methods that I use during acceptance tests. One example is register_user which looks like this

def register_user(user)
  visit home_page
  fill_in 'user_name', :with => user.username
  fill_in 'password', :with => user.password
  click_button 'sign_up_button'
end

我想在几个不同的验收测试中使用这个方法(它们在不同的文件中).包含此内容的最佳方法是什么?我试过把它放在 spec/support/ 中,但它对我不起作用.在花了一些时间之后,我意识到我什至不知道这是否是一个好的方法,所以我想我会在这里问.

I want to use this method in several different acceptance tests (they're in different files). What's the best way to include this? I've tried putting it in spec/support/ but it hasn't been working for me. After spending some time on it I realized I don't even know if it's a good way of doing it so I figured I'd ask here.

注意:我使用的是 rails 3、spork 和 rspec.

Note: I am using rails 3, spork and rspec.

推荐答案

将您的助手放到 spec/support 文件夹中,然后执行以下操作:

Put your helper to the spec/support folder and do something like this:

规范/支持/:

module YourHelper
  def register_user(user)
    visit home_page
    fill_in 'user_name', :with => user.username
    fill_in 'password', :with => user.password
    click_button 'sign_up_button'
  end
end

RSpec.configure do |config|
  config.include YourHelper, :type => :request
end

这篇关于在何处/如何包含用于水豚集成测试的辅助方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆