0

我刚刚开始使用黄瓜并且喜欢它,但是有一个问题似乎非常基本,我无法解决。我正在使用以下内容对我的主页进行非常基本的测试:

home_pages.feature

Feature: Viewer visits the Home Page
        In order to read the page
        As a viewer
        I want to see the home page of my app

    Scenario: View home page
        Given I am on the home page
        Then I should see "Test" in the selector "h1"

    Scenario: Check Home Page Links
        Given I am on the home page
        Then I should see "How It Works" in a link
        And I should see "Sign Up" in a link
        And I should see "Log In" in a link

和 cr1_steps.rb

Given /^I am on the home page$/ do
  visit root_path
end

Then /^I should see "([^"]*)" in the selector "([^"]*)"$/ do |text, selector|
  page.should have_selector selector, content: text
end

Then /^I should see "([^"]*)" in a link$/ do |text|
    page.should have_link text
end

主页.html.erb

<div class="center hero-unit">
  <h1>Working</h1>
    <p>testing testing testing</p>
      <a class="btn btn-primary btn-large">
        Click This
      </a>
 </div>
  <ul class="thumbnails">
    <li class="span3">
      <div class="thumbnail">
        <img src="http://placehold.it/360x268" alt="">
      </div>
    </li>
  </ul>

然而,即使“h1”选择器在 home.html.erb 中有“工作”,黄瓜也会通过,因为它应该失败,因为我正在测试“h1”测试任何想法为什么会这样

4

1 回答 1

2

:content我在 Capybara 文档中没有看到一个选项#has_selector?

试试text: text吧。

于 2012-06-09T16:14:21.300 回答