【问题标题】:Getting Rspec to Recognize Macros for Capybara's Specials让 Rspec 识别 Capybara 特价商品的宏
【发布时间】:2013-05-13 13:04:56
【问题描述】:

将宏添加到 Rspec 的配置时,您必须指定将访问它的测试类型。例如,您可以输入:

config.extend ControllerMacros, :type => :controller

你如何让它与 Capybara 一起工作,它的类型 (:feature) 似乎无法被 Rspec's config 识别。尝试这样的事情是行不通的:

config.extend FeatureMacros, :type => :feature

【问题讨论】:

    标签: ruby-on-rails rspec capybara config


    【解决方案1】:

    我不知道你为什么要输入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/

    Capybara 助手示例

    # spec/support/features/session_helpers.rb
    require 'spec_helper'
    
    module Features
      module SessionHelpers
    
        def user_sign_in
        end
      end
    end
    

    【讨论】:

    • 这行得通。如果你使用包含,你也不必设置type
    猜你喜欢
    • 2021-07-22
    • 2017-12-10
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多