當我做一個示例問題時,發生了類似的問題。水豚沒有選擇那裏的文字。在這水豚不選擇鏈接對象在那裏。我錯過了什麼嗎?水豚無法找到Factory_Girl創建的對象的鏈接
錯誤消息:
When I click the link "Why is earth round?" # features/step_definitions/queston_steps.rb:6
no link with title, id or text 'Why is earth round?' found (Capybara::ElementNotFound)
(eval):2:in `click_link'
./features/step_definitions/queston_steps.rb:7:in `/^I click the link "([^"]*)"$/'
features/viewing_questions.feature:9:in `When I click the link "Why is earth round?"'
這是我的測試寶石:
group :test, :development do
gem 'rspec-rails'
end
group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl'
gem 'factory_girl_rails'
end
這是我的代碼。
場景:
Scenario: Listing questions
Given I am on the home page
And there is a question "Why is earth round?"
When I click the link "Why is earth round?"
Then I should be on the page for "Why is earth round?"
And I should see "Question: Why is earth round?"
廠定義:
Factory.define(:queston) do |q|
q.question "Why is earth round?"
end
步驟定義:
Given /^there is a question "([^"]*)"$/ do |question|
FactoryGirl.create(:queston, :question => question)
#Queston.create(:question => question)
end
When /^I click the link "([^"]*)"$/ do |link|
click_link(link)
end
查看:
<ul>
<% @questons.each do |queston| %>
<li><%= link_to queston.question, queston %></li>
<% end %>
</ul>
Queston是模型類和問題是它的屬性。
你能後,您當您嘗試運行此收到錯誤? – Veraticus 2012-03-01 16:10:59
對不起,編輯了這篇文章。 – Humming 2012-03-01 16:31:47