rspec-rails 2.99.0.beta2 → 2.99.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +6 -14
  2. data/Changelog.md +49 -32
  3. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +28 -3
  4. data/lib/rspec/rails.rb +4 -0
  5. data/lib/rspec/rails/example/controller_example_group.rb +26 -2
  6. data/lib/rspec/rails/infer_type_configuration.rb +26 -0
  7. data/lib/rspec/rails/mocks.rb +19 -5
  8. data/lib/rspec/rails/tasks/rspec.rake +12 -5
  9. data/lib/rspec/rails/version.rb +1 -1
  10. metadata +41 -218
  11. data/features/Autotest.md +0 -24
  12. data/features/Generators.md +0 -24
  13. data/features/GettingStarted.md +0 -84
  14. data/features/README.md +0 -56
  15. data/features/RailsVersions.md +0 -4
  16. data/features/Transactions.md +0 -84
  17. data/features/Upgrade.md +0 -121
  18. data/features/controller_specs/Cookies.md +0 -57
  19. data/features/controller_specs/README.md +0 -45
  20. data/features/controller_specs/anonymous_controller.feature +0 -378
  21. data/features/controller_specs/bypass_rescue.feature +0 -75
  22. data/features/controller_specs/capybara.feature +0 -44
  23. data/features/controller_specs/controller_spec.feature +0 -58
  24. data/features/controller_specs/engine_routes.feature +0 -51
  25. data/features/controller_specs/isolation_from_views.feature +0 -87
  26. data/features/controller_specs/render_views.feature +0 -114
  27. data/features/feature_specs/feature_spec.feature +0 -34
  28. data/features/helper_specs/helper_spec.feature +0 -122
  29. data/features/mailer_specs/url_helpers.feature +0 -38
  30. data/features/matchers/README.md +0 -18
  31. data/features/matchers/new_record_matcher.feature +0 -41
  32. data/features/matchers/redirect_to_matcher.feature +0 -40
  33. data/features/matchers/relation_match_array.feature +0 -27
  34. data/features/matchers/render_template_matcher.feature +0 -49
  35. data/features/mocks/mock_model.feature +0 -147
  36. data/features/mocks/stub_model.feature +0 -58
  37. data/features/model_specs/README.md +0 -21
  38. data/features/model_specs/errors_on.feature +0 -51
  39. data/features/model_specs/records.feature +0 -27
  40. data/features/model_specs/transactional_examples.feature +0 -109
  41. data/features/request_specs/request_spec.feature +0 -49
  42. data/features/routing_specs/README.md +0 -16
  43. data/features/routing_specs/be_routable_matcher.feature +0 -80
  44. data/features/routing_specs/engine_routes.feature +0 -38
  45. data/features/routing_specs/named_routes.feature +0 -18
  46. data/features/routing_specs/route_to_matcher.feature +0 -90
  47. data/features/step_definitions/additional_cli_steps.rb +0 -4
  48. data/features/step_definitions/model_steps.rb +0 -3
  49. data/features/support/env.rb +0 -53
  50. data/features/support/rails_versions.rb +0 -4
  51. data/features/support/rubinius.rb +0 -6
  52. data/features/view_specs/inferred_controller_path.feature +0 -45
  53. data/features/view_specs/stub_template.feature +0 -51
  54. data/features/view_specs/view_spec.feature +0 -206
  55. data/spec/autotest/rails_rspec2_spec.rb +0 -36
  56. data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
  57. data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
  58. data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
  59. data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -57
  60. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
  61. data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
  62. data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
  63. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -150
  64. data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
  65. data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
  66. data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
  67. data/spec/rspec/rails/configuration_spec.rb +0 -26
  68. data/spec/rspec/rails/deprecations_spec.rb +0 -18
  69. data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -126
  70. data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
  71. data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
  72. data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
  73. data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
  74. data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
  75. data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
  76. data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
  77. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
  78. data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
  79. data/spec/rspec/rails/fixture_support_spec.rb +0 -17
  80. data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
  81. data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
  82. data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
  83. data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -43
  84. data/spec/rspec/rails/matchers/errors_on_spec.rb +0 -38
  85. data/spec/rspec/rails/matchers/has_spec.rb +0 -29
  86. data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
  87. data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
  88. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
  89. data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
  90. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
  91. data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -401
  92. data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
  93. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
  94. data/spec/rspec/rails/view_rendering_spec.rb +0 -111
  95. data/spec/spec_helper.rb +0 -32
  96. data/spec/support/ar_classes.rb +0 -42
  97. data/spec/support/helpers.rb +0 -34
  98. data/spec/support/matchers.rb +0 -9
  99. data/spec/support/null_object.rb +0 -6
