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

问题描述

我正在使用capybara进行集成/验收测试。它们位于 / 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:

spec / support /:

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

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

10-09 21:10