Bra*_*and 27 ruby rspec ruby-on-rails capybara
我使用capybara进行集成/验收测试.它们在/spec/requests/文件夹中.现在我在验收测试中使用了一些帮助方法.一个例子是register_user这样的
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
Run Code Online (Sandbox Code Playgroud)
我想在几种不同的验收测试中使用这种方法(它们在不同的文件中).包含这个的最佳方法是什么?我试过把它放进去,spec/support/但它并没有为我工作.花了一些时间后,我意识到我甚至不知道这是否是一个好方法,所以我想我会在这里问.
注意:我使用的是rails 3,spork和rspec.
Vas*_*ich 38
将您的助手放到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
Run Code Online (Sandbox Code Playgroud)
Alt*_*gos 16
我使用@VasiliyErmolovich给出的解决方案,但我更改了类型以使其工作:
config.include YourHelper, :type => :feature
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10022 次 |
| 最近记录: |