2012-03-01 73 views
1

當我做一個示例問題時,發生了類似的問題。水豚沒有選擇那裏的文字。在這水豚不選擇鏈接對象在那裏。我錯過了什麼嗎?水豚無法找到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是模型類和問題是它的屬性。

+0

你能後,您當您嘗試運行此收到錯誤? – Veraticus 2012-03-01 16:10:59

+0

對不起,編輯了這篇文章。 – Humming 2012-03-01 16:31:47

回答

1

問題出在我的情況。我得先簡單聲明對象,像這樣:

Scenario: Listing questions 
Given there is a question "Why is earth round?" 
And I am on the home page 

而不是

Scenario: Listing questions 
Given I am on the home page 
And there is a question "Why is earth round?" 
0

這可能是一個錯字:你FactoryGirl工廠定義了一個名爲queston模式,而不是question.

如果沒有,我會嘗試提出的問題和響應主體看在每一個地方產生什麼。顯然有些東西沒有正確生成。

+0

是的,Queston是模型。它不是一個錯字。 – Humming 2012-03-01 16:47:03