4 h2. Spec::Rails - Overview
6 A Rails plugin that brings RSpec to Rails.
10 * Use RSpec to independently specify models, views, controllers and helpers.
11 * Integrated fixture loading.
12 * Special generators for models and controllers that generate specs instead of tests.
13 * Special RSpec matchers for even more readable specs.
17 For people for whom TDD is a brand new concept, the testing support built into Rails is a huge
18 leap forward. The fact that it's built right in is fantastic, and Rails
19 apps are generally much easier to maintain than they would have been without such support.
21 For those of us coming from a history with TDD, and now BDD, the existing support
22 presents some problems related to dependencies across specs. To that end, RSpec
23 supports 4 types of specs. This is largely inspired by Test::Rails, which is
24 the rails testing framework built into "ZenTest":http://zentest.rubyforge.org.
25 We've also built in first class mocking
26 and stubbing support in order to break dependencies across these different concerns.
28 h2. Different Contexts for different Contexts
30 Spec::Rails supports different Context subclasses for the following types of specs:
34 These are the equivalent of unit tests in Rails'' built in testing. Ironically
35 (for the traditional TDD'er) these are the only specs that we feel should actually interact
36 with the database. "Learn more...":writing/models.html.
38 h3. Controller Examples
40 These align somewhat with functional tests in rails, except
41 that they do not actually render views (though you can force rendering of views
42 if you prefer). Instead of setting expectations about what goes on a page, you
43 set expectations about what templates get rendered. "Learn more...":writing/controllers.html.
47 This is the other half of Rails'' functional testing. View specs allow
48 you to set up assigns (thanks to ZenTest). "Learn more...":writing/views.html.
52 ... let you specify directly methods that live in your helpers. "Learn more...":writing/helpers.html.
54 h3. Integration Examples
56 We also plan to support "Integration Examples":writing/integration.html in the future.
58 For the time being we recommend that you use either
59 "rails integration testing":http://weblog.jamisbuck.org/2006/3/9/integration-testing-in-rails-1-1
60 or another framework like "watir":http://wtr.rubyforge.org/ or "selenium":http://www.openqa.org/selenium/.
64 You can use fixture in any of your specs, be they model, view, controller, or helper. If you have fixtures that you want to use
65 globally, you can set them in spec/spec_helper.rb. See that file for more information.
67 h2. Naming conventions
69 For clarity and consistency, RSpec uses a slightly different naming convention
70 for directories and Rake tasks than what you get from the Test::Unit testing built into rails.
94 The Rake tasks are named accordingly.