2013-04-06 40 views
0

我有以下使用香草spec_helper的示例代碼。我試圖使用sign_in_as,但得到一個錯誤,說它不存在。我之前沒有真正看過這個配置語法,所以我不確定這是否正確使用。任何幫助,將不勝感激? THX該代碼是否適用於包含在rspec的幫助文件中?

在助手/ sign_in_helpers.rb

module SignInHelpers 
    def say_hello 
    puts 'hello' 
    end 

    def sign_in 
    sign_in_as '[email protected]' 
    end 

    def sign_in_as email 
    visit root_path 
    fill_in 'Email address', with: email 
    click_button 'Sign In' 
    end 
end  

RSpec.configure do |config| 
    config.include SignInHelpers 
end 

回答

1

代碼中的一些錯誤。

  1. ,你應該對文件

    需要 'spec_helper'

  2. 把文件的地方是spec/support的頂這個代碼,而不是spec/helpers

而且,對於下面的代碼,最好將它們全部放在配置塊中的spec/spec_helper.rb中,儘管你的方式也應該如此。

RSpec.configure do |config| 
    config.include SignInHelpers 
end 

順便說一句,更好地定義爲你的助手僅是功能型的,而不是要在控制器的測試工作。

config.include SignInHelpers type: :feature 
相關問題