Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rdoc

  • Loading branch information...
commit 9bf3e32e8d086af4ccc25575223be49df3e864e1 1 parent eb08f7d
@dchelimsky dchelimsky authored
View
60 README.md
@@ -47,6 +47,17 @@ Please note that the generators are there to help you get started, but they are
no substitute for writing your own examples, and they are only guaranteed to
work out of the box for the default scenario (`ActiveRecord` + `Webrat`).
+### Webrat and Capybara
+
+You can choose between webrat or capybara for simulating a browser, automating
+a browser, or setting expectations using the matchers they supply. Just add
+your preference to the Gemfile:
+
+```ruby
+gem "webrat"
+gem "capybara"
+```
+
### Autotest
The `rspec:install` generator creates an `.rspec` file, which tells Autotest
@@ -62,17 +73,6 @@ gems, you can just type `autotest`. If, however, Bundler is managing any gems
for you directly (i.e. you've got `:git` or `:path` attributes in the `Gemfile`),
you'll need to run `bundle exec autotest`.
-### Webrat and Capybara
-
-You can choose between webrat or capybara for simulating a browser, automating
-a browser, or setting expectations using the matchers they supply. Just add
-your preference to the Gemfile:
-
-```ruby
-gem "webrat"
-gem "capybara"
-```
-
## Living on edge
Bundler makes it a snap to use the latest code for any gem your app depends on. For
@@ -135,6 +135,7 @@ available from Rails.
You can use RSpec expectations/matchers or Test::Unit assertions.
## `render_views`
+
By default, controller specs do not render views. This supports specifying
controllers without concern for whether the views they render work correctly
(NOTE: the template must exist, unlike rspec-rails-1. See Upgrade.md for more
@@ -148,7 +149,7 @@ describe SomeController do
# ...
```
-### * Upgrade note
+### Upgrade note
`render_views` replaces `integrate_views` from rspec-rails-1.3
@@ -231,7 +232,7 @@ RSpec doesn't officially support this pattern, which only works as a
side-effect of the inclusion of `ActionView::TestCase`. Be aware that it may be
made unavailable in the future.
-### * Upgrade note
+### Upgrade note
```ruby
# rspec-rails-1.x
@@ -250,7 +251,7 @@ render
rendered.should =~ /Some text expected to appear on the page/
```
-### * Upgrade note
+### Upgrade note
```ruby
# rspec-rails-1.x
@@ -262,6 +263,31 @@ render
rendered.should xxx
```
+# Model specs
+
+Model specs live in spec/models.
+
+```ruby
+describe Articles do
+ describe ".recent" do
+ it "includes articles published less than one week ago" do
+ article = Article.create!(:published_at => Date.today - 1.week + 1.second)
+ Article.recent.should eq([article])
+ end
+
+ it "excludes articles published at midnight one week ago" do
+ article = Article.create!(:published_at => Date.today - 1.week)
+ Article.recent.should be_empty
+ end
+
+ it "excludes articles published more than one week ago" do
+ article = Article.create!(:published_at => Date.today - 1.week - 1.second)
+ Article.recent.should be_empty
+ end
+ end
+end
+```
+
# Routing specs
Routing specs live in spec/routing.
@@ -282,7 +308,7 @@ describe "routing to profiles" do
end
```
-### * Upgrade note
+### Upgrade note
`route_for` from rspec-rails-1.x is gone. Use `route_to` and `be_routable` instead.
@@ -361,11 +387,11 @@ to be used with `should_not` to specify routes that should not be routable.
{ :get => "/widgets/1/edit" }.should_not be_routable
```
-## Contribute
+# Contribute
See [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)
-## Also see
+# Also see
* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
* [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
View
53 lib/rspec/rails/example/controller_example_group.rb
@@ -14,41 +14,41 @@ module RSpec::Rails
#
# ### with fixtures
#
- # describe WidgetsController do
- # describe "GET index" do
- # fixtures :widgets
- #
- # it "assigns all widgets to @widgets" do
- # get :index
- # assigns(:widgets).should eq(Widget.all)
+ # describe WidgetsController do
+ # describe "GET index" do
+ # fixtures :widgets
+ #
+ # it "assigns all widgets to @widgets" do
+ # get :index
+ # assigns(:widgets).should eq(Widget.all)
+ # end
# end
# end
- # end
#
# ### with a factory
#
- # describe WidgetsController do
- # describe "GET index" do
- # it "assigns all widgets to @widgets" do
- # widget = Factory(:widget)
- # get :index
- # assigns(:widgets).should eq([widget])
+ # describe WidgetsController do
+ # describe "GET index" do
+ # it "assigns all widgets to @widgets" do
+ # widget = Factory(:widget)
+ # get :index
+ # assigns(:widgets).should eq([widget])
+ # end
# end
# end
- # end
#
# ## with stubs
#
- # describe WidgetsController do
- # describe "GET index" do
- # it "assigns all widgets to @widgets" do
- # widget = stub_model(Widget)
- # Widget.stub(:all) { widget }
- # get :index
- # assigns(:widgets).should eq([widget])
+ # describe WidgetsController do
+ # describe "GET index" do
+ # it "assigns all widgets to @widgets" do
+ # widget = stub_model(Widget)
+ # Widget.stub(:all) { [widget] }
+ # get :index
+ # assigns(:widgets).should eq([widget])
+ # end
# end
# end
- # end
#
# ## Matchers
#
@@ -79,10 +79,9 @@ module RSpec::Rails
# functional tests, you can tell controller groups to render the views in the
# app with the +render_views+ declaration:
#
- # describe WidgetsController do
- # render_views
- # ...
- #
+ # describe WidgetsController do
+ # render_views
+ # # ...
module ControllerExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup
View
35 lib/rspec/rails/example/helper_example_group.rb
@@ -3,28 +3,30 @@
module RSpec::Rails
# Extends ActionView::TestCase::Behavior
#
- # == Examples
+ # Provides a `helper` object which mixes in the helper module being spec'd,
+ # along with `ApplicationHelper` (if present).
#
- # describe RoleBasedDisplayHelper do
- # describe "display_for" do
- # context "given the role of the current user" do
- # it "yields to the block" do
- # helper.stub(:current_user) { double(:roles => ['admin'] }
- # text = helper.display_for('admin') { "this text" }
- # text.should eq("this text")
+ # @example
+ #
+ # describe RoleBasedDisplayHelper do
+ # describe "display_for" do
+ # context "given the role of the current user" do
+ # it "yields to the block" do
+ # helper.stub(:current_user) { double(:roles => ['admin']) }
+ # text = helper.display_for('admin') { "this text" }
+ # text.should eq("this text")
+ # end
# end
- # end
#
- # context "given a different role that that of the current user" do
- # it "renders an empty String" do
- # helper.stub(:current_user) { double(:roles => ['manager'] }
- # text = helper.display_for('admin') { "this text" }
- # text.should eq("")
+ # context "given a different role that that of the current user" do
+ # it "renders an empty String" do
+ # helper.stub(:current_user) { double(:roles => ['manager']) }
+ # text = helper.display_for('admin') { "this text" }
+ # text.should eq("")
+ # end
# end
# end
# end
- # end
- #
module HelperExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup
@@ -32,6 +34,7 @@ module HelperExampleGroup
include RSpec::Rails::ViewAssigns
module ClassMethods
+ # @api private
def determine_default_helper_class(ignore)
described_class
end
View
1  lib/rspec/rails/example/model_example_group.rb
@@ -1,4 +1,5 @@
module RSpec::Rails
+ # The basis for model specs
module ModelExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup
View
10 lib/rspec/rails/example/request_example_group.rb
@@ -1,16 +1,16 @@
module RSpec::Rails
# Extends ActionDispatch::Integration::Runner to work with RSpec.
#
- # == Matchers
+ # ## Matchers
#
# In addition to the stock matchers from rspec-expectations, request
# specs add these matchers, which delegate to rails' assertions:
#
- # response.should render_template(*args)
- # => delegates to assert_template(*args)
+ # response.should render_template(*args)
+ # # => delegates to assert_template(*args)
#
- # response.should redirect_to(destination)
- # => delegates to assert_redirected_to(destination)
+ # response.should redirect_to(destination)
+ # # => delegates to assert_redirected_to(destination)
module RequestExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup
View
13 lib/rspec/rails/example/routing_example_group.rb
@@ -1,6 +1,19 @@
require "action_dispatch/testing/assertions/routing"
module RSpec::Rails
+ # Routing specs live in spec/routing. If `config/routes.rb` has nothing
+ # beyond `map.resources :thing`, then you probably don't need a routing spec,
+ # but they can be quite helpful when specifying non-standard routes.
+ #
+ # @example
+ #
+ # require 'spec_helper'
+ #
+ # describe "profiles routes" do
+ # it "routes /profiles/jdoe" do
+ # get("/profiles/jdoe").should route_to("profiles#show", :username => 'jdoe')
+ # end
+ # end
module RoutingExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::RailsExampleGroup
Please sign in to comment.
Something went wrong with that request. Please try again.