2013-05-13 35 views
3

向Rspec的配置中添加宏時,必須指定它將被訪問的測試類型。例如,您可以鍵入:讓Rspec爲Capybara的特色識別宏

config.extend ControllerMacros, :type => :controller 

你怎麼得到這個與水豚,其類型工作(:功能)貌似是不被認可的Rspec's config。嘗試這樣的事情不工作:

config.extend FeatureMacros, :type => :feature 

回答

4

我不知道爲什麼你鍵入extend,我所有的設置都include和他們的作品。

RSpec.configure do |config| 
    # ... others 

    # Session helpers - For Capybara 
    config.include Features::SessionHelpers, type: :feature 

    # Controller helpers 
    config.include ControllerMacros, type: :controller 

end 

而模塊文件在spec/support。如果子模塊,它們像`規格/支持/功能/

水豚助手

# spec/support/features/session_helpers.rb 
require 'spec_helper' 

module Features 
    module SessionHelpers 

    def user_sign_in 
    end 
    end 
end 
+0

此工程的實例子文件夾中。如果你使用include,你不必設置'type'。 – nullnullnull 2013-05-13 13:29:19