例の問題を抱えていたときにも同様の問題が発生しました。カピバラはそこにあったテキストを選んでいない。このカピバラでは、そこにあるオブジェクトのリンクを選択していません。何か不足していますか?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はモデルクラスであり、という質問がその属性です。
あなたはこれを実行してみたときに表示されるエラーを投稿することができます:私はこのように、単に最初のオブジェクトを宣言する必要がありますか? – Veraticus
申し訳ありません、投稿を編集しました。 – Humming