rspec-rails 2.11.4 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Capybara.md +2 -2
- data/Changelog.md +25 -1
- data/README.md +61 -25
- data/features/controller_specs/anonymous_controller.feature +25 -25
- data/features/controller_specs/bypass_rescue.feature +4 -4
- data/features/controller_specs/controller_spec.feature +4 -4
- data/features/controller_specs/isolation_from_views.feature +13 -13
- data/features/controller_specs/render_views.feature +11 -11
- data/features/feature_specs/feature_spec.feature +34 -0
- data/features/helper_specs/helper_spec.feature +10 -10
- data/features/mailer_specs/url_helpers.feature +7 -7
- data/features/matchers/new_record_matcher.feature +20 -7
- data/features/matchers/redirect_to_matcher.feature +6 -6
- data/features/matchers/relation_match_array.feature +8 -6
- data/features/matchers/render_template_matcher.feature +25 -4
- data/features/mocks/mock_model.feature +21 -21
- data/features/mocks/stub_model.feature +8 -8
- data/features/model_specs/errors_on.feature +25 -7
- data/features/model_specs/transactional_examples.feature +13 -13
- data/features/request_specs/request_spec.feature +8 -8
- data/features/routing_specs/be_routable_matcher.feature +10 -10
- data/features/routing_specs/named_routes.feature +3 -3
- data/features/routing_specs/route_to_matcher.feature +17 -17
- data/features/view_specs/inferred_controller_path.feature +7 -6
- data/features/view_specs/stub_template.feature +5 -5
- data/features/view_specs/view_spec.feature +50 -18
- data/lib/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec.rb +6 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +2 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +2 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -0
- data/lib/generators/rspec/model/templates/model_spec.rb +2 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +2 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +37 -3
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +9 -7
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +2 -0
- data/lib/rspec/rails/example.rb +5 -1
- data/lib/rspec/rails/example/feature_example_group.rb +30 -0
- data/lib/rspec/rails/example/view_example_group.rb +23 -12
- data/lib/rspec/rails/extensions.rb +1 -0
- data/lib/rspec/rails/extensions/active_record/base.rb +5 -3
- data/lib/rspec/rails/extensions/active_record/proxy.rb +17 -0
- data/lib/rspec/rails/matchers/be_new_record.rb +8 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -2
- data/lib/rspec/rails/vendor/capybara.rb +2 -8
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/autotest/rails_rspec2_spec.rb +4 -4
- data/spec/generators/rspec/model/model_generator_spec.rb +1 -1
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +8 -0
- data/spec/rspec/rails/example/feature_example_group_spec.rb +56 -0
- data/spec/rspec/rails/example/view_example_group_spec.rb +7 -1
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +16 -2
- data/spec/rspec/rails/matchers/has_spec.rb +29 -0
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +18 -7
- metadata +66 -10
@@ -4,13 +4,13 @@ Feature: named routes
|
|
4
4
|
|
5
5
|
Scenario: access named route
|
6
6
|
Given a file named "spec/routing/widget_routes_spec.rb" with:
|
7
|
-
"""
|
7
|
+
"""ruby
|
8
8
|
require "spec_helper"
|
9
9
|
|
10
10
|
describe "routes to the widgets controller" do
|
11
11
|
it "routes a named route" do
|
12
|
-
|
13
|
-
|
12
|
+
expect(:get => new_widget_path).
|
13
|
+
to route_to(:controller => "widgets", :action => "new")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
"""
|
@@ -4,21 +4,21 @@ Feature: route_to matcher
|
|
4
4
|
It is most valuable when specifying routes other than standard RESTful
|
5
5
|
routes.
|
6
6
|
|
7
|
-
get("/").
|
7
|
+
expect(get("/")).to route_to("welcome#index") # new in 2.6.0
|
8
8
|
|
9
9
|
or
|
10
10
|
|
11
|
-
|
11
|
+
expect(:get => "/").to route_to(:controller => "welcome")
|
12
12
|
|
13
13
|
Scenario: passing route spec with shortcut syntax
|
14
14
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
15
|
-
"""
|
15
|
+
"""ruby
|
16
16
|
require "spec_helper"
|
17
17
|
|
18
18
|
describe "routes for Widgets" do
|
19
19
|
it "routes /widgets to the widgets controller" do
|
20
|
-
get("/widgets").
|
21
|
-
|
20
|
+
expect(get("/widgets")).
|
21
|
+
to route_to("widgets#index")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
"""
|
@@ -28,13 +28,13 @@ Feature: route_to matcher
|
|
28
28
|
|
29
29
|
Scenario: passing route spec with verbose syntax
|
30
30
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
31
|
-
"""
|
31
|
+
"""ruby
|
32
32
|
require "spec_helper"
|
33
33
|
|
34
34
|
describe "routes for Widgets" do
|
35
35
|
it "routes /widgets to the widgets controller" do
|
36
|
-
|
37
|
-
|
36
|
+
expect(:get => "/widgets").
|
37
|
+
to route_to(:controller => "widgets", :action => "index")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
"""
|
@@ -44,12 +44,12 @@ Feature: route_to matcher
|
|
44
44
|
|
45
45
|
Scenario: route spec for a route that doesn't exist (fails)
|
46
46
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
47
|
-
"""
|
47
|
+
"""ruby
|
48
48
|
require "spec_helper"
|
49
49
|
|
50
50
|
describe "routes for Widgets" do
|
51
51
|
it "routes /widgets/foo to the /foo action" do
|
52
|
-
get("/widgets/foo").
|
52
|
+
expect(get("/widgets/foo")).to route_to("widgets#foo")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
"""
|
@@ -59,13 +59,13 @@ Feature: route_to matcher
|
|
59
59
|
|
60
60
|
Scenario: route spec for a namespaced route with shortcut specifier
|
61
61
|
Given a file named "spec/routing/admin_routing_spec.rb" with:
|
62
|
-
"""
|
62
|
+
"""ruby
|
63
63
|
require "spec_helper"
|
64
64
|
|
65
65
|
describe "routes for Widgets" do
|
66
66
|
it "routes /admin/accounts to the admin/accounts controller" do
|
67
|
-
get("/admin/accounts").
|
68
|
-
|
67
|
+
expect(get("/admin/accounts")).
|
68
|
+
to route_to("admin/accounts#index")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
"""
|
@@ -75,16 +75,16 @@ Feature: route_to matcher
|
|
75
75
|
|
76
76
|
Scenario: route spec for a namespaced route with verbose specifier
|
77
77
|
Given a file named "spec/routing/admin_routing_spec.rb" with:
|
78
|
-
"""
|
78
|
+
"""ruby
|
79
79
|
require "spec_helper"
|
80
80
|
|
81
81
|
describe "routes for Widgets" do
|
82
82
|
it "routes /admin/accounts to the admin/accounts controller" do
|
83
|
-
get("/admin/accounts").
|
84
|
-
|
83
|
+
expect(get("/admin/accounts")).
|
84
|
+
to route_to(:controller => "admin/accounts", :action => "index")
|
85
85
|
end
|
86
86
|
end
|
87
87
|
"""
|
88
88
|
|
89
89
|
When I run `rspec spec/routing/admin_routing_spec.rb`
|
90
|
-
Then the examples should all pass
|
90
|
+
Then the examples should all pass
|
@@ -2,12 +2,13 @@ Feature: view spec infers controller path and action
|
|
2
2
|
|
3
3
|
Scenario: infer controller path
|
4
4
|
Given a file named "spec/views/widgets/new.html.erb_spec.rb" with:
|
5
|
-
"""
|
5
|
+
"""ruby
|
6
6
|
require "spec_helper"
|
7
7
|
|
8
8
|
describe "widgets/new" do
|
9
9
|
it "infers the controller path" do
|
10
|
-
controller.request.path_parameters[:controller].
|
10
|
+
expect(controller.request.path_parameters[:controller]).to eq("widgets")
|
11
|
+
expect(controller.controller_path).to eq("widgets")
|
11
12
|
end
|
12
13
|
end
|
13
14
|
"""
|
@@ -16,12 +17,12 @@ Feature: view spec infers controller path and action
|
|
16
17
|
|
17
18
|
Scenario: infer action
|
18
19
|
Given a file named "spec/views/widgets/new.html.erb_spec.rb" with:
|
19
|
-
"""
|
20
|
+
"""ruby
|
20
21
|
require "spec_helper"
|
21
22
|
|
22
23
|
describe "widgets/new" do
|
23
24
|
it "infers the controller path" do
|
24
|
-
controller.request.path_parameters[:action].
|
25
|
+
expect(controller.request.path_parameters[:action]).to eq("new")
|
25
26
|
end
|
26
27
|
end
|
27
28
|
"""
|
@@ -30,12 +31,12 @@ Feature: view spec infers controller path and action
|
|
30
31
|
|
31
32
|
Scenario: do not infer action in a partial
|
32
33
|
Given a file named "spec/views/widgets/_form.html.erb_spec.rb" with:
|
33
|
-
"""
|
34
|
+
"""ruby
|
34
35
|
require "spec_helper"
|
35
36
|
|
36
37
|
describe "widgets/_form" do
|
37
38
|
it "includes a link to new" do
|
38
|
-
controller.request.path_parameters[:action].
|
39
|
+
expect(controller.request.path_parameters[:action]).to be_nil
|
39
40
|
end
|
40
41
|
end
|
41
42
|
"""
|
@@ -5,7 +5,7 @@ Feature: stub template
|
|
5
5
|
|
6
6
|
Scenario: stub template that does not exist
|
7
7
|
Given a file named "spec/views/gadgets/list.html.erb_spec.rb" with:
|
8
|
-
"""
|
8
|
+
"""ruby
|
9
9
|
require "spec_helper"
|
10
10
|
|
11
11
|
describe "gadgets/list" do
|
@@ -16,8 +16,8 @@ Feature: stub template
|
|
16
16
|
])
|
17
17
|
stub_template "gadgets/_gadget.html.erb" => "<%= gadget.name %><br/>"
|
18
18
|
render
|
19
|
-
rendered.
|
20
|
-
rendered.
|
19
|
+
expect(rendered).to match /First/
|
20
|
+
expect(rendered).to match /Second/
|
21
21
|
end
|
22
22
|
end
|
23
23
|
"""
|
@@ -31,7 +31,7 @@ Feature: stub template
|
|
31
31
|
|
32
32
|
Scenario: stub template that exists
|
33
33
|
Given a file named "spec/views/gadgets/edit.html.erb_spec.rb" with:
|
34
|
-
"""
|
34
|
+
"""ruby
|
35
35
|
require "spec_helper"
|
36
36
|
|
37
37
|
describe "gadgets/edit" do
|
@@ -42,7 +42,7 @@ Feature: stub template
|
|
42
42
|
it "renders the form partial" do
|
43
43
|
stub_template "gadgets/_form.html.erb" => "This content"
|
44
44
|
render
|
45
|
-
rendered.
|
45
|
+
expect(rendered).to match /This content/
|
46
46
|
end
|
47
47
|
end
|
48
48
|
"""
|
@@ -4,7 +4,7 @@ Feature: view spec
|
|
4
4
|
|
5
5
|
Scenario: passing spec that renders the described view file
|
6
6
|
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
7
|
-
"""
|
7
|
+
"""ruby
|
8
8
|
require "spec_helper"
|
9
9
|
|
10
10
|
describe "widgets/index" do
|
@@ -16,8 +16,8 @@ Feature: view spec
|
|
16
16
|
|
17
17
|
render
|
18
18
|
|
19
|
-
rendered.
|
20
|
-
rendered.
|
19
|
+
expect(rendered).to match /slicer/
|
20
|
+
expect(rendered).to match /dicer/
|
21
21
|
end
|
22
22
|
end
|
23
23
|
"""
|
@@ -26,7 +26,7 @@ Feature: view spec
|
|
26
26
|
|
27
27
|
Scenario: passing spec with before and nesting
|
28
28
|
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
29
|
-
"""
|
29
|
+
"""ruby
|
30
30
|
require "spec_helper"
|
31
31
|
|
32
32
|
describe "widgets/index" do
|
@@ -42,8 +42,8 @@ Feature: view spec
|
|
42
42
|
it "displays both widgets" do
|
43
43
|
render
|
44
44
|
|
45
|
-
rendered.
|
46
|
-
rendered.
|
45
|
+
expect(rendered).to match /slicer/
|
46
|
+
expect(rendered).to match /dicer/
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -53,7 +53,7 @@ Feature: view spec
|
|
53
53
|
|
54
54
|
Scenario: passing spec with explicit template rendering
|
55
55
|
Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
|
56
|
-
"""
|
56
|
+
"""ruby
|
57
57
|
require "spec_helper"
|
58
58
|
|
59
59
|
describe "rendering the widget template" do
|
@@ -62,7 +62,7 @@ Feature: view spec
|
|
62
62
|
|
63
63
|
render :template => "widgets/widget.html.erb"
|
64
64
|
|
65
|
-
rendered.
|
65
|
+
expect(rendered).to match /slicer/
|
66
66
|
end
|
67
67
|
end
|
68
68
|
"""
|
@@ -73,9 +73,41 @@ Feature: view spec
|
|
73
73
|
When I run `rspec spec/views`
|
74
74
|
Then the examples should all pass
|
75
75
|
|
76
|
+
Scenario: passing spec with a description that includes the format and handler
|
77
|
+
Given a file named "spec/views/widgets/widget.xml.erb_spec.rb" with:
|
78
|
+
"""ruby
|
79
|
+
require "spec_helper"
|
80
|
+
|
81
|
+
describe "widgets/widget.html.erb" do
|
82
|
+
it "renders the HTML template" do
|
83
|
+
render
|
84
|
+
|
85
|
+
expect(rendered).to match /HTML/
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "widgets/widget.xml.erb" do
|
90
|
+
it "renders the XML template" do
|
91
|
+
render
|
92
|
+
|
93
|
+
expect(rendered).to match /XML/
|
94
|
+
end
|
95
|
+
end
|
96
|
+
"""
|
97
|
+
And a file named "app/views/widgets/widget.html.erb" with:
|
98
|
+
"""
|
99
|
+
HTML
|
100
|
+
"""
|
101
|
+
And a file named "app/views/widgets/widget.xml.erb" with:
|
102
|
+
"""
|
103
|
+
XML
|
104
|
+
"""
|
105
|
+
When I run `rspec spec/views`
|
106
|
+
Then the examples should all pass
|
107
|
+
|
76
108
|
Scenario: passing spec with rendering of locals in a partial
|
77
109
|
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
78
|
-
"""
|
110
|
+
"""ruby
|
79
111
|
require "spec_helper"
|
80
112
|
|
81
113
|
describe "rendering locals in a partial" do
|
@@ -84,7 +116,7 @@ Feature: view spec
|
|
84
116
|
|
85
117
|
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
|
86
118
|
|
87
|
-
rendered.
|
119
|
+
expect(rendered).to match /slicer/
|
88
120
|
end
|
89
121
|
end
|
90
122
|
"""
|
@@ -97,7 +129,7 @@ Feature: view spec
|
|
97
129
|
|
98
130
|
Scenario: passing spec with rendering of locals in an implicit partial
|
99
131
|
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
100
|
-
"""
|
132
|
+
"""ruby
|
101
133
|
require "spec_helper"
|
102
134
|
|
103
135
|
describe "rendering locals in a partial" do
|
@@ -106,7 +138,7 @@ Feature: view spec
|
|
106
138
|
|
107
139
|
render "widgets/widget", :widget => widget
|
108
140
|
|
109
|
-
rendered.
|
141
|
+
expect(rendered).to match /slicer/
|
110
142
|
end
|
111
143
|
end
|
112
144
|
"""
|
@@ -119,7 +151,7 @@ Feature: view spec
|
|
119
151
|
|
120
152
|
Scenario: passing spec with rendering of text
|
121
153
|
Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with:
|
122
|
-
"""
|
154
|
+
"""ruby
|
123
155
|
require "spec_helper"
|
124
156
|
|
125
157
|
describe "rendering text directly" do
|
@@ -127,7 +159,7 @@ Feature: view spec
|
|
127
159
|
|
128
160
|
render :text => "This is directly rendered"
|
129
161
|
|
130
|
-
rendered.
|
162
|
+
expect(rendered).to match /directly rendered/
|
131
163
|
end
|
132
164
|
end
|
133
165
|
"""
|
@@ -142,7 +174,7 @@ Feature: view spec
|
|
142
174
|
<%- end %>
|
143
175
|
"""
|
144
176
|
And a file named "spec/views/secrets/index.html.erb_spec.rb" with:
|
145
|
-
"""
|
177
|
+
"""ruby
|
146
178
|
require 'spec_helper'
|
147
179
|
|
148
180
|
describe 'secrets/index' do
|
@@ -152,7 +184,7 @@ Feature: view spec
|
|
152
184
|
|
153
185
|
it 'checks for admin access' do
|
154
186
|
render
|
155
|
-
rendered.
|
187
|
+
expect(rendered).to match /Secret admin area/
|
156
188
|
end
|
157
189
|
end
|
158
190
|
"""
|
@@ -161,12 +193,12 @@ Feature: view spec
|
|
161
193
|
|
162
194
|
Scenario: request.path_parameters should match Rails by using symbols for keys
|
163
195
|
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
164
|
-
"""
|
196
|
+
"""ruby
|
165
197
|
require "spec_helper"
|
166
198
|
|
167
199
|
describe "controller.request.path_parameters" do
|
168
200
|
it "matches the Rails environment by using symbols for keys" do
|
169
|
-
[:controller, :action].each { |k| controller.request.path_parameters.keys.
|
201
|
+
[:controller, :action].each { |k| expect(controller.request.path_parameters.keys).to include(k) }
|
170
202
|
end
|
171
203
|
end
|
172
204
|
"""
|
@@ -33,7 +33,7 @@ class Autotest::RailsRspec2 < Autotest::Rspec2
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def setup_rails_rspec2_mappings
|
36
|
-
%w{
|
36
|
+
%w{coverage/ db/ doc/ log/ public/ script/ tmp/ vendor/rails vendor/plugins vendor/gems}.each do |exception|
|
37
37
|
add_exception(/^([\.\/]*)?#{exception}/)
|
38
38
|
end
|
39
39
|
|
data/lib/generators/rspec.rb
CHANGED
@@ -6,6 +6,12 @@ module Rspec
|
|
6
6
|
def self.source_root
|
7
7
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
8
8
|
end
|
9
|
+
|
10
|
+
if ::Rails.version < '3.1'
|
11
|
+
def module_namespacing
|
12
|
+
yield if block_given?
|
13
|
+
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
+
<% module_namespacing do -%>
|
3
4
|
describe <%= class_name %> do
|
4
5
|
<% for action in actions -%>
|
5
6
|
describe "<%= action %>" do
|
@@ -21,3 +22,4 @@ describe <%= class_name %> do
|
|
21
22
|
pending "add some examples to (or delete) #{__FILE__}"
|
22
23
|
<% end -%>
|
23
24
|
end
|
25
|
+
<% end -%>
|
@@ -57,8 +57,42 @@ module Rspec
|
|
57
57
|
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
|
60
|
+
def example_valid_attributes
|
61
|
+
# Only take the first attribute so this hash does not become unweildy and large in the
|
62
|
+
# generated controller spec. It is the responsibility of the user to keep the the valid
|
63
|
+
# attributes method up-to-date as they add validations.
|
64
|
+
@example_valid_attributes ||=
|
65
|
+
if attributes.any?
|
66
|
+
{ attributes.first.name => attributes.first.default.to_s }
|
67
|
+
else
|
68
|
+
{ }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def example_invalid_attributes
|
73
|
+
@example_invalid_attributes ||=
|
74
|
+
if attributes.any?
|
75
|
+
{ attributes.first.name => "invalid value" }
|
76
|
+
else
|
77
|
+
{ }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def example_params_for_update
|
82
|
+
@example_params_for_update ||=
|
83
|
+
if example_valid_attributes.any?
|
84
|
+
example_valid_attributes
|
85
|
+
else
|
86
|
+
{ "these" => "params" }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def formatted_hash(hash)
|
91
|
+
formatted = hash.inspect
|
92
|
+
formatted.gsub!("{", "{ ")
|
93
|
+
formatted.gsub!("}", " }")
|
94
|
+
formatted.gsub!("=>", " => ")
|
95
|
+
formatted
|
62
96
|
end
|
63
97
|
|
64
98
|
# support for namespaced-resources
|
@@ -73,7 +107,7 @@ module Rspec
|
|
73
107
|
|
74
108
|
def ns_parts
|
75
109
|
@ns_parts ||= begin
|
76
|
-
matches = ARGV[0].to_s.match(/\A(\w+)
|
110
|
+
matches = ARGV[0].to_s.match(/\A(\w+)(?:\/|::)(\w+)/)
|
77
111
|
matches ? [matches[1], matches[2]] : []
|
78
112
|
end
|
79
113
|
end
|