27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

246 CHAPTER 10 Tracking state<br />

group :test do<br />

gem 'cucumber-rails'<br />

gem 'capybara'<br />

gem 'database_cleaner'<br />

gem 'factory_girl'<br />

gem 'email_spec'<br />

gem 'launchy'<br />

end<br />

When you run bundle install, it will install the launchy gem for you. Let’s rerun<br />

your feature again. This time, a page pops up with your home page, as shown in<br />

figure 10.2.<br />

See how there are two Ticketee links on this page? Capybara’s dutifully following<br />

your instruction to click the Ticketee link, and it clicks the first link it finds on the<br />

page! You want it to click the second link. Let’s change the line in your features/<br />

creating_comments.feature that follows this link to the following:<br />

And I follow "Ticketee" within "#projects"<br />

Here you use the within version of this step which will look up the link within the element<br />

with the id attribute set to “projects.” No element currently has this attribute, so<br />

let’s preempt the scenario failing on this step and add this id to the ul element in<br />

app/views/projects/index.html.erb, as shown in the following listing.<br />

Listing 10.2 app/views/projects/index.html.erb<br />

<br />

<br />

<br />

<br />

<br />

Good! That should make your scenario follow the correct link. Try rerunning it now.<br />

You should see this:<br />

And I fill in "Text" with "Added a comment!"<br />

cannot fill in, no text field, text area or password field<br />

with id, name, or label 'Text' found (Capybara::ElementNotFound)<br />

Oops! A web page from the "Then show me the page" step came up. Remove this step<br />

from your scenario now.<br />

This failing step means that you’ve got work to do! The label it’s looking for is<br />

going to belong to the comment box underneath your ticket’s information.<br />

Figure 10.2 The home page

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!