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.

Summary<br />

controller so anyone who reads the code knows that the controller responds to these<br />

actions.<br />

Back to the spec now: if you run bin/rspec spec/controllers/projects<br />

_controller_spec.rb once more, the test now passes:<br />

.<br />

1 example, 0 failures<br />

Let’s check to see if everything else is still working by running rake cucumber:ok and<br />

then rake spec. You should see these outputs:<br />

6 scenarios (6 passed)<br />

37 steps (37 passed)<br />

# and<br />

.<br />

3 examples, 0 failures, 2 pending<br />

The RSpec output shows two pending examples. These come from the spec files for<br />

ProjectsHelper (spec/helpers/projects_helper_spec.rb) and Project model (spec/<br />

models/project_spec.rb) respectively. You can delete these files or remove the pending<br />

lines from them to make your RSpec output green instead of yellow when it passes.<br />

Other than that, these two specs have no effect on your test output.<br />

It’s great to see that everything is still going! Let’s commit and push that!<br />

git add .<br />

git commit -m "Users should be redirected back to the projects page<br />

if they try going to a project that doesn't exist."<br />

git push<br />

This completes the basic CRUD implementation for your project’s resource. Now you<br />

can create, read, update, and delete projects to your heart’s content, and these features<br />

are all well covered with tests, which leads to greater maintainability.<br />

4.4 Summary<br />

This chapter covered developing the first part of your application using BDD practices<br />

and Cucumber and then making each step pass. Now you have an application that is<br />

truly maintainable. If you want to know if these features or specs are working later in<br />

the project, you can run rake cucumber:ok or rake spec and if something is broken,<br />

you’ll know about it. Doesn’t that beat manual testing? Just think of all the time you’ll<br />

save in the long run.<br />

You learned firsthand how rapidly you can develop the CRUD interface for a<br />

resource in Rails. There are even faster ways to do it (such as by using scaffolding, discussed<br />

in chapter 1), but to absorb how this whole process works, it’s best to go<br />

through it yourself, step by step, as you did in this chapter.<br />

So far you’ve been developing your application using BDD techniques, and as your<br />

application grows, it will become more evident how useful these techniques are. The<br />

main thing they’ll provide is assurance that what you’ve coded so far is still working<br />

exactly as it was when you first wrote it. Without these tests, you may accidentally break<br />

97

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

Saved successfully!

Ooh no, something went wrong!