Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 85 lines (60 sloc) 2.329 kb
909fa3b @dchelimsky docs
dchelimsky authored
1 Install Rails-3
2
3 $ gem install rails -v "~> 3.0.0"
4
5 ### Generate an app
6
7 $ rails new example
8 $ cd example
9
10 ### Add rspec-rails to the Gemfile
11
12 $ echo 'gem "rspec-rails", :group => [:development, :test]' >> Gemfile
13
14 ### Install the bundle
15
16 $ bundle install
17
e77d224 @dchelimsky doc update
dchelimsky authored
18 ### Bootstrap RSpec
19
20 $ rails generate rspec:install
21
909fa3b @dchelimsky docs
dchelimsky authored
22 ### Generate a scaffold
23
24 $ rails generate scaffold Widgets name:string
25
26 This generates files in the `app` and `spec` directories. The files in the
27 `app` directory are generated by Rails, and Rails delegates the generation of
28 the files in the `spec` directory to RSpec.
29
30 ### Run migrations
31
32 $ rake db:migrate && rake db:test:prepare
33
34 ### Run RSpec
35
36 $ rake spec
37
38 or
39
e77d224 @dchelimsky doc update
dchelimsky authored
40 $ rspec spec --format documentation
909fa3b @dchelimsky docs
dchelimsky authored
41
42 If all went well, you should see output ending with:
43
44 29 examples, 0 failures, 2 pending
e77d224 @dchelimsky doc update
dchelimsky authored
45
46 This output also includes the following controller spec:
47
48 WidgetsController
49 GET index
50 assigns all widgets as @widgets
51 GET show
52 assigns the requested widget as @widget
53 GET new
54 assigns a new widget as @widget
55 GET edit
56 assigns the requested widget as @widget
57 POST create
58 with valid params
59 creates a new Widget
60 assigns a newly created widget as @widget
61 redirects to the created widget
62 with invalid params
63 assigns a newly created but unsaved widget as @widget
64 re-renders the 'new' template
65 PUT update
66 with valid params
67 updates the requested widget
68 assigns the requested widget as @widget
69 redirects to the widget
70 with invalid params
71 assigns the widget as @widget
72 re-renders the 'edit' template
73 DELETE destroy
74 destroys the requested widget
75 redirects to the widgets list
76
77 Output like this can help to quickly gain a high level understanding of how an
78 object behaves. It also exposes which cases have been specified and which have
79 not. Note the balance between the examples for the `create` and `update`
80 actions. If the `redirects to the widget` example was missing from one or the
81 other, it would be easy to spot.
82
83 Take a look at the generated `spec/controllers/widgets_controller_spec.rb` to
84 get a sense of how to organize your specs to generate output like this.
Something went wrong with that request. Please try again.