黄瓜,Rails:has_content?即使字符串不存在也通过测试

问题描述 投票:0回答:1

场景是:

    Scenario: View welcome page
    Given I am on the home page
    Then I should see 'Welcome'

步骤的定义是

Then("I should see {string}") do |string|
  page.has_content?(string)
end

测试通过,无论欢迎词是否在主页中。我在做什么错?

ruby-on-rails cucumber capybara
1个回答
0
投票

仅在引发异常时,该步骤才会失败。按照其命名约定,如果内容不在页面中,则has_content?方法将返回false,因此不会引发异常。如果您打算失败,这将导致您的步骤“通过”。

您需要使用某种单元测试库进行断言(我的Ruby有点生锈)

Then("I should see {string}") do |string|
  page.has_content?(string).should_be true
end

您需要RSpec之类的东西才能访问允许我断言的库。

© www.soinside.com 2019 - 2024. All rights reserved.