加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

ruby-on-rails – 当Guard在监视文件中运行规范时,Rspec / Capy

发布时间:2020-12-15 01:26:45 所属栏目:大数据 来源:网络整理
导读:使用Guard运行我的规范时,我遇到了一个奇怪的问题. 我正在运行使用Capybara“feature”/“scenario”语法的功能规范.我也在使用Spring. 如果我在控制台中运行rspec spec或spring rspec或在Guard shell中运行rspec,一切正常.但是,当看到的规格由Guard自动运行

使用Guard运行我的规范时,我遇到了一个奇怪的问题.

我正在运行使用Capybara“feature”/“scenario”语法的功能规范.我也在使用Spring.

如果我在控制台中运行rspec spec或spring rspec或在Guard shell中运行rspec,一切正常.但是,当看到的规格由Guard自动运行时,我收到以下错误:

/spec/features/navigation_spec.rb:1:in feature’ for main:Object (NoMethodError)

为什么它只是在这个特定的上下文中才取出Capybara语法?

这是相关代码:

GuardFile

guard :rspec,:spring => true do
    watch(%r{^spec/.+_spec.rb$})
end

规格/功能/ navigation_spec.rb

feature "navigation" do
    context "When on the home page" do
        before { visit "/" }

        scenario "I should see the navigation header" do
            expect(page).to have_selector("div.navigation")
        end
    end
end

投机/ spec_helper.rb

require 'capybara/rspec'
最佳答案
对于将来可能会遇到类似问题的任何人,我忘了在功能规范中包含require’pect_helper'(就像一个白痴).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读