【问题标题】:RSpec False Positive - How is this possible?RSpec 误报 - 这怎么可能?
【发布时间】:2013-02-05 13:33:07
【问题描述】:

RSpec 在我的帮助页面上说一切都很好而且花花公子,但事实并非如此。什么会导致误报。 (我已经多次重启了我的测试套件)。

这是我的规格页面:

require 'spec_helper'

describe "Static pages" do

  subject { page }

  shared_examples_for "all static pages" do
    it { should have_selector 'h1',    text: heading }
    it { should have_selector 'title', text: full_title(page_title) }
  end

.
.
.

  describe "Help page" do
    before { visit help_path }

    let(:heading) { 'Help' }
    let(:page_title) { 'Help' }
  end

.
.
.

end

这是我的帮助页面:

<% provide(:title, '') %>
<h1></h1>
<p>
  Get help on the Ruby on Rails Tutorial at the
  <a href="http://railstutorial.org/help">Rails Tutorial help page</a>.
  To get help on this sample app, see the
  <a href="http://railstutorial.org/book">Rails Tutorial book</a>.
</p>

表示测试通过。如何解决?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 rspec rspec2


    【解决方案1】:

    看起来你不见了:

    it_should_behave_like 'all static pages'
    

    describe 'Help Page' 块中。您已经为“所有静态页面”定义了共享示例,但没有告诉 rspec“帮助页面”应该表现得像一个。

    另外,请查看this answer非常相似的问题。它展示了如何重构规范以更清楚地表达意图。

    【讨论】:

      猜你喜欢
      • 2011-01-31
      • 1970-01-01
      • 2020-05-25
      • 2018-11-06
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多