我刚刚开始使用黄瓜并且喜欢它,但是有一个问题似乎非常基本,我无法解决。我正在对我的主页做一个非常基本的测试,其中包括:
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”测试任何想法为什么这可能
答案 0 :(得分:2)
我在:content
#has_selector?
选项
请尝试text: text
。