rspec-rails 2.14.1 → 2.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +9 -0
  3. data/lib/autotest/rails_rspec2.rb +1 -0
  4. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +6 -1
  5. data/lib/rspec/rails/adapters.rb +1 -0
  6. data/lib/rspec/rails/example/controller_example_group.rb +2 -1
  7. data/lib/rspec/rails/matchers/have_extension.rb +1 -0
  8. data/lib/rspec/rails/matchers/routing_matchers.rb +4 -0
  9. data/lib/rspec/rails/mocks.rb +6 -0
  10. data/lib/rspec/rails/tasks/rspec.rake +12 -5
  11. data/lib/rspec/rails/version.rb +1 -1
  12. metadata +38 -214
  13. data/features/Autotest.md +0 -24
  14. data/features/Generators.md +0 -24
  15. data/features/GettingStarted.md +0 -84
  16. data/features/README.md +0 -56
  17. data/features/RailsVersions.md +0 -4
  18. data/features/Transactions.md +0 -84
  19. data/features/Upgrade.md +0 -121
  20. data/features/controller_specs/Cookies.md +0 -57
  21. data/features/controller_specs/README.md +0 -45
  22. data/features/controller_specs/anonymous_controller.feature +0 -378
  23. data/features/controller_specs/bypass_rescue.feature +0 -75
  24. data/features/controller_specs/controller_spec.feature +0 -58
  25. data/features/controller_specs/engine_routes.feature +0 -51
  26. data/features/controller_specs/isolation_from_views.feature +0 -87
  27. data/features/controller_specs/render_views.feature +0 -114
  28. data/features/feature_specs/feature_spec.feature +0 -34
  29. data/features/helper_specs/helper_spec.feature +0 -122
  30. data/features/mailer_specs/url_helpers.feature +0 -38
  31. data/features/matchers/README.md +0 -18
  32. data/features/matchers/new_record_matcher.feature +0 -41
  33. data/features/matchers/redirect_to_matcher.feature +0 -40
  34. data/features/matchers/relation_match_array.feature +0 -27
  35. data/features/matchers/render_template_matcher.feature +0 -49
  36. data/features/mocks/mock_model.feature +0 -147
  37. data/features/mocks/stub_model.feature +0 -58
  38. data/features/model_specs/README.md +0 -21
  39. data/features/model_specs/errors_on.feature +0 -51
  40. data/features/model_specs/records.feature +0 -27
  41. data/features/model_specs/transactional_examples.feature +0 -109
  42. data/features/request_specs/request_spec.feature +0 -49
  43. data/features/routing_specs/README.md +0 -16
  44. data/features/routing_specs/be_routable_matcher.feature +0 -80
  45. data/features/routing_specs/engine_routes.feature +0 -38
  46. data/features/routing_specs/named_routes.feature +0 -18
  47. data/features/routing_specs/route_to_matcher.feature +0 -90
  48. data/features/step_definitions/additional_cli_steps.rb +0 -4
  49. data/features/step_definitions/model_steps.rb +0 -3
  50. data/features/support/env.rb +0 -53
  51. data/features/support/rails_versions.rb +0 -4
  52. data/features/support/rubinius.rb +0 -6
  53. data/features/view_specs/inferred_controller_path.feature +0 -45
  54. data/features/view_specs/stub_template.feature +0 -51
  55. data/features/view_specs/view_spec.feature +0 -206
  56. data/spec/autotest/rails_rspec2_spec.rb +0 -36
  57. data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
  58. data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
  59. data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
  60. data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -44
  61. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
  62. data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
  63. data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
  64. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
  65. data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
  66. data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
  67. data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
  68. data/spec/rspec/rails/configuration_spec.rb +0 -26
  69. data/spec/rspec/rails/deprecations_spec.rb +0 -18
  70. data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -100
  71. data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
  72. data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -64
  73. data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
  74. data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
  75. data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
  76. data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
  77. data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
  78. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
  79. data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
  80. data/spec/rspec/rails/fixture_support_spec.rb +0 -17
  81. data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
  82. data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
  83. data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
  84. data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -44
  85. data/spec/rspec/rails/matchers/errors_on_spec.rb +0 -38
  86. data/spec/rspec/rails/matchers/has_spec.rb +0 -29
  87. data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
  88. data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -80
  89. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
  90. data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
  91. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
  92. data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -401
  93. data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
  94. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
  95. data/spec/rspec/rails/view_rendering_spec.rb +0 -111
  96. data/spec/spec_helper.rb +0 -32
  97. data/spec/support/ar_classes.rb +0 -42
  98. data/spec/support/helpers.rb +0 -34
  99. data/spec/support/matchers.rb +0 -9
  100. data/spec/support/null_object.rb +0 -6
