0
我剛剛開始使用黃瓜,並喜歡它,但有一個問題似乎很基本,我不能解決。我做我的主頁的一個非常基本的測試有以下:黃瓜h1測試通過但不應該?
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中有「Working」,黃瓜仍在傳遞,因爲它應該失敗,因爲我是te刺痛的「H1」測試任何想法,爲什麼這可能是
對不起,我不確定你在這裏是什麼意思,我會替換什麼。你能不能指出我的文檔?感謝您的幫助。 – Tom
'page.should have_selector(selector,text:text)'http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers#has_selector%3F-instance_method –