A similar problem happened to me when I was doing an example problem. Capybara was not picking the text that was there. In this Capybara is not picking the link for the object that is there. Am I missing something?
Error message:
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?"'
These are my test gems:
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
These are my codes.
Scenario:
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 definition:
Factory.define(:queston) do |q|
q.question "Why is earth round?"
end
Step definition:
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
View:
<ul>
<% @questons.each do |queston| %>
<li><%= link_to queston.question, queston %></li>
<% end %>
</ul>
Queston is the model class and question is its attribute.
The problem was with my scenario. I have to simply declare the object first, like this:
Instead of