rspec-rails 1.2.7.1 → 1.2.9
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/Contribute.rdoc +4 -0
- data/History.rdoc +26 -1
- data/Manifest.txt +2 -3
- data/Rakefile +16 -15
- data/TODO.txt +2 -3
- data/Upgrade.rdoc +34 -0
- data/generators/integration_spec/templates/integration_spec.rb +1 -1
- data/generators/rspec/rspec_generator.rb +0 -1
- data/generators/rspec/templates/rspec.rake +1 -39
- data/generators/rspec/templates/spec_helper.rb +5 -2
- data/generators/rspec_controller/rspec_controller_generator.rb +2 -0
- data/generators/rspec_controller/templates/controller_spec.rb +1 -1
- data/generators/rspec_controller/templates/helper_spec.rb +1 -1
- data/generators/rspec_controller/templates/view_spec.rb +1 -1
- data/generators/rspec_model/templates/model_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/controller_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/routing_spec.rb +16 -46
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +1 -1
- data/lib/spec/rails/example/controller_example_group.rb +12 -1
- data/lib/spec/rails/example/routing_helpers.rb +16 -20
- data/lib/spec/rails/extensions/action_controller/rescue.rb +2 -2
- data/lib/spec/rails/extensions/action_controller/test_case.rb +1 -1
- data/lib/spec/rails/matchers.rb +1 -0
- data/lib/spec/rails/matchers/render_template.rb +8 -2
- data/lib/spec/rails/matchers/route_to.rb +149 -0
- data/lib/spec/rails/version.rb +3 -3
- data/spec/autotest/mappings_spec.rb +1 -1
- data/spec/resources/controllers/controller_spec_controller.rb +5 -1
- data/spec/resources/controllers/render_spec_controller.rb +4 -0
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +1 -1
- data/spec/spec/rails/example/configuration_spec.rb +1 -1
- data/spec/spec/rails/example/controller_example_group_spec.rb +15 -7
- data/spec/spec/rails/example/controller_isolation_spec.rb +22 -9
- data/spec/spec/rails/example/cookies_proxy_spec.rb +1 -1
- data/spec/spec/rails/example/error_handling_spec.rb +1 -1
- data/spec/spec/rails/example/example_group_factory_spec.rb +1 -1
- data/spec/spec/rails/example/helper_example_group_spec.rb +2 -2
- data/spec/spec/rails/example/model_example_group_spec.rb +1 -1
- data/spec/spec/rails/example/routing_example_group_spec.rb +3 -2
- data/spec/spec/rails/example/shared_routing_example_group_examples.rb +224 -31
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +1 -1
- data/spec/spec/rails/example/view_example_group_spec.rb +1 -1
- data/spec/spec/rails/extensions/action_view_base_spec.rb +1 -1
- data/spec/spec/rails/extensions/active_record_spec.rb +1 -1
- data/spec/spec/rails/interop/testcase_spec.rb +1 -1
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +11 -37
- data/spec/spec/rails/matchers/assert_select_spec.rb +1 -1
- data/spec/spec/rails/matchers/errors_on_spec.rb +1 -1
- data/spec/spec/rails/matchers/have_text_spec.rb +1 -1
- data/spec/spec/rails/matchers/include_text_spec.rb +1 -1
- data/spec/spec/rails/matchers/redirect_to_spec.rb +1 -1
- data/spec/spec/rails/matchers/render_template_spec.rb +8 -1
- data/spec/spec/rails/matchers/should_change_spec.rb +1 -1
- data/spec/spec/rails/mocks/mock_model_spec.rb +1 -1
- data/spec/spec/rails/mocks/stub_model_spec.rb +1 -1
- data/spec/spec/rails/sample_modified_fixture.rb +1 -1
- data/spec/spec/rails/sample_spec.rb +1 -1
- data/spec/spec/rails/spec_spec.rb +1 -1
- data/spec/spec_helper.rb +23 -24
- metadata +11 -12
- data/generators/rspec/templates/script/spec_server +0 -9
- data/lib/spec/rails/spec_server.rb +0 -135
- data/spec/spec/rails/spec_server_spec.rb +0 -108
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
Spec::Runner.configuration.global_fixtures = :people
|
3
3
|
|
4
4
|
describe ExplicitHelper, :type => :helper do
|
@@ -148,7 +148,7 @@ module Spec
|
|
148
148
|
helper_name :explicit
|
149
149
|
|
150
150
|
before(:each) do
|
151
|
-
if Rails::VERSION::STRING
|
151
|
+
if ::Rails::VERSION::STRING < "2.2"
|
152
152
|
pending("need to get this new feature working against pre 2.2 versions of rails")
|
153
153
|
end
|
154
154
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'controller_spec_controller'
|
3
3
|
require File.join(File.dirname(__FILE__), "/shared_routing_example_group_examples.rb")
|
4
4
|
|
5
5
|
describe "Routing Examples", :type => :routing do
|
6
6
|
|
7
7
|
include RoutingExampleGroupSpec
|
8
|
-
|
8
|
+
include RouteToExampleGroupSpec
|
9
|
+
include BeRoutableExampleGroupSpec
|
9
10
|
end
|
@@ -2,43 +2,236 @@ class CustomRouteSpecController < ActionController::Base; end
|
|
2
2
|
class RspecOnRailsSpecsController < ActionController::Base; end
|
3
3
|
|
4
4
|
share_as :RoutingExampleGroupSpec do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
describe "using backward compatible route_for()" do
|
6
|
+
it "translates GET-only paths to be explicit" do
|
7
|
+
self.should_receive(:assert_routing).with(hash_including(:method => :get), anything, {}, anything)
|
8
|
+
route_for(:controller => "controller_spec", :action => "some_action").
|
9
|
+
should == "/controller_spec/some_action"
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
it "uses assert_routing to specify that the :controller and :action are involved" do
|
13
|
+
@route = { :controller => "controller_spec", :action => "some_action" }
|
14
|
+
self.should_receive(:assert_routing).with(anything, @route, {}, anything)
|
15
|
+
route_for(@route).
|
16
|
+
should == "/controller_spec/some_action"
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
route_for(:controller => "rspec_on_rails_specs", :action => "update", :id => "37").
|
22
|
-
should == {:path => "/rspec_on_rails_specs/37", :method => :put}
|
23
|
-
end
|
19
|
+
it "passes extra args through to assert_routing" do
|
20
|
+
@route = { :controller => "controller_spec", :action => "some_action" }
|
21
|
+
self.should_receive(:assert_routing).with(anything, anything, {}, { :a => "1", :b => "2" } )
|
22
|
+
route_for(@route).
|
23
|
+
should == "/controller_spec/some_action?a=1&b=2"
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
it "passes with an existing route" do
|
27
|
+
route_for(:controller => "controller_spec", :action => "some_action").
|
28
|
+
should == "/controller_spec/some_action"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "passes with an existing route with additional parameters" do
|
32
|
+
route_for(:controller => "controller_spec", :action => "some_action", :param => '1').
|
33
|
+
should == "/controller_spec/some_action?param=1"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "recognizes routes with methods besides :get" do
|
37
|
+
should_receive(:assert_routing).with(hash_including(:method => :put), anything, {}, anything)
|
38
|
+
|
39
|
+
route_for(:controller => "rspec_on_rails_specs", :action => "update", :id => "37").
|
40
|
+
should == {:path => "/rspec_on_rails_specs/37", :method => :put}
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "failing due to bad path:" do
|
44
|
+
it "raises routing error and suggests should_not be_routeable()" do
|
45
|
+
lambda {
|
46
|
+
route_for(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37") ==
|
47
|
+
{:path => "/rspec_on_rails_specs/bad_route/37", :method => :put}
|
48
|
+
}.should raise_error( ActionController::RoutingError, /suggest.*should_not be_routable/ )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "failing due to params mismatch:" do
|
53
|
+
it "re-raises assertion and suggests should_not be_routeable()" do
|
54
|
+
lambda {
|
55
|
+
route_for(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37") ==
|
56
|
+
{:path => "/rspec_on_rails_specs/37", :method => :put}
|
57
|
+
}.should raise_error( ::Test::Unit::AssertionFailedError, /suggest.*should_not be_routable/ )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "failing due to wrong HTTP method" do
|
62
|
+
it "raises method error and suggest should_not be_routable()" do
|
63
|
+
lambda {
|
64
|
+
route_for(:controller => "rspec_on_rails_specs", :action => "update", :id => "37").
|
65
|
+
should == {:path => "/rspec_on_rails_specs/37", :method => :post}
|
66
|
+
}.should raise_error(ActionController::MethodNotAllowed) { |error| error.should_not =~ /should_not be_routable/ }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "generates params for custom routes" do
|
71
|
+
# redundant, deprecated
|
72
|
+
params_from(:get, '/custom_route').
|
73
|
+
should == {:controller => "custom_route_spec", :action => "custom_route"}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "generates params for existing routes" do
|
77
|
+
# redundant, deprecated
|
78
|
+
params_from(:get, '/controller_spec/some_action').
|
79
|
+
should == {:controller => "controller_spec", :action => "some_action"}
|
80
|
+
end
|
29
81
|
|
30
|
-
|
31
|
-
|
32
|
-
|
82
|
+
it "generates params for existing routes with a query parameters" do
|
83
|
+
# redundant, deprecated
|
84
|
+
params_from(:get, '/controller_spec/some_action?param=1').
|
85
|
+
should == {:controller => "controller_spec", :action => "some_action", :param => '1'}
|
86
|
+
end
|
87
|
+
|
88
|
+
it "generates params for existing routes with multiple query parameters" do
|
89
|
+
# redundant, deprecated
|
90
|
+
params_from(:get, '/controller_spec/some_action?param1=1¶m2=2').
|
91
|
+
should == {:controller => "controller_spec", :action => "some_action", :param1 => '1', :param2 => '2' }
|
92
|
+
end
|
33
93
|
end
|
94
|
+
end
|
95
|
+
|
96
|
+
share_as :BeRoutableExampleGroupSpec do
|
97
|
+
describe "using should_not be_routable()" do
|
98
|
+
it "passes for a bad route" do
|
99
|
+
{ :put => "/rspec_on_rails_specs/bad_route/37" }.
|
100
|
+
should_not be_routable
|
101
|
+
end
|
102
|
+
it "passes for a bad route having an arg" do
|
103
|
+
{ :put => "/rspec_on_rails_specs/bad_route/37?some_arg=1" }.
|
104
|
+
should_not be_routable
|
105
|
+
end
|
106
|
+
describe "when assert_recognizes throws exceptions:" do
|
107
|
+
[ ActionController::RoutingError, ActionController::MethodNotAllowed ].each do |e|
|
108
|
+
it "passes on #{e}" do
|
109
|
+
self.stub!( :assert_recognizes ).and_return { raise e, "stubbed exception" }
|
110
|
+
{ :get => "/rspec_on_rails_spec/bad_route/37" }.should_not be_routable
|
111
|
+
end
|
112
|
+
it "should be_routable on usual Test::Unit::AssertionFailedError" do
|
113
|
+
# <{}> is predictable because of the way we call assert_recognizes during be_routable().
|
114
|
+
self.stub!( :assert_recognizes ).and_return { raise ::Test::Unit::AssertionFailedError, "<{a}> did not match <{}>" }
|
115
|
+
{ :get => "/rspec_on_rails_spec/arguably_bad_route" }.should be_routable
|
116
|
+
end
|
117
|
+
it "should re-raise on unusual Test::Unit::AssertionFailedError" do
|
118
|
+
self.stub!( :assert_recognizes ).and_return { raise ::Test::Unit::AssertionFailedError, "some other message" }
|
119
|
+
expect { { :get => "/rspec_on_rails_spec/weird_case_route/" }.should be_routable }.
|
120
|
+
to raise_error
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
it "test should be_routable" do
|
125
|
+
{ :get => "/custom_route" }.
|
126
|
+
should be_routable
|
127
|
+
end
|
128
|
+
|
129
|
+
it "recommends route_to() on failure with should()" do
|
130
|
+
lambda {
|
131
|
+
{ :get => "/nonexisting_route" }.
|
132
|
+
should be_routable
|
133
|
+
}.should raise_error( /route_to\(/)
|
134
|
+
end
|
34
135
|
|
35
|
-
|
36
|
-
|
37
|
-
|
136
|
+
it "shows actual route that was generated on failure with should_not()" do
|
137
|
+
begin
|
138
|
+
{ :get => "/custom_route" }.should_not be_routable
|
139
|
+
rescue Exception => e
|
140
|
+
ensure
|
141
|
+
# Different versions of ruby order these differently
|
142
|
+
e.message.should =~ /"action"=>"custom_route"/
|
143
|
+
e.message.should =~ /"controller"=>"custom_route_spec"/
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it "works with routeable (alternate spelling)" do
|
148
|
+
{ :put => "/nonexisting_route" }.
|
149
|
+
should_not be_routeable
|
150
|
+
end
|
38
151
|
end
|
152
|
+
end
|
153
|
+
|
154
|
+
share_as :RouteToExampleGroupSpec do
|
155
|
+
describe "using should[_not] route_to()" do
|
156
|
+
it "supports existing routes" do
|
157
|
+
{ :get => "/controller_spec/some_action" }.
|
158
|
+
should route_to( :controller => "controller_spec", :action => "some_action" )
|
159
|
+
end
|
160
|
+
|
161
|
+
it "translates GET-only paths to be explicit, when matching against a string (for parity with route_for().should == '/path')" do
|
162
|
+
self.should_receive(:assert_routing).with(hash_including(:method => :get), anything, {}, anything)
|
163
|
+
"/controller_spec/some_action".
|
164
|
+
should route_to({})
|
165
|
+
end
|
166
|
+
|
167
|
+
it "asserts, using assert_routing, that the :controller and :action are involved" do
|
168
|
+
@route = { :controller => "controller_spec", :action => "some_action" }
|
169
|
+
self.should_receive(:assert_routing).with(anything, @route, {}, anything)
|
170
|
+
"/controller_spec/some_action".
|
171
|
+
should route_to(@route)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "sends extra args through" do
|
175
|
+
@route = { :controller => "controller_spec", :action => "some_action" }
|
176
|
+
self.should_receive(:assert_routing).with(anything, anything, {}, { :a => "1", :b => "2" } )
|
177
|
+
"/controller_spec/some_action?a=1&b=2".
|
178
|
+
should route_to( @route )
|
179
|
+
end
|
180
|
+
|
181
|
+
it "supports routes with additional parameters" do
|
182
|
+
{ :get => "/controller_spec/some_action?param=1" }.
|
183
|
+
should route_to( :controller => "controller_spec", :action => "some_action", :param => '1' )
|
184
|
+
end
|
185
|
+
|
186
|
+
it "recognizes routes with methods besides :get" do
|
187
|
+
self.should_receive(:assert_routing).with(hash_including(:method => :put), anything, {}, anything)
|
188
|
+
{ :put => "/rspec_on_rails_specs/37" }.
|
189
|
+
should route_to(:controller => "rspec_on_rails_specs", :action => "update", :id => "37")
|
190
|
+
end
|
191
|
+
|
192
|
+
it "allows only one key/value in the path - :method => path" do
|
193
|
+
lambda {
|
194
|
+
{ :a => "b" ,:c => "d" }.
|
195
|
+
should route_to("anything")
|
196
|
+
}.should raise_error( ArgumentError, /usage/ )
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "failing due to bad path" do
|
200
|
+
it "raises routing error, and suggests should_not be_routeable()" do
|
201
|
+
lambda {
|
202
|
+
{ :put => "/rspec_on_rails_specs/nonexistent/37" }.
|
203
|
+
should route_to(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37")
|
204
|
+
}.should raise_error( ActionController::RoutingError, /suggest.*nonexistent.*should_not be_routable/ )
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "failing due to params mismatch" do
|
209
|
+
it "raises assertion, and suggests should_not be_routeable()" do
|
210
|
+
lambda {
|
211
|
+
{ :put => "/rspec_on_rails_specs/37" }.
|
212
|
+
should route_to(:controller => "rspec_on_rails_specs", :action => "nonexistent", :id => "37")
|
213
|
+
}.should raise_error( ::Test::Unit::AssertionFailedError, /suggest.*rspec_on_rails_specs\/37.*should_not be_routable/ )
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "passing when expected failure" do
|
218
|
+
it "suggests should_not be_routable()" do
|
219
|
+
self.stub!(:assert_routing).and_return true
|
220
|
+
lambda {
|
221
|
+
{ :put => "/rspec_on_rails_specs/37" }.
|
222
|
+
should_not route_to(:controller => "rspec_on_rails_specs", :action => "update", :id => "37")
|
223
|
+
}.should raise_error( /expected a routing error.*be_routable/im )
|
224
|
+
end
|
225
|
+
end
|
39
226
|
|
40
|
-
|
41
|
-
|
42
|
-
|
227
|
+
describe "failing due to wrong HTTP method" do
|
228
|
+
it "raises method error and suggests should_not be_routable()" do
|
229
|
+
self.stub!(:assert_routing) { raise ActionController::MethodNotAllowed }
|
230
|
+
lambda {
|
231
|
+
{ :post => "/rspec_on_rails_specs/37" }.
|
232
|
+
should route_to(:controller => "rspec_on_rails_specs", :action => "update", :id => "37" )
|
233
|
+
}.should raise_error(ActionController::MethodNotAllowed, /rspec_on_rails_specs\/37.*should_not be_routable/ )
|
234
|
+
end
|
235
|
+
end
|
43
236
|
end
|
44
|
-
end
|
237
|
+
end
|
@@ -1,45 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "be_valid" do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context "with valid attributes" do
|
5
|
+
it "returns true" do
|
6
|
+
be_valid.matches?(Thing.new(:name => 'thing')).should == true
|
7
7
|
end
|
8
|
-
def valid?; @valid end
|
9
8
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
describe CanBeValid do
|
17
|
-
subject { CanBeValid.new(true) }
|
18
|
-
it { subject.should be_valid }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe CanBeValid do
|
22
|
-
subject { CanBeValid.new(false) }
|
23
|
-
it { subject.should_not be_valid }
|
24
|
-
end
|
25
|
-
|
26
|
-
class CanHaveErrors
|
27
|
-
def initialize(errors)
|
28
|
-
@valid = !errors
|
29
|
-
@errors = ActiveRecord::Errors.new self
|
30
|
-
@errors.add :name, "is too short"
|
9
|
+
|
10
|
+
context "with invalid attributes" do
|
11
|
+
it "returns false" do
|
12
|
+
be_valid.matches?(Thing.new).should == false
|
31
13
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def self.human_attribute_name(ignore)
|
36
|
-
"Name"
|
14
|
+
|
15
|
+
it "adds errors to the errors " do
|
16
|
+
expect { Thing.new.should be_valid }.to raise_error(/can't be blank/)
|
37
17
|
end
|
38
18
|
end
|
39
|
-
|
40
|
-
it "should show errors in the output if they're available" do
|
41
|
-
lambda {
|
42
|
-
CanHaveErrors.new(true).should be_valid
|
43
|
-
}.should fail_with(/Name is too short/)
|
44
|
-
end
|
45
19
|
end
|