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.

56 CHAPTER 3 Developing a real Rails application<br />

To run all features for your application, run rake cucumber:ok. This command causes<br />

the following error message:<br />

...db/schema.rb doesn't exist yet. Run "rake db:migrate" to<br />

create it then try again. If you do not intend to use a database,<br />

you should instead alter ...ticketee/config/application.rb to limit<br />

the frameworks that will be loaded<br />

The db/schema.rb file referenced here (when generated) will contain a Ruby version<br />

of your database’s schema, which can be used to import the structure of your database.<br />

The great thing is that this file is database agnostic, so if you choose to switch<br />

databases during the life of your project, you won’t have to re-create this schema file.<br />

To generate this file, run this command:<br />

rake db:migrate<br />

For now, this command prints out the standard first line of rake output, the path to<br />

the application:<br />

(in /home/us/ticketee)<br />

When you run any Rake task, the first line will be this line. Its only purpose is to indicate<br />

which directory you’re running inside. When you run this particular task, it generates<br />

the db/schema.rb file your feature required. Therefore, you can run rake<br />

cucumber:ok again to have it fail on the second step of your feature:<br />

When I follow "New Project"<br />

no link with title, id or text 'New Project' found<br />

The first step here passes, but you haven’t written a step definition for it, as you did in<br />

chapter 2! It nevertheless passes because of the features/step_definitions/web_steps.rb<br />

file, which was generated when you ran the rails generate cucumber:install command.<br />

This file contains a step definition that matches your first step:<br />

Given /^(?:|I )am on (.+)$/ do |page_name|<br />

visit path_to(page_name)<br />

end<br />

First, Cucumber interprets this step on the basis of the definition from within this file.<br />

The visit method inside this definition comes from Capybara and emulates going to<br />

a specific path in a virtual browser. The path_to method is also defined, but it’s in the<br />

features/support/paths.rb file inside the NavigationHelpers module, again provided<br />

by Cucumber:<br />

module NavigationHelpers<br />

...<br />

def path_to(page_name)<br />

case page_name<br />

when /the home\s?page/<br />

'/'<br />

...<br />

Therefore, the path that Capybara will visit is /. If you start the server for the application<br />

by running rails server (or rails s) and navigate to http://localhost:3000 in

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

Saved successfully!

Ooh no, something went wrong!