2011-11-19 27 views
21

我使用水豚進行了我的集成/驗收測試,他們在/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 

我想用幾個不同的驗收測試此方法(它們是在不同的文件)。什麼是包括它的最好方法?我試圖把它在spec/support/但它一直沒有爲我工作,花了一些時間後,我意識到我甚至不知道這是否是一種很好的方式,所以我想我會在這裏問一下。

注意:我正在使用rails 3,spork和rspec。

回答

36

把你的幫手規範/支持文件夾和做這樣的事情:

規格/支持/:

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 
+6

何時使用spec/support與spec/helpers? – cman77

+0

以上問題碰撞 –

+9

@ cman77 spec/helpers用於測試應用程序/幫助程序,spec/support文件適用於您希望在您的規格中使用的模塊和配置 –

15

我使用@VasiliyErmolovich給出解決方案,但我改變了鍵入以使其工作:

config.include YourHelper, :type => :feature 
+0

同樣在這裏...這就是如果你有你的測試規格/功能與規格/要求 –