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.

Leaving a comment<br />

| title | description |<br />

| Change a ticket's state | You should be able to create a comment |<br />

Given I am on the homepage<br />

And I follow "Ticketee"<br />

Scenario: Creating a comment<br />

When I follow "Change a ticket's state"<br />

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

And I press "Create Comment"<br />

Then I should see "Comment has been created."<br />

Then I should see "Added a comment!" within "#comments"<br />

Scenario: Creating an invalid comment<br />

When I follow "Change a ticket's state"<br />

And I press "Create Comment"<br />

Then I should see "Comment has not been created."<br />

And I should see "Text can't be blank"<br />

Here you navigate from the homepage to the ticket page by following the respective<br />

links, fill in the box with the label Text, and create your comment. You’ve put the link<br />

to the ticket inside the scenarios rather than the Background because you’ll use this<br />

feature for permission checking later on. Let’s try running this feature now by running<br />

bin/cucumber features/creating_comments.feature.<br />

10.1.1 Where’s the ticket?<br />

You’ll see that, after it follows the Ticketee link on the page, it can’t find the ticket.<br />

What?<br />

And I follow "Change a ticket's state"<br />

no link with title, id or text 'Change a ticket's state'<br />

found (Capybara::ElementNotFound)<br />

Uh oh, something’s gone wrong and for some reason Capybara can’t find the link.<br />

Before the failing step in the scenario you put this line:<br />

Then show me the page<br />

This step will show the exact page that Capybara sees when it tries to follow this link,<br />

providing a certain gem is installed. If you run this feature by using bin/cucumber<br />

features/creating_comments.feature, you’ll be told to install the launchy gem:<br />

Sorry, you need to install launchy to open pages: `gem install launchy`<br />

WARNING Launchy is known to be problematic on Windows and just may<br />

not work at all. As a replacement, you may have to manually open the<br />

pages created in the tmp directory called capybara-[date].<br />

Launchy is the gem responsible for launching the browser to show you the page.<br />

Launchy also provides a common cross-platform of launching different applications.<br />

Rather than installing this using gem install launchy, you’ll add this to your Gemfile<br />

inside the cucumber group because you only need this gem for your Cucumber features.<br />

The whole cucumber group for your Gemfile should now look like this:<br />

245

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

Saved successfully!

Ooh no, something went wrong!