@@ -1,80 +0,0 @@
1
- require "spec_helper"
2
- require "active_support/test_case"
3
-
4
- describe "redirect_to" do
5
- include RSpec::Rails::Matchers::RedirectTo
6
-
7
- let(:response) { ActionController::TestResponse.new }
8
-
9
- context "with should" do
10
- context "when assert_redirected_to passes" do
11
- def assert_redirected_to(*); end
12
-
13
- it "passes" do
14
- expect do
15
- response.should redirect_to("destination")
16
- end.to_not raise_exception
17
- end
18
- end
19
-
20
- context "when assert_redirected_to fails" do
21
- def assert_redirected_to(*)
22
- raise ActiveSupport::TestCase::Assertion.new("this message")
23
- end
24
-
25
- it "uses failure message from assert_redirected_to" do
26
- expect do
27
- response.should redirect_to("destination")
28
- end.to raise_exception("this message")
29
- end
30
- end
31
-
32
- context "when fails due to some other exception" do
33
- def assert_redirected_to(*)
34
- raise "oops"
35
- end
36
-
37
- it "raises that exception" do
38
- expect do
39
- response.should redirect_to("destination")
40
- end.to raise_exception("oops")
41
- end
42
- end
43
- end
44
-
45
- context "with should_not" do
46
- context "when assert_redirected_to fails" do
47
- def assert_redirected_to(*)
48
- raise ActiveSupport::TestCase::Assertion.new("this message")
49
- end
50
-
51
- it "passes" do
52
- expect do
53
- response.should_not redirect_to("destination")
54
- end.to_not raise_exception
55
- end
56
- end
57
-
58
- context "when assert_redirected_to passes" do
59
- def assert_redirected_to(*); end
60
-
61
- it "fails with custom failure message" do
62
- expect do
63
- response.should_not redirect_to("destination")
64
- end.to raise_exception(/expected not to redirect to \"destination\", but did/)
65
- end
66
- end
67
-
68
- context "when fails due to some other exception" do
69
- def assert_redirected_to(*)
70
- raise "oops"
71
- end
72
-
73
- it "raises that exception" do
74
- expect do
75
- response.should_not redirect_to("destination")
76
- end.to raise_exception("oops")
77
- end
78
- end
79
- end
80
- end
@@ -1,31 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "ActiveSupport::Relation =~ matcher" do
4
- before { MockableModel.delete_all }
5
-
6
- let!(:models) { Array.new(3) { MockableModel.create } }
7
-
8
- if ::Rails::VERSION::STRING >= '4'
9
- it "verifies that the scope returns the records on the right hand side, regardless of order" do
10
- MockableModel.all.should =~ models.reverse
11
- end
12
-
13
- it "fails if the scope encompasses more records than on the right hand side" do
14
- MockableModel.create
15
- MockableModel.all.should_not =~ models.reverse
16
- end
17
- else
18
- it "verifies that the scope returns the records on the right hand side, regardless of order" do
19
- MockableModel.scoped.should =~ models.reverse
20
- end
21
-
22
- it "fails if the scope encompasses more records than on the right hand side" do
23
- MockableModel.create
24
- MockableModel.scoped.should_not =~ models.reverse
25
- end
26
- end
27
-
28
- it "fails if the scope encompasses fewer records than on the right hand side" do
29
- MockableModel.limit(models.length - 1).should_not =~ models.reverse
30
- end
31
- end
@@ -1,151 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "route_to" do
4
- include RSpec::Rails::Matchers::RoutingMatchers
5
- include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
6
-
7
- def assert_recognizes(*)
8
- # no-op
9
- end
10
-
11
- it "provides a description" do
12
- matcher = route_to("these" => "options")
13
- matcher.matches?(:get => "path")
14
- matcher.description.should == "route {:get=>\"path\"} to {\"these\"=>\"options\"}"
15
- end
16
-
17
- it "delegates to assert_recognizes" do
18
- self.should_receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" }, {})
19
- {:get => "path"}.should route_to("these" => "options")
20
- end
21
-
22
- context "with shortcut syntax" do
23
- it "routes with extra options" do
24
- self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" }, {})
25
- get("path").should route_to("controller#action", :extra => "options")
26
- end
27
-
28
- it "routes without extra options" do
29
- self.should_receive(:assert_recognizes).with(
30
- {:controller => "controller", :action => "action"},
31
- {:method=> :get, :path=>"path" },
32
- {}
33
- )
34
- get("path").should route_to("controller#action")
35
- end
36
-
37
- it "routes with one query parameter" do
38
- self.should_receive(:assert_recognizes).with(
39
- {:controller => "controller", :action => "action", :queryitem => "queryvalue"},
40
- {:method=> :get, :path=>"path" },
41
- {'queryitem' => 'queryvalue' }
42
- )
43
- get("path?queryitem=queryvalue").should route_to("controller#action", :queryitem => 'queryvalue')
44
- end
45
-
46
- it "routes with multiple query parameters" do
47
- self.should_receive(:assert_recognizes).with(
48
- {:controller => "controller", :action => "action", :queryitem => "queryvalue", :qi2 => 'qv2'},
49
- {:method=> :get, :path=>"path"},
50
- {'queryitem' => 'queryvalue', 'qi2' => 'qv2'}
51
- )
52
- get("path?queryitem=queryvalue&qi2=qv2").should route_to("controller#action", :queryitem => 'queryvalue', :qi2 => 'qv2')
53
- end
54
-
55
- end
56
-
57
- context "with should" do
58
- context "when assert_recognizes passes" do
59
- it "passes" do
60
- expect do
61
- {:get => "path"}.should route_to("these" => "options")
62
- end.to_not raise_exception
63
- end
64
- end
65
-
66
- context "when assert_recognizes fails with an assertion failure" do
67
- it "fails with message from assert_recognizes" do
68
- def assert_recognizes(*)
69
- raise ActiveSupport::TestCase::Assertion.new("this message")
70
- end
71
- expect do
72
- {:get => "path"}.should route_to("these" => "options")
73
- end.to raise_error(RSpec::Expectations::ExpectationNotMetError, "this message")
74
- end
75
- end
76
-
77
- context "when assert_recognizes fails with a routing error" do
78
- it "fails with message from assert_recognizes" do
79
- def assert_recognizes(*)
80
- raise ActionController::RoutingError.new("this message")
81
- end
82
- expect do
83
- {:get => "path"}.should route_to("these" => "options")
84
- end.to raise_error(RSpec::Expectations::ExpectationNotMetError, "this message")
85
- end
86
- end
87
-
88
- context "when an exception is raised" do
89
- it "raises that exception" do
90
- def assert_recognizes(*)
91
- raise "oops"
92
- end
93
- expect do
94
- {:get => "path"}.should route_to("these" => "options")
95
- end.to raise_exception("oops")
96
- end
97
- end
98
- end
99
-
100
- context "with should_not" do
101
- context "when assert_recognizes passes" do
102
- it "fails with custom message" do
103
- expect do
104
- {:get => "path"}.should_not route_to("these" => "options")
105
- end.to raise_error(/expected .* not to route to .*/)
106
- end
107
- end
108
-
109
- context "when assert_recognizes fails with an assertion failure" do
110
- it "passes" do
111
- def assert_recognizes(*)
112
- raise ActiveSupport::TestCase::Assertion.new("this message")
113
- end
114
- expect do
115
- {:get => "path"}.should_not route_to("these" => "options")
116
- end.to_not raise_error
117
- end
118
- end
119
-
120
- context "when assert_recognizes fails with a routing error" do
121
- it "passes" do
122
- def assert_recognizes(*)
123
- raise ActionController::RoutingError.new("this message")
124
- end
125
- expect do
126
- {:get => "path"}.should_not route_to("these" => "options")
127
- end.to_not raise_error
128
- end
129
- end
130
-
131
- context "when an exception is raised" do
132
- it "raises that exception" do
133
- def assert_recognizes(*)
134
- raise "oops"
135
- end
136
- expect do
137
- {:get => "path"}.should_not route_to("these" => "options")
138
- end.to raise_exception("oops")
139
- end
140
- end
141
- end
142
-
143
- it "uses failure message from assert_recognizes" do
144
- def assert_recognizes(*)
145
- raise ActiveSupport::TestCase::Assertion, "this message"
146
- end
147
- expect do
148
- {"this" => "path"}.should route_to("these" => "options")
149
- end.to raise_error("this message")
150
- end
151
- end
@@ -1,31 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe RSpec::Rails::MinitestLifecycleAdapter do
4
- it "invokes minitest lifecycle hooks at the appropriate times" do
5
- invocations = []
6
- example_group = RSpec::Core::ExampleGroup.describe("MinitestHooks") do
7
- include RSpec::Rails::MinitestLifecycleAdapter
8
-
9
- define_method(:before_setup) { invocations << :before_setup }
10
- define_method(:after_setup) { invocations << :after_setup }
11
- define_method(:before_teardown) { invocations << :before_teardown }
12
- define_method(:after_teardown) { invocations << :after_teardown }
13
- end
14
-
15
- example = example_group.example("foo") { invocations << :example }
16
- example_group.run(NullObject.new)
17
-
18
- expect(invocations).to eq([
19
- :before_setup, :after_setup, :example, :before_teardown, :after_teardown
20
- ])
21
- end
22
-
23
- it "allows let variables named 'send'" do
24
- run_result = ::RSpec::Core::ExampleGroup.describe do
25
- let(:send) { "WHAT" }
26
- specify { expect(send).to eq "WHAT" }
27
- end.run NullObject.new
28
-
29
- expect(run_result).to be true
30
- end
31
- end
@@ -1,401 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "mock_model(RealModel)" do
4
-
5
- context "given a String" do
6
- context "that does not represent an existing constant" do
7
- it "class says it's name" do
8
- model = mock_model("Foo")
9
- model.class.name.should eq("Foo")
10
- end
11
- end
12
-
13
- context "that represents an existing constant" do
14
- context "that extends ActiveModel::Naming" do
15
- it "treats the constant as the class" do
16
- model = mock_model("MockableModel")
17
- model.class.name.should eq("MockableModel")
18
- end
19
- end
20
-
21
- context "that does not extend ActiveModel::Naming" do
22
- it "raises with a helpful message" do
23
- expect do
24
- mock_model("String")
25
- end.to raise_error(ArgumentError)
26
- end
27
- end
28
- end
29
- end
30
-
31
- context "given a class that does not extend ActiveModel::Naming" do
32
- it "raises with a helpful message" do
33
- expect do
34
- mock_model(String)
35
- end.to raise_error(ArgumentError)
36
- end
37
- end
38
-
39
- describe "with #id stubbed" do
40
- before(:each) do
41
- @model = mock_model(MockableModel, :id => 1)
42
- end
43
-
44
- it "is named using the stubbed id value" do
45
- @model.instance_variable_get(:@name).should == "MockableModel_1"
46
- end
47
- end
48
-
49
- describe "destroy" do
50
- it "sets persisted to false" do
51
- model = mock_model(MockableModel)
52
- model.destroy
53
- model.should_not be_persisted
54
- end
55
- end
56
-
57
- describe "association" do
58
- it "constructs a mock association object" do
59
- model = mock_model(MockableModel)
60
- expect(model.association(:association_name)).to be
61
- end
62
-
63
- it "returns a different association object for each association name" do
64
- model = mock_model(MockableModel)
65
- posts = model.association(:posts)
66
- authors = model.association(:authors)
67
-
68
- expect(posts).not_to equal(authors)
69
- end
70
-
71
- it "returns the same association model each time for the same association name" do
72
- model = mock_model(MockableModel)
73
- posts1 = model.association(:posts)
74
- posts2 = model.association(:posts)
75
-
76
- expect(posts1).to equal(posts2)
77
- end
78
- end
79
-
80
- describe "errors" do
81
- context "default" do
82
- it "is empty" do
83
- model = mock_model(MockableModel)
84
- model.errors.should be_empty
85
- end
86
- end
87
-
88
- context "with :save => false" do
89
- it "is not empty" do
90
- model = mock_model(MockableModel, :save => false)
91
- model.errors.should_not be_empty
92
- end
93
- end
94
-
95
- context "with :update_attributes => false" do
96
- it "is not empty" do
97
- model = mock_model(MockableModel, :save => false)
98
- model.errors.should_not be_empty
99
- end
100
- end
101
- end
102
-
103
- describe "with params" do
104
- it "does not mutate its parameters" do
105
- params = {:a => 'b'}
106
- mock_model(MockableModel, params)
107
- params.should == {:a => 'b'}
108
- end
109
- end
110
-
111
- describe "as association" do
112
- before(:each) do
113
- @real = AssociatedModel.create!
114
- @mock_model = mock_model(MockableModel)
115
- @real.mockable_model = @mock_model
116
- end
117
-
118
- it "passes: associated_model == mock" do
119
- @mock_model.should == @real.mockable_model
120
- end
121
-
122
- it "passes: mock == associated_model" do
123
- @real.mockable_model.should == @mock_model
124
- end
125
- end
126
-
127
- describe "as association that doesn't exist yet" do
128
- before(:each) do
129
- @real = AssociatedModel.create!
130
- @mock_model = mock_model("Other")
131
- @real.nonexistent_model = @mock_model
132
- end
133
-
134
- it "passes: associated_model == mock" do
135
- @mock_model.should == @real.nonexistent_model
136
- end
137
-
138
- it "passes: mock == associated_model" do
139
- @real.nonexistent_model.should == @mock_model
140
- end
141
- end
142
-
143
- describe "#is_a?" do
144
- before(:each) do
145
- @model = mock_model(SubMockableModel)
146
- end
147
-
148
- it "says it is_a?(RealModel)" do
149
- @model.is_a?(SubMockableModel).should be(true)
150
- end
151
-
152
- it "says it is_a?(OtherModel) if RealModel is an ancestors" do
153
- @model.is_a?(MockableModel).should be(true)
154
- end
155
-
156
- it "can be stubbed" do
157
- mock_model(MockableModel, :is_a? => true).is_a?(:Foo).should be_true
158
- end
159
- end
160
-
161
- describe "#kind_of?" do
162
- before(:each) do
163
- @model = mock_model(SubMockableModel)
164
- end
165
-
166
- it "says it is kind_of? if RealModel is" do
167
- @model.kind_of?(SubMockableModel).should be(true)
168
- end
169
-
170
- it "says it is kind_of? if RealModel's ancestor is" do
171
- @model.kind_of?(MockableModel).should be(true)
172
- end
173
-
174
- it "can be stubbed" do
175
- mock_model(MockableModel, :kind_of? => true).kind_of?(:Foo).should be_true
176
- end
177
- end
178
-
179
- describe "#instance_of?" do
180
- before(:each) do
181
- @model = mock_model(SubMockableModel)
182
- end
183
-
184
- it "says it is instance_of? if RealModel is" do
185
- @model.instance_of?(SubMockableModel).should be(true)
186
- end
187
-
188
- it "does not say it instance_of? if RealModel isn't, even if it's ancestor is" do
189
- @model.instance_of?(MockableModel).should be(false)
190
- end
191
-
192
- it "can be stubbed" do
193
- mock_model(MockableModel, :instance_of? => true).instance_of?(:Foo).should be_true
194
- end
195
- end
196
-
197
- describe "#respond_to?" do
198
- context "with an ActiveRecord model" do
199
- before(:each) do
200
- MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
201
- @model = mock_model(MockableModel)
202
- end
203
-
204
- it "accepts two arguments" do
205
- expect do
206
- @model.respond_to?("title_before_type_cast", false)
207
- end.to_not raise_exception
208
- end
209
-
210
- context "without as_null_object" do
211
- it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
212
- @model.respond_to?("column_a").should be(true)
213
- end
214
- it "stubs column accessor (with string)" do
215
- @model.respond_to?("column_a")
216
- @model.column_a.should be_nil
217
- end
218
- it "stubs column accessor (with symbol)" do
219
- @model.respond_to?(:column_a)
220
- @model.column_a.should be_nil
221
- end
222
- it "does not stub column accessor if already stubbed in declaration (with string)" do
223
- model = mock_model(MockableModel, "column_a" => "a")
224
- model.respond_to?("column_a")
225
- model.column_a.should eq("a")
226
- end
227
- it "does not stub column accessor if already stubbed in declaration (with symbol)" do
228
- model = mock_model(MockableModel, :column_a => "a")
229
- model.respond_to?("column_a")
230
- model.column_a.should eq("a")
231
- end
232
- it "does not stub column accessor if already stubbed after declaration (with string)" do
233
- @model.stub("column_a" => "a")
234
- @model.respond_to?("column_a")
235
- @model.column_a.should eq("a")
236
- end
237
- it "does not stub column accessor if already stubbed after declaration (with symbol)" do
238
- @model.stub(:column_a => "a")
239
- @model.respond_to?("column_a")
240
- @model.column_a.should eq("a")
241
- end
242
- it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
243
- @model.respond_to?("column_c").should be(false)
244
- end
245
- it "says it will not respond_to?(xxx_before_type_cast)" do
246
- @model.respond_to?("title_before_type_cast").should be(false)
247
- end
248
- end
249
-
250
- context "with as_null_object" do
251
- it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
252
- @model.as_null_object.respond_to?("column_a").should be(true)
253
- end
254
- it "says it will respond_to?(key) even if RealModel does not have the attribute 'key'" do
255
- @model.as_null_object.respond_to?("column_c").should be(true)
256
- end
257
- it "says it will not respond_to?(xxx_before_type_cast)" do
258
- @model.as_null_object.respond_to?("title_before_type_cast").should be(false)
259
- end
260
- it "returns self for any unprepared message" do
261
- @model.as_null_object.tap do |x|
262
- x.non_existant_message.should be(@model)
263
- end
264
- end
265
- end
266
- end
267
-
268
- context "with a non-ActiveRecord model" do
269
- it "responds as normal" do
270
- model = NonActiveRecordModel.new
271
- model.should respond_to(:to_param)
272
- end
273
-
274
- context "with as_null_object" do
275
- it "says it will not respond_to?(xxx_before_type_cast)" do
276
- model = NonActiveRecordModel.new.as_null_object
277
- model.respond_to?("title_before_type_cast").should be(false)
278
- end
279
- end
280
- end
281
-
282
- it "can be stubbed" do
283
- mock_model(MockableModel, :respond_to? => true).respond_to?(:foo).should be_true
284
- end
285
- end
286
-
287
- describe "#class" do
288
- it "returns the mocked model" do
289
- mock_model(MockableModel).class.should eq(MockableModel)
290
- end
291
-
292
- it "can be stubbed" do
293
- mock_model(MockableModel, :class => String).class.should be(String)
294
- end
295
- end
296
-
297
- describe "#to_s" do
298
- it "returns (model.name)_(model#to_param)" do
299
- mock_model(MockableModel).to_s.should == "MockableModel_#{to_param}"
300
- end
301
-
302
- it "can be stubbed" do
303
- mock_model(MockableModel, :to_s => "this string").to_s.should == "this string"
304
- end
305
- end
306
-
307
- describe "#destroyed?" do
308
- context "default" do
309
- it "returns false" do
310
- @model = mock_model(SubMockableModel)
311
- @model.destroyed?.should be(false)
312
- end
313
- end
314
- end
315
-
316
- describe "#marked_for_destruction?" do
317
- context "default" do
318
- it "returns false" do
319
- @model = mock_model(SubMockableModel)
320
- @model.marked_for_destruction?.should be(false)
321
- end
322
- end
323
- end
324
-
325
- describe "#persisted?" do
326
- context "with default identifier" do
327
- it "returns true" do
328
- mock_model(MockableModel).should be_persisted
329
- end
330
- end
331
-
332
- context "with explicit identifier via :id" do
333
- it "returns true" do
334
- mock_model(MockableModel, :id => 37).should be_persisted
335
- end
336
- end
337
-
338
- context "with id => nil" do
339
- it "returns false" do
340
- mock_model(MockableModel, :id => nil).should_not be_persisted
341
- end
342
- end
343
- end
344
-
345
- describe "#valid?" do
346
- context "default" do
347
- it "returns true" do
348
- mock_model(MockableModel).should be_valid
349
- end
350
- end
351
-
352
- context "stubbed with false" do
353
- it "returns false" do
354
- mock_model(MockableModel, :valid? => false).should_not be_valid
355
- end
356
- end
357
- end
358
-
359
- describe "#as_new_record" do
360
- it "says it is a new record" do
361
- m = mock_model(MockableModel)
362
- m.as_new_record.should be_new_record
363
- end
364
-
365
- it "says it is not persisted" do
366
- m = mock_model(MockableModel)
367
- m.as_new_record.should_not be_persisted
368
- end
369
-
370
- it "has a nil id" do
371
- mock_model(MockableModel).as_new_record.id.should be(nil)
372
- end
373
-
374
- it "returns nil for #to_param" do
375
- mock_model(MockableModel).as_new_record.to_param.should be(nil)
376
- end
377
- end
378
-
379
- describe "#blank?" do
380
- it "is false" do
381
- mock_model(MockableModel).should_not be_blank
382
- end
383
- end
384
-
385
- describe "ActiveModel Lint tests" do
386
- require 'active_model/lint'
387
- include RSpec::Rails::MinitestAssertionAdapter
388
- include ActiveModel::Lint::Tests
389
-
390
- # to_s is to support ruby-1.9
391
- ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
392
- example m.gsub('_',' ') do
393
- send m
394
- end
395
- end
396
-
397
- def model
398
- mock_model(MockableModel, :id => nil)
399
- end
400
- end
401
- end