2012-03-01 6 views
1

例の問題を抱えていたときにも同様の問題が発生しました。カピバラはそこにあったテキストを選んでいない。このカピバラでは、そこにあるオブジェクトのリンクを選択していません。何か不足していますか?Capybaraさんが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

+0

申し訳ありません、投稿を編集しました。 – Humming

答えて

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

関連する問題