@@ -1,81 +0,0 @@
1
- require "spec_helper"
2
- require "active_support"
3
- require "active_support/test_case"
4
-
5
- describe "redirect_to" do
6
- include RSpec::Rails::Matchers::RedirectTo
7
-
8
- let(:response) { ActionController::TestResponse.new }
9
-
10
- context "with should" do
11
- context "when assert_redirected_to passes" do
12
- def assert_redirected_to(*); end
13
-
14
- it "passes" do
15
- expect do
16
- expect(response).to redirect_to("destination")
17
- end.to_not raise_exception
18
- end
19
- end
20
-
21
- context "when assert_redirected_to fails" do
22
- def assert_redirected_to(*)
23
- raise ActiveSupport::TestCase::Assertion.new("this message")
24
- end
25
-
26
- it "uses failure message from assert_redirected_to" do
27
- expect do
28
- expect(response).to redirect_to("destination")
29
- end.to raise_exception("this message")
30
- end
31
- end
32
-
33
- context "when fails due to some other exception" do
34
- def assert_redirected_to(*)
35
- raise "oops"
36
- end
37
-
38
- it "raises that exception" do
39
- expect do
40
- expect(response).to redirect_to("destination")
41
- end.to raise_exception("oops")
42
- end
43
- end
44
- end
45
-
46
- context "with should_not" do
47
- context "when assert_redirected_to fails" do
48
- def assert_redirected_to(*)
49
- raise ActiveSupport::TestCase::Assertion.new("this message")
50
- end
51
-
52
- it "passes" do
53
- expect do
54
- expect(response).not_to redirect_to("destination")
55
- end.to_not raise_exception
56
- end
57
- end
58
-
59
- context "when assert_redirected_to passes" do
60
- def assert_redirected_to(*); end
61
-
62
- it "fails with custom failure message" do
63
- expect do
64
- expect(response).not_to redirect_to("destination")
65
- end.to raise_exception(/expected not to redirect to \"destination\", but did/)
66
- end
67
- end
68
-
69
- context "when fails due to some other exception" do
70
- def assert_redirected_to(*)
71
- raise "oops"
72
- end
73
-
74
- it "raises that exception" do
75
- expect do
76
- expect(response).not_to redirect_to("destination")
77
- end.to raise_exception("oops")
78
- end
79
- end
80
- end
81
- 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
- expect(MockableModel.all).to match_array(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
- expect(MockableModel.all).not_to match_array(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
- expect(MockableModel.scoped).to match_array(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
- expect(MockableModel.scoped).not_to match_array(models.reverse)
25
- end
26
- end
27
-
28
- it "fails if the scope encompasses fewer records than on the right hand side" do
29
- expect(MockableModel.limit(models.length - 1)).not_to match_array(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
- expect(matcher.description).to eq("route {:get=>\"path\"} to {\"these\"=>\"options\"}")
15
- end
16
-
17
- it "delegates to assert_recognizes" do
18
- expect(self).to receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" }, {})
19
- expect({:get => "path"}).to route_to("these" => "options")
20
- end
21
-
22
- context "with shortcut syntax" do
23
- it "routes with extra options" do
24
- expect(self).to receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" }, {})
25
- expect(get("path")).to route_to("controller#action", :extra => "options")
26
- end
27
-
28
- it "routes without extra options" do
29
- expect(self).to receive(:assert_recognizes).with(
30
- {:controller => "controller", :action => "action"},
31
- {:method=> :get, :path=>"path" },
32
- {}
33
- )
34
- expect(get("path")).to route_to("controller#action")
35
- end
36
-
37
- it "routes with one query parameter" do
38
- expect(self).to receive(:assert_recognizes).with(
39
- {:controller => "controller", :action => "action", :queryitem => "queryvalue"},
40
- {:method=> :get, :path=>"path" },
41
- {'queryitem' => 'queryvalue' }
42
- )
43
- expect(get("path?queryitem=queryvalue")).to route_to("controller#action", :queryitem => 'queryvalue')
44
- end
45
-
46
- it "routes with multiple query parameters" do
47
- expect(self).to 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
- expect(get("path?queryitem=queryvalue&qi2=qv2")).to 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
- expect({:get => "path"}).to 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
- expect({:get => "path"}).to 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
- expect({:get => "path"}).to 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
- expect({:get => "path"}).to 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
- expect({:get => "path"}).not_to route_to("these" => "options")
105
- end.to raise_error(/expected {:get=>"path"} not to route to {"these"=>"options"}/)
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
- expect({:get => "path"}).not_to 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
- expect({:get => "path"}).not_to 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
- expect({:get => "path"}).not_to 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
- expect({"this" => "path"}).to 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
- expect(model.class.name).to 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
- expect(model.class.name).to 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
- expect(@model.instance_variable_get(:@name)).to eq("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
- expect(model).not_to 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
- expect(model.errors).to 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
- expect(model.errors).not_to 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
- expect(model.errors).not_to 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
- expect(params).to eq({: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
- expect(@mock_model).to eq(@real.mockable_model)
120
- end
121
-
122
- it "passes: mock == associated_model" do
123
- expect(@real.mockable_model).to eq(@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
- expect(@mock_model).to eq(@real.nonexistent_model)
136
- end
137
-
138
- it "passes: mock == associated_model" do
139
- expect(@real.nonexistent_model).to eq(@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
- expect(@model.is_a?(SubMockableModel)).to be(true)
150
- end
151
-
152
- it "says it is_a?(OtherModel) if RealModel is an ancestors" do
153
- expect(@model.is_a?(MockableModel)).to be(true)
154
- end
155
-
156
- it "can be stubbed" do
157
- expect(mock_model(MockableModel, :is_a? => true).is_a?(:Foo)).to be_truthy
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
- expect(@model.kind_of?(SubMockableModel)).to be(true)
168
- end
169
-
170
- it "says it is kind_of? if RealModel's ancestor is" do
171
- expect(@model.kind_of?(MockableModel)).to be(true)
172
- end
173
-
174
- it "can be stubbed" do
175
- expect(mock_model(MockableModel, :kind_of? => true).kind_of?(:Foo)).to be_truthy
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
- expect(@model.instance_of?(SubMockableModel)).to 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
- expect(@model.instance_of?(MockableModel)).to be(false)
190
- end
191
-
192
- it "can be stubbed" do
193
- expect(mock_model(MockableModel, :instance_of? => true).instance_of?(:Foo)).to be_truthy
194
- end
195
- end
196
-
197
- describe "#respond_to?" do
198
- context "with an ActiveRecord model" do
199
- before(:each) do
200
- allow(MockableModel).to receive(: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
- expect(@model.respond_to?("column_a")).to be(true)
213
- end
214
- it "stubs column accessor (with string)" do
215
- @model.respond_to?("column_a")
216
- expect(@model.column_a).to be_nil
217
- end
218
- it "stubs column accessor (with symbol)" do
219
- @model.respond_to?(:column_a)
220
- expect(@model.column_a).to 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
- expect(model.column_a).to 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
- expect(model.column_a).to eq("a")
231
- end
232
- it "does not stub column accessor if already stubbed after declaration (with string)" do
233
- allow(@model).to receive(:column_a).and_return("a")
234
- @model.respond_to?("column_a")
235
- expect(@model.column_a).to eq("a")
236
- end
237
- it "does not stub column accessor if already stubbed after declaration (with symbol)" do
238
- allow(@model).to receive(:column_a).and_return("a")
239
- @model.respond_to?("column_a")
240
- expect(@model.column_a).to eq("a")
241
- end
242
- it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
243
- expect(@model.respond_to?("column_c")).to be(false)
244
- end
245
- it "says it will not respond_to?(xxx_before_type_cast)" do
246
- expect(@model.respond_to?("title_before_type_cast")).to 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
- expect(@model.as_null_object.respond_to?("column_a")).to be(true)
253
- end
254
- it "says it will respond_to?(key) even if RealModel does not have the attribute 'key'" do
255
- expect(@model.as_null_object.respond_to?("column_c")).to be(true)
256
- end
257
- it "says it will not respond_to?(xxx_before_type_cast)" do
258
- expect(@model.as_null_object.respond_to?("title_before_type_cast")).to be(false)
259
- end
260
- it "returns self for any unprepared message" do
261
- @model.as_null_object.tap do |x|
262
- expect(x.non_existant_message).to 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
- expect(model).to 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
- expect(model.respond_to?("title_before_type_cast")).to be(false)
278
- end
279
- end
280
- end
281
-
282
- it "can be stubbed" do
283
- expect(mock_model(MockableModel, :respond_to? => true).respond_to?(:foo)).to be_truthy
284
- end
285
- end
286
-
287
- describe "#class" do
288
- it "returns the mocked model" do
289
- expect(mock_model(MockableModel).class).to eq(MockableModel)
290
- end
291
-
292
- it "can be stubbed" do
293
- expect(mock_model(MockableModel, :class => String).class).to be(String)
294
- end
295
- end
296
-
297
- describe "#to_s" do
298
- it "returns (model.name)_(model#to_param)" do
299
- expect(mock_model(MockableModel).to_s).to eq("MockableModel_#{to_param}")
300
- end
301
-
302
- it "can be stubbed" do
303
- expect(mock_model(MockableModel, :to_s => "this string").to_s).to eq("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
- expect(@model.destroyed?).to 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
- expect(@model.marked_for_destruction?).to 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
- expect(mock_model(MockableModel)).to be_persisted
329
- end
330
- end
331
-
332
- context "with explicit identifier via :id" do
333
- it "returns true" do
334
- expect(mock_model(MockableModel, :id => 37)).to be_persisted
335
- end
336
- end
337
-
338
- context "with id => nil" do
339
- it "returns false" do
340
- expect(mock_model(MockableModel, :id => nil)).not_to be_persisted
341
- end
342
- end
343
- end
344
-
345
- describe "#valid?" do
346
- context "default" do
347
- it "returns true" do
348
- expect(mock_model(MockableModel)).to be_valid
349
- end
350
- end
351
-
352
- context "stubbed with false" do
353
- it "returns false" do
354
- expect(mock_model(MockableModel, :valid? => false)).not_to 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
- expect(m.as_new_record).to be_new_record
363
- end
364
-
365
- it "says it is not persisted" do
366
- m = mock_model(MockableModel)
367
- expect(m.as_new_record).not_to be_persisted
368
- end
369
-
370
- it "has a nil id" do
371
- expect(mock_model(MockableModel).as_new_record.id).to be(nil)
372
- end
373
-
374
- it "returns nil for #to_param" do
375
- expect(mock_model(MockableModel).as_new_record.to_param).to be(nil)
376
- end
377
- end
378
-
379
- describe "#blank?" do
380
- it "is false" do
381
- expect(mock_model(MockableModel)).not_to 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