黄瓜h1测试通过,但不应该?

时间:2012-06-09 15:17:13

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

我刚刚开始使用黄瓜并且喜欢它,但是有一个问题似乎非常基本,我无法解决。我正在对我的主页做一个非常基本的测试,其中包括:

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

home.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”测试任何想法为什么这可能

1 个答案:

答案 0 :(得分:2)

我在:content

的Capybara文档中看不到#has_selector?选项

请尝试text: text