rspec-rails 2.8.0.rc2 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +46 -8
- data/features/controller_specs/anonymous_controller.feature +178 -0
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
- data/lib/rspec/rails/example/view_example_group.rb +1 -1
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +4 -4
- data/spec/generators/rspec/view/view_generator_spec.rb +4 -4
- data/spec/rspec/rails/example/view_example_group_spec.rb +9 -0
- metadata +16 -22
data/README.md
CHANGED
@@ -100,21 +100,59 @@ See http://github.com/rspec/rspec-rails/issues
|
|
100
100
|
|
101
101
|
# Request Specs
|
102
102
|
|
103
|
-
Request specs live in spec/requests
|
103
|
+
Request specs live in spec/requests, and mix in behavior
|
104
|
+
[ActionDispatch::Integration::Runner](http://api.rubyonrails.org/classes/ActionDispatch/Integration/Runner.html),
|
105
|
+
which is the basis for [Rails' integration
|
106
|
+
tests](http://guides.rubyonrails.org/testing.html#integration-testing). The
|
107
|
+
intent is to specify one or more request/response cycles from end to end using
|
108
|
+
a black box approach.
|
104
109
|
|
105
110
|
```ruby
|
106
|
-
describe "
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
+
describe "home page" do
|
112
|
+
it "diplays the user's username after successful login" do
|
113
|
+
user = User.create!(:username => "jdoe", :password => "secret")
|
114
|
+
get "/login"
|
115
|
+
assert_select "form.login" do
|
116
|
+
assert_select "input[name=?]", "username"
|
117
|
+
assert_select "input[name=?]", "password"
|
118
|
+
assert_select "input[type=?]", "submit"
|
111
119
|
end
|
120
|
+
|
121
|
+
post "/login", :username => "jdoe", :password => "secret"
|
122
|
+
assert_select ".header .username", :text => "jdoe"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
This example uses only standard Rails and RSpec API's, but many RSpec/Rails
|
128
|
+
users like to use extension libraries like FactoryGirl and Capybara:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
describe "home page" do
|
132
|
+
it "diplays the user's username after successful login" do
|
133
|
+
user = Factory(:user, :username => "jdoe", :password => "secret")
|
134
|
+
visit "/login"
|
135
|
+
fill_in "Username", :with => "jdoe"
|
136
|
+
fill_in "Password", :with => "secret"
|
137
|
+
click_buton "Log in"
|
138
|
+
|
139
|
+
page.should have_selector(".header .username", :content => "jdoe")
|
112
140
|
end
|
113
141
|
end
|
114
142
|
```
|
115
143
|
|
116
|
-
|
117
|
-
|
144
|
+
FactoryGirl decouples this example from changes to validation requirements,
|
145
|
+
which can be encoded into the underlying factory definition without requiring
|
146
|
+
changes to this example.
|
147
|
+
|
148
|
+
Among other benefits, Capybara binds the form post to the generated HTML, which
|
149
|
+
means we don't need to specify them separately.
|
150
|
+
|
151
|
+
There are several other Ruby libs that implement the factory pattern or provide
|
152
|
+
a DSL for request specs (a.k.a. acceptance or integration specs), but
|
153
|
+
FactoryGirl and Capybara seem to be the most widely used. Whether you choose
|
154
|
+
these or other libs, we strongly recommend using something for each of these
|
155
|
+
roles.
|
118
156
|
|
119
157
|
# Controller Specs
|
120
158
|
|
@@ -150,3 +150,181 @@ Feature: anonymous controller
|
|
150
150
|
"""
|
151
151
|
When I run `rspec spec`
|
152
152
|
Then the examples should all pass
|
153
|
+
|
154
|
+
Scenario: anonymous controllers only create resource routes
|
155
|
+
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
156
|
+
"""
|
157
|
+
require "spec_helper"
|
158
|
+
|
159
|
+
describe ApplicationController do
|
160
|
+
controller do
|
161
|
+
def index
|
162
|
+
render :text => "index called"
|
163
|
+
end
|
164
|
+
|
165
|
+
def create
|
166
|
+
render :text => "create called"
|
167
|
+
end
|
168
|
+
|
169
|
+
def new
|
170
|
+
render :text => "new called"
|
171
|
+
end
|
172
|
+
|
173
|
+
def show
|
174
|
+
render :text => "show called"
|
175
|
+
end
|
176
|
+
|
177
|
+
def edit
|
178
|
+
render :text => "edit called"
|
179
|
+
end
|
180
|
+
|
181
|
+
def update
|
182
|
+
render :text => "update called"
|
183
|
+
end
|
184
|
+
|
185
|
+
def destroy
|
186
|
+
render :text => "destroy called"
|
187
|
+
end
|
188
|
+
|
189
|
+
def willerror
|
190
|
+
render :text => "will not render"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#index" do
|
195
|
+
it "responds to GET" do
|
196
|
+
get :index
|
197
|
+
response.body.should == "index called"
|
198
|
+
end
|
199
|
+
|
200
|
+
it "also responds to POST" do
|
201
|
+
post :index
|
202
|
+
response.body.should == "index called"
|
203
|
+
end
|
204
|
+
|
205
|
+
it "also responds to PUT" do
|
206
|
+
put :index
|
207
|
+
response.body.should == "index called"
|
208
|
+
end
|
209
|
+
|
210
|
+
it "also responds to DELETE" do
|
211
|
+
delete :index
|
212
|
+
response.body.should == "index called"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "#create" do
|
217
|
+
it "responds to POST" do
|
218
|
+
post :create
|
219
|
+
response.body.should == "create called"
|
220
|
+
end
|
221
|
+
|
222
|
+
# And the rest...
|
223
|
+
%w{get post put delete}.each do |calltype|
|
224
|
+
it "responds to #{calltype}" do
|
225
|
+
send(calltype, :create)
|
226
|
+
response.body.should == "create called"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "#new" do
|
232
|
+
it "responds to GET" do
|
233
|
+
get :new
|
234
|
+
response.body.should == "new called"
|
235
|
+
end
|
236
|
+
|
237
|
+
# And the rest...
|
238
|
+
%w{get post put delete}.each do |calltype|
|
239
|
+
it "responds to #{calltype}" do
|
240
|
+
send(calltype, :new)
|
241
|
+
response.body.should == "new called"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "#edit" do
|
247
|
+
it "responds to GET" do
|
248
|
+
get :edit, :id => "anyid"
|
249
|
+
response.body.should == "edit called"
|
250
|
+
end
|
251
|
+
|
252
|
+
it "requires the :id parameter" do
|
253
|
+
expect { get :edit }.to raise_error(ActionController::RoutingError)
|
254
|
+
end
|
255
|
+
|
256
|
+
# And the rest...
|
257
|
+
%w{get post put delete}.each do |calltype|
|
258
|
+
it "responds to #{calltype}" do
|
259
|
+
send(calltype, :edit, {:id => "anyid"})
|
260
|
+
response.body.should == "edit called"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#show" do
|
266
|
+
it "responds to GET" do
|
267
|
+
get :show, :id => "anyid"
|
268
|
+
response.body.should == "show called"
|
269
|
+
end
|
270
|
+
|
271
|
+
it "requires the :id parameter" do
|
272
|
+
expect { get :show }.to raise_error(ActionController::RoutingError)
|
273
|
+
end
|
274
|
+
|
275
|
+
# And the rest...
|
276
|
+
%w{get post put delete}.each do |calltype|
|
277
|
+
it "responds to #{calltype}" do
|
278
|
+
send(calltype, :show, {:id => "anyid"})
|
279
|
+
response.body.should == "show called"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "#update" do
|
285
|
+
it "responds to PUT" do
|
286
|
+
put :update, :id => "anyid"
|
287
|
+
response.body.should == "update called"
|
288
|
+
end
|
289
|
+
|
290
|
+
it "requires the :id parameter" do
|
291
|
+
expect { put :update }.to raise_error(ActionController::RoutingError)
|
292
|
+
end
|
293
|
+
|
294
|
+
# And the rest...
|
295
|
+
%w{get post put delete}.each do |calltype|
|
296
|
+
it "responds to #{calltype}" do
|
297
|
+
send(calltype, :update, {:id => "anyid"})
|
298
|
+
response.body.should == "update called"
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe "#destroy" do
|
304
|
+
it "responds to DELETE" do
|
305
|
+
delete :destroy, :id => "anyid"
|
306
|
+
response.body.should == "destroy called"
|
307
|
+
end
|
308
|
+
|
309
|
+
it "requires the :id parameter" do
|
310
|
+
expect { delete :destroy }.to raise_error(ActionController::RoutingError)
|
311
|
+
end
|
312
|
+
|
313
|
+
# And the rest...
|
314
|
+
%w{get post put delete}.each do |calltype|
|
315
|
+
it "responds to #{calltype}" do
|
316
|
+
send(calltype, :destroy, {:id => "anyid"})
|
317
|
+
response.body.should == "destroy called"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe "#willerror" do
|
323
|
+
it "cannot be called" do
|
324
|
+
expect { get :willerror }.to raise_error(ActionController::RoutingError)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
"""
|
329
|
+
When I run `rspec spec`
|
330
|
+
Then the examples should all pass
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/edit
|
4
|
+
describe "<%= ns_table_name %>/edit" do
|
5
5
|
before(:each) do
|
6
6
|
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/index
|
4
|
+
describe "<%= ns_table_name %>/index" do
|
5
5
|
before(:each) do
|
6
6
|
assign(:<%= table_name %>, [
|
7
7
|
<% [1,2].each_with_index do |id, model_index| -%>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/new
|
4
|
+
describe "<%= ns_table_name %>/new" do
|
5
5
|
before(:each) do
|
6
6
|
assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
-
describe "<%= ns_table_name %>/show
|
4
|
+
describe "<%= ns_table_name %>/show" do
|
5
5
|
before(:each) do
|
6
6
|
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
|
7
7
|
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
@@ -10,7 +10,7 @@ module RSpec::Rails
|
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def _default_helper
|
13
|
-
base = metadata[:example_group][:description].split('/').
|
13
|
+
base = metadata[:example_group][:description].split('/')[0..-2].join('/')
|
14
14
|
(base.camelize + 'Helper').constantize if base
|
15
15
|
rescue NameError
|
16
16
|
nil
|
data/lib/rspec/rails/version.rb
CHANGED
@@ -35,7 +35,7 @@ describe Rspec::Generators::ScaffoldGenerator do
|
|
35
35
|
subject { file("spec/views/posts/edit.html.erb_spec.rb") }
|
36
36
|
it { should exist }
|
37
37
|
it { should contain /require 'spec_helper'/ }
|
38
|
-
it { should contain /describe "(.*)\/edit
|
38
|
+
it { should contain /describe "(.*)\/edit"/ }
|
39
39
|
it { should contain /it "renders the edit (.*) form"/ }
|
40
40
|
end
|
41
41
|
|
@@ -43,7 +43,7 @@ describe Rspec::Generators::ScaffoldGenerator do
|
|
43
43
|
subject { file("spec/views/posts/index.html.erb_spec.rb") }
|
44
44
|
it { should exist }
|
45
45
|
it { should contain /require 'spec_helper'/ }
|
46
|
-
it { should contain /describe "(.*)\/index
|
46
|
+
it { should contain /describe "(.*)\/index"/ }
|
47
47
|
it { should contain /it "renders a list of (.*)"/ }
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ describe Rspec::Generators::ScaffoldGenerator do
|
|
51
51
|
subject { file("spec/views/posts/new.html.erb_spec.rb") }
|
52
52
|
it { should exist }
|
53
53
|
it { should contain /require 'spec_helper'/ }
|
54
|
-
it { should contain /describe "(.*)\/new
|
54
|
+
it { should contain /describe "(.*)\/new"/ }
|
55
55
|
it { should contain /it "renders new (.*) form"/ }
|
56
56
|
end
|
57
57
|
|
@@ -59,7 +59,7 @@ describe Rspec::Generators::ScaffoldGenerator do
|
|
59
59
|
subject { file("spec/views/posts/show.html.erb_spec.rb") }
|
60
60
|
it { should exist }
|
61
61
|
it { should contain /require 'spec_helper'/ }
|
62
|
-
it { should contain /describe "(.*)\/show
|
62
|
+
it { should contain /describe "(.*)\/show"/ }
|
63
63
|
it { should contain /it "renders attributes in <p>"/ }
|
64
64
|
end
|
65
65
|
end
|
@@ -14,7 +14,7 @@ describe Rspec::Generators::ViewGenerator do
|
|
14
14
|
run_generator %w(posts index)
|
15
15
|
file('spec/views/posts/index.html.erb_spec.rb').tap do |f|
|
16
16
|
f.should contain /require 'spec_helper'/
|
17
|
-
f.should contain /describe "posts\/index
|
17
|
+
f.should contain /describe "posts\/index"/
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -23,18 +23,18 @@ describe Rspec::Generators::ViewGenerator do
|
|
23
23
|
run_generator %w(admin/posts index)
|
24
24
|
file('spec/views/admin/posts/index.html.erb_spec.rb').tap do |f|
|
25
25
|
f.should contain /require 'spec_helper'/
|
26
|
-
f.should contain /describe "admin\/posts\/index
|
26
|
+
f.should contain /describe "admin\/posts\/index"/
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe '
|
32
|
+
describe 'with a specified template engine' do
|
33
33
|
it 'generates a spec for the supplied action' do
|
34
34
|
run_generator %w(posts index --template_engine haml)
|
35
35
|
file('spec/views/posts/index.html.haml_spec.rb').tap do |f|
|
36
36
|
f.should contain /require 'spec_helper'/
|
37
|
-
f.should contain /describe "posts\/index
|
37
|
+
f.should contain /describe "posts\/index"/
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -14,6 +14,7 @@ module RSpec::Rails
|
|
14
14
|
|
15
15
|
describe 'automatic inclusion of helpers' do
|
16
16
|
module ::ThingsHelper; end
|
17
|
+
module ::Namespaced; module ThingsHelper; end; end
|
17
18
|
|
18
19
|
it 'includes the helper with the same name' do
|
19
20
|
group = RSpec::Core::ExampleGroup.describe 'things/show.html.erb'
|
@@ -23,6 +24,14 @@ module RSpec::Rails
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
27
|
+
it 'includes the namespaced helper with the same name' do
|
28
|
+
group = RSpec::Core::ExampleGroup.describe 'namespaced/things/show.html.erb'
|
29
|
+
group.should_receive(:helper).with(Namespaced::ThingsHelper)
|
30
|
+
group.class_eval do
|
31
|
+
include ViewExampleGroup
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
26
35
|
it 'operates normally when no helper with the same name exists' do
|
27
36
|
raise 'unexpected constant found' if Object.const_defined?('ClocksHelper')
|
28
37
|
lambda {
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 47
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 8
|
9
9
|
- 0
|
10
|
-
|
11
|
-
- 2
|
12
|
-
version: 2.8.0.rc2
|
10
|
+
version: 2.8.0
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- David Chelimsky
|
@@ -17,13 +15,13 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date:
|
18
|
+
date: 2012-01-05 00:00:00 Z
|
21
19
|
dependencies:
|
22
20
|
- !ruby/object:Gem::Dependency
|
23
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
hash: 7
|
29
27
|
segments:
|
@@ -38,7 +36,7 @@ dependencies:
|
|
38
36
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
37
|
none: false
|
40
38
|
requirements:
|
41
|
-
- -
|
39
|
+
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
41
|
hash: 7
|
44
42
|
segments:
|
@@ -53,7 +51,7 @@ dependencies:
|
|
53
51
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
52
|
none: false
|
55
53
|
requirements:
|
56
|
-
- -
|
54
|
+
- - ">="
|
57
55
|
- !ruby/object:Gem::Version
|
58
56
|
hash: 7
|
59
57
|
segments:
|
@@ -68,21 +66,19 @@ dependencies:
|
|
68
66
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
67
|
none: false
|
70
68
|
requirements:
|
71
|
-
- -
|
69
|
+
- - ~>
|
72
70
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
71
|
+
hash: 47
|
74
72
|
segments:
|
75
73
|
- 2
|
76
74
|
- 8
|
77
75
|
- 0
|
78
|
-
|
79
|
-
- 2
|
80
|
-
version: 2.8.0.rc2
|
76
|
+
version: 2.8.0
|
81
77
|
prerelease: false
|
82
78
|
requirement: *id004
|
83
79
|
name: rspec
|
84
80
|
type: :runtime
|
85
|
-
description: RSpec
|
81
|
+
description: RSpec for Rails
|
86
82
|
email: rspec-users@rubyforge.org
|
87
83
|
executables: []
|
88
84
|
|
@@ -249,21 +245,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
249
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
246
|
none: false
|
251
247
|
requirements:
|
252
|
-
- - "
|
248
|
+
- - ">="
|
253
249
|
- !ruby/object:Gem::Version
|
254
|
-
hash:
|
250
|
+
hash: 3
|
255
251
|
segments:
|
256
|
-
-
|
257
|
-
|
258
|
-
- 1
|
259
|
-
version: 1.3.1
|
252
|
+
- 0
|
253
|
+
version: "0"
|
260
254
|
requirements: []
|
261
255
|
|
262
256
|
rubyforge_project: rspec
|
263
257
|
rubygems_version: 1.8.11
|
264
258
|
signing_key:
|
265
259
|
specification_version: 3
|
266
|
-
summary: rspec-rails-2.8.0
|
260
|
+
summary: rspec-rails-2.8.0
|
267
261
|
test_files:
|
268
262
|
- features/Autotest.md
|
269
263
|
- features/Generators.md
|