Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

doc update

  • Loading branch information...
commit e77d2240a396e448e0638287a11198c7a0cd6b9f 1 parent 33c14a2
@dchelimsky dchelimsky authored
2  README.md
@@ -2,6 +2,8 @@
rspec-2 for rails-3 with lightweight extensions to each
+[![build status](http://travis-ci.org/rspec/rspec-rails.png)](http://travis-ci.org/rspec/rspec-rails)
+
NOTE: rspec-2 does _not_ support rails-2. Use rspec-rails-1.3.x for rails-2.
## Documentation
View
46 features/GettingStarted.md
@@ -15,6 +15,10 @@ Install Rails-3
$ bundle install
+### Bootstrap RSpec
+
+ $ rails generate rspec:install
+
### Generate a scaffold
$ rails generate scaffold Widgets name:string
@@ -33,8 +37,48 @@ the files in the `spec` directory to RSpec.
or
- $ rspec spec
+ $ rspec spec --format documentation
If all went well, you should see output ending with:
29 examples, 0 failures, 2 pending
+
+This output also includes the following controller spec:
+
+ WidgetsController
+ GET index
+ assigns all widgets as @widgets
+ GET show
+ assigns the requested widget as @widget
+ GET new
+ assigns a new widget as @widget
+ GET edit
+ assigns the requested widget as @widget
+ POST create
+ with valid params
+ creates a new Widget
+ assigns a newly created widget as @widget
+ redirects to the created widget
+ with invalid params
+ assigns a newly created but unsaved widget as @widget
+ re-renders the 'new' template
+ PUT update
+ with valid params
+ updates the requested widget
+ assigns the requested widget as @widget
+ redirects to the widget
+ with invalid params
+ assigns the widget as @widget
+ re-renders the 'edit' template
+ DELETE destroy
+ destroys the requested widget
+ redirects to the widgets list
+
+Output like this can help to quickly gain a high level understanding of how an
+object behaves. It also exposes which cases have been specified and which have
+not. Note the balance between the examples for the `create` and `update`
+actions. If the `redirects to the widget` example was missing from one or the
+other, it would be easy to spot.
+
+Take a look at the generated `spec/controllers/widgets_controller_spec.rb` to
+get a sense of how to organize your specs to generate output like this.
View
29 lib/generators/rspec/scaffold/templates/controller_spec.rb
@@ -2,25 +2,22 @@
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
-# was generated by the Rails when you ran the scaffold generator.
+# was generated by Rails when you ran the scaffold generator.
#
-# Caveats:
-#
-# This assumes that the implementation code is the stock implemenation code
-# generated by the rails scaffold generator. If you are using any extension
-# libraries to generate different controller code, this generated spec may or
-# may not work.
+# It assumes that the implementation code is the stock implemenation code
+# generated by the rails scaffold generator. If you are using any extension
+# libraries to generate different controller code, this generated spec may or
+# may not pass.
#
-# This only uses APIs available in rails and/or rspec-rails. There are a
-# number of tools you can use to make these specs even more expressive, but
-# we're sticking to rails and rspec-rails APIs to keep things simple and
-# stable.
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
-# Compared to earlier versions of this generator, there is very limited use
-# of stubs and message expectations in this spec. Stubs are only used when
-# there is no simpler way to get a handle on the object needed for the
-# example. Message expectations are only used when there is no simpler way to
-# specify that an instance is receiving a specific message.
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
describe <%= controller_class_name %>Controller do
Please sign in to comment.
Something went wrong with that request. Please try again.