rspec-activemodel-mocks 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aad23d1dddfba78f66030c7f0cae1ac0e27d4985af0f4802ea8580b794148b7
4
- data.tar.gz: 9857de724a896288463b66e8beb94c65a9f9c30ab7e66ec35fd2405b26db9c3c
3
+ metadata.gz: 59ec608e6f9b0a1ee5477ed48c3d2750ad76600d4bae9f79d25c9a4780da6024
4
+ data.tar.gz: 727ef3cc5f9cc8944e15ef79d9f43639b9e059ba4ac6c8a8eb6402722a5a4710
5
5
  SHA512:
6
- metadata.gz: b9bcd1324168510eee65b4f7a8e80efe9c463ce00f2bde09a3f479b94b63f3a23c990d14bc21b07197c33fee237e4ff9deabf10381c3afc1f483c512da1958f1
7
- data.tar.gz: 68cd5a0eb7e7f7bed0c48a2d9b8fb9e137e4899dd2264770f66837fc19f3927e84c33743e61fd2ce46f64ac98cca0425a2ea7ab9b7fd13d6395ed9d12580aa15
6
+ metadata.gz: 545c2feb61438959b3c24a5197537a88951332d4c2e197a9ae0a95028aa014940c84a132d0a2382670d341ce57084736c42bb096859b8a8f70750a3d489f5c4d
7
+ data.tar.gz: 56ee248bda2bc142e0fb391f3f21130a1632c63047896d3377243885ea97689c8b9ec612319cf087015678078297f5973aef07642d90d87728e692216ef5124d
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RSpec::ActiveModel::Mocks [![Build Status](https://secure.travis-ci.org/rspec/rspec-activemodel-mocks.png?branch=master)](http://travis-ci.org/rspec/rspec-activemodel-mocks)
1
+ # RSpec::ActiveModel::Mocks [![RSpec CI](https://github.com/rspec/rspec-activemodel-mocks/actions/workflows/ci.yml/badge.svg)](https://github.com/rspec/rspec-activemodel-mocks/actions/workflows/ci.yml)
2
2
 
3
3
  RSpec::ActiveModel::Mocks provides tools for testing `ActiveModel` classes.
4
4
 
@@ -14,12 +14,8 @@ And then execute:
14
14
 
15
15
  $ bundle
16
16
 
17
- If you are using [rspec-rails](https://github.com/rspec/rspec-rails) and have
18
- followed the installation instructions there, you're all set to use `stub_model`
19
- and `mock_model`.
20
-
21
- To use `stub_model` and `mock_model` without rspec-rails, require the
22
- following file:
17
+ To finish the installation and start using `stub_model` and `mock_model`, require the
18
+ following file in your `spec_helper.rb` or `rails_helper.rb`.
23
19
 
24
20
  require 'rspec/active_model/mocks'
25
21
 
@@ -1,4 +1,5 @@
1
- Then /^the example(s)? should( all)? pass$/ do |_, _|
2
- step %q{the output should contain "0 failures"}
3
- step %q{the exit status should be 0}
1
+ # frozen_string_literal: true
2
+ Then(/^the example(s)? should( all)? pass$/) do |_, _|
3
+ step 'the output should contain "0 failures"'
4
+ step 'the exit status should be 0'
4
5
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'aruba/cucumber'
2
3
 
3
4
  module ArubaExt
@@ -17,7 +18,7 @@ unless File.directory?('./tmp/sample')
17
18
  end
18
19
 
19
20
  def aruba_path(file_or_dir)
20
- File.expand_path("../../../#{file_or_dir.sub('sample','aruba')}", __FILE__)
21
+ File.expand_path("../../../#{file_or_dir.sub('sample', 'aruba')}", __FILE__)
21
22
  end
22
23
 
23
24
  def sample_path(file_or_dir)
@@ -37,12 +38,12 @@ def copy(file_or_dir)
37
38
  end
38
39
 
39
40
  Before do
40
- steps %Q{
41
+ steps %(
41
42
  Given a directory named "spec"
42
- }
43
+ )
43
44
 
44
45
  Dir['tmp/sample/*'].each do |file_or_dir|
45
- if !(file_or_dir =~ /spec$/)
46
+ if file_or_dir !~ /spec$/
46
47
  write_symlink(file_or_dir)
47
48
  end
48
49
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  # Required until https://github.com/rubinius/rubinius/issues/2430 is resolved
2
- ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc"
3
+ ENV['RBXOPT'] = "#{ENV.fetch("RBXOPT", nil)} -Xcompiler.no_rbc"
3
4
 
4
- Around "@unsupported-on-rbx" do |scenario, block|
5
+ Around "@unsupported-on-rbx" do |_scenario, block|
5
6
  block.call unless defined?(Rubinius)
6
7
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_support'
2
3
  require 'active_support/core_ext/object/to_param'
3
4
  require 'active_model'
@@ -5,7 +6,6 @@ require 'active_model'
5
6
  module RSpec::ActiveModel::Mocks
6
7
  class IllegalDataAccessException < StandardError; end
7
8
  module Mocks
8
-
9
9
  module ActiveModelInstanceMethods
10
10
  # Stubs `persisted?` to return false and `id` to return nil
11
11
  # @return self
@@ -74,6 +74,8 @@ module RSpec::ActiveModel::Mocks
74
74
  end
75
75
  end
76
76
 
77
+ # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
78
+
77
79
  # Creates a test double representing `string_or_model_class` with common
78
80
  # ActiveModel methods stubbed out. Additional methods may be easily
79
81
  # stubbed (via add_stubs) if `stubs` is passed. This is most useful for
@@ -91,14 +93,25 @@ module RSpec::ActiveModel::Mocks
91
93
  # * A String representing a Class that does not exist
92
94
  # * A String representing a Class that extends ActiveModel::Naming
93
95
  # * A Class that extends ActiveModel::Naming
94
- def mock_model(string_or_model_class, stubs = {})
96
+ def mock_model(string_or_model_class, stubs={})
97
+ @__rspec_active_model_mocks ||= Hash.new { |h, k| h[k] = [] }
98
+
95
99
  if String === string_or_model_class
96
100
  if Object.const_defined?(string_or_model_class)
97
101
  model_class = Object.const_get(string_or_model_class)
98
102
  else
99
103
  model_class = Object.const_set(string_or_model_class, Class.new do
104
+ # rubocop:disable Style/SingleLineMethods
100
105
  extend ::ActiveModel::Naming
101
106
  def self.primary_key; :id; end
107
+
108
+ # For detection of being a valid association in 7+
109
+ def self.<(other); other == ActiveRecord::Base; end
110
+ def self._reflect_on_association(_other); nil; end
111
+ def self.composite_primary_key?; false; end
112
+ def self.has_query_constraints?; false; end
113
+ def self.param_delimiter; "-"; end
114
+ # rubocop:enable Style/SingleLineMethods
102
115
  end)
103
116
  end
104
117
  else
@@ -106,24 +119,30 @@ module RSpec::ActiveModel::Mocks
106
119
  end
107
120
 
108
121
  unless model_class.kind_of? ::ActiveModel::Naming
109
- raise ArgumentError.new <<-EOM
122
+ raise ArgumentError, <<-EOM
110
123
  The mock_model method can only accept as its first argument:
111
124
  * A String representing a Class that does not exist
112
125
  * A String representing a Class that extends ActiveModel::Naming
113
126
  * A Class that extends ActiveModel::Naming
114
127
 
115
128
  It received #{model_class.inspect}
116
- EOM
129
+ EOM
117
130
  end
118
131
 
119
- stubs = {:id => next_id}.merge(stubs)
120
- stubs = {:persisted? => !!stubs[:id],
121
- :destroyed? => false,
122
- :marked_for_destruction? => false,
123
- :valid? => true,
124
- :blank? => false}.merge(stubs)
132
+ stubs = { :id => next_id }.merge(stubs)
133
+ stubs = { :persisted? => !!stubs[:id],
134
+ :destroyed? => false,
135
+ :marked_for_destruction? => false,
136
+ :valid? => true,
137
+ :blank? => false }.merge(stubs)
125
138
 
126
139
  double("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m|
140
+ if model_class.method(:===).owner == Module && !stubs.key?(:===)
141
+ allow(model_class).to receive(:===).and_wrap_original do |original, other|
142
+ @__rspec_active_model_mocks[model_class].include?(other) || original.call(other)
143
+ end
144
+ end
145
+ @__rspec_active_model_mocks[model_class] << m
127
146
  msingleton = class << m; self; end
128
147
  msingleton.class_eval do
129
148
  include ActiveModelInstanceMethods
@@ -131,25 +150,22 @@ EOM
131
150
  include ActiveModel::Conversion
132
151
  include ActiveModel::Validations
133
152
  end
134
- if defined?(ActiveRecord)
135
- [:save, :update_attributes, :update].each do |key|
136
- if stubs[key] == false
137
- RSpec::Mocks.allow_message(m.errors, :empty?).and_return(false)
138
- end
139
- end
153
+ if defined?(ActiveRecord) && stubs.values_at(:save, :update_attributes, :update).include?(false)
154
+ RSpec::Mocks.allow_message(m.errors, :empty?).and_return(false)
155
+ RSpec::Mocks.allow_message(m.errors, :blank?).and_return(false)
140
156
  end
141
157
 
142
158
  msingleton.__send__(:define_method, :is_a?) do |other|
143
159
  model_class.ancestors.include?(other)
144
- end unless stubs.has_key?(:is_a?)
160
+ end unless stubs.key?(:is_a?)
145
161
 
146
162
  msingleton.__send__(:define_method, :kind_of?) do |other|
147
163
  model_class.ancestors.include?(other)
148
- end unless stubs.has_key?(:kind_of?)
164
+ end unless stubs.key?(:kind_of?)
149
165
 
150
166
  msingleton.__send__(:define_method, :instance_of?) do |other|
151
167
  other == model_class
152
- end unless stubs.has_key?(:instance_of?)
168
+ end unless stubs.key?(:instance_of?)
153
169
 
154
170
  msingleton.__send__(:define_method, :__model_class_has_column?) do |method_name|
155
171
  model_class.respond_to?(:column_names) && model_class.column_names.include?(method_name.to_s)
@@ -157,28 +173,33 @@ EOM
157
173
 
158
174
  msingleton.__send__(:define_method, :has_attribute?) do |attr_name|
159
175
  __model_class_has_column?(attr_name)
160
- end unless stubs.has_key?(:has_attribute?)
176
+ end unless stubs.key?(:has_attribute?)
161
177
 
162
178
  msingleton.__send__(:define_method, :respond_to?) do |method_name, *args|
163
- include_private = args.first || false
179
+ include_private = args.first || false
164
180
  __model_class_has_column?(method_name) ? true : super(method_name, include_private)
165
- end unless stubs.has_key?(:respond_to?)
181
+ end unless stubs.key?(:respond_to?)
166
182
 
167
- msingleton.__send__(:define_method, :method_missing) do |m, *a, &b|
168
- respond_to?(m) ? null_object? ? self : nil : super(m, *a, &b)
183
+ msingleton.__send__(:define_method, :method_missing) do |missing_m, *a, &b|
184
+ if respond_to?(missing_m)
185
+ null_object? ? self : nil
186
+ else
187
+ super(missing_m, *a, &b)
188
+ end
169
189
  end
170
190
 
171
191
  msingleton.__send__(:define_method, :class) do
172
192
  model_class
173
- end unless stubs.has_key?(:class)
193
+ end unless stubs.key?(:class)
174
194
 
175
195
  mock_param = to_param
176
196
  msingleton.__send__(:define_method, :to_s) do
177
197
  "#{model_class.name}_#{mock_param}"
178
- end unless stubs.has_key?(:to_s)
198
+ end unless stubs.key?(:to_s)
179
199
  yield m if block_given?
180
200
  end
181
201
  end
202
+ # rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
182
203
 
183
204
  module ActiveModelStubExtensions
184
205
  # Stubs `persisted` to return false and `id` to return nil
@@ -197,7 +218,7 @@ EOM
197
218
  module ActiveRecordStubExtensions
198
219
  # Stubs `id` (or other primary key method) to return nil
199
220
  def as_new_record
200
- self.__send__("#{self.class.primary_key}=", nil)
221
+ __send__("#{self.class.primary_key}=", nil)
201
222
  super
202
223
  end
203
224
 
@@ -209,10 +230,13 @@ EOM
209
230
  # Raises an IllegalDataAccessException (stubbed models are not allowed to access the database)
210
231
  # @raises IllegalDataAccessException
211
232
  def connection
212
- raise RSpec::ActiveModel::Mocks::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
233
+ raise RSpec::ActiveModel::Mocks::IllegalDataAccessException,
234
+ "stubbed models are not allowed to access the database"
213
235
  end
214
236
  end
215
237
 
238
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
239
+
216
240
  # Creates an instance of `Model` with `to_param` stubbed using a
217
241
  # generated value that is unique to each object. If `Model` is an
218
242
  # `ActiveRecord` model, it is prohibited from accessing the database.
@@ -246,17 +270,21 @@ EOM
246
270
  if defined?(ActiveRecord) && model_class < ActiveRecord::Base && model_class.primary_key
247
271
  m.extend ActiveRecordStubExtensions
248
272
  primary_key = model_class.primary_key.to_sym
249
- stubs = {primary_key => next_id}.merge(stubs)
250
- stubs = {:persisted? => !!stubs[primary_key]}.merge(stubs)
273
+ stubs = { primary_key => next_id }.merge(stubs)
274
+ stubs = { :persisted? => !!stubs[primary_key] }.merge(stubs)
251
275
  else
252
- stubs = {:id => next_id}.merge(stubs)
253
- stubs = {:persisted? => !!stubs[:id]}.merge(stubs)
276
+ stubs = { :id => next_id }.merge(stubs)
277
+ stubs = { :persisted? => !!stubs[:id] }.merge(stubs)
254
278
  end
255
- stubs = {:blank? => false}.merge(stubs)
279
+ stubs = { :blank? => false }.merge(stubs)
256
280
 
257
281
  stubs.each do |message, return_value|
258
282
  if m.respond_to?("#{message}=")
259
- m.__send__("#{message}=", return_value)
283
+ begin
284
+ m.__send__("#{message}=", return_value)
285
+ rescue ActiveModel::MissingAttributeError
286
+ RSpec::Mocks.allow_message(m, message).and_return(return_value)
287
+ end
260
288
  else
261
289
  RSpec::Mocks.allow_message(m, message).and_return(return_value)
262
290
  end
@@ -265,15 +293,17 @@ EOM
265
293
  yield m if block_given?
266
294
  end
267
295
  end
296
+ # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
268
297
 
269
- private
298
+ private
270
299
 
300
+ # rubocop:disable Style/ClassVars
271
301
  @@model_id = 1000
272
302
 
273
303
  def next_id
274
304
  @@model_id += 1
275
305
  end
276
-
306
+ # rubocop:enable Style/ClassVars
277
307
  end
278
308
  end
279
309
 
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  module RSpec
2
3
  module ActiveModel
3
4
  module Mocks
4
5
  module Version
5
- STRING = '1.1.0'
6
+ STRING = '1.2.1'
6
7
  end
7
8
  end
8
9
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require 'rspec/core'
2
3
 
3
- RSpec::configure do |c|
4
+ RSpec.configure do |c|
4
5
  c.backtrace_exclusion_patterns << /lib\/rspec\/active_model\/mocks/
5
6
  end
6
7
 
@@ -1 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  require 'rspec/active_model/mocks'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe "mock_model(RealModel)" do
@@ -81,6 +82,7 @@ describe "mock_model(RealModel)" do
81
82
  it "is empty" do
82
83
  model = mock_model(MockableModel)
83
84
  expect(model.errors).to be_empty
85
+ expect(model.errors).to be_blank
84
86
  end
85
87
  end
86
88
 
@@ -88,6 +90,7 @@ describe "mock_model(RealModel)" do
88
90
  it "is not empty" do
89
91
  model = mock_model(MockableModel, :save => false)
90
92
  expect(model.errors).not_to be_empty
93
+ expect(model.errors).not_to be_blank
91
94
  end
92
95
  end
93
96
 
@@ -95,15 +98,16 @@ describe "mock_model(RealModel)" do
95
98
  it "is not empty" do
96
99
  model = mock_model(MockableModel, :save => false)
97
100
  expect(model.errors).not_to be_empty
101
+ expect(model.errors).not_to be_blank
98
102
  end
99
103
  end
100
104
  end
101
105
 
102
106
  describe "with params" do
103
107
  it "does not mutate its parameters" do
104
- params = {:a => 'b'}
108
+ params = { :a => 'b' }
105
109
  mock_model(MockableModel, params)
106
- expect(params).to eq({:a => 'b'})
110
+ expect(params).to eq({ :a => 'b' })
107
111
  end
108
112
  end
109
113
 
@@ -157,6 +161,69 @@ describe "mock_model(RealModel)" do
157
161
  end
158
162
  end
159
163
 
164
+ describe "#===" do
165
+ it "works with a case statement" do
166
+ case mock_model(MockableModel)
167
+ when MockableModel then true
168
+ else
169
+ raise
170
+ end
171
+
172
+ # rubocop:disable Lint/LiteralAsCondition
173
+ case :not_mockable_model
174
+ when MockableModel then raise
175
+ else
176
+ true
177
+ end
178
+ # rubocop:enable Lint/LiteralAsCondition
179
+ end
180
+
181
+ it "won't break previous stubs" do
182
+ allow(MockableModel).to receive(:===).with("string") { true }
183
+ mock_model(MockableModel)
184
+
185
+ # rubocop:disable Lint/LiteralAsCondition
186
+ case "string"
187
+ when MockableModel then true
188
+ else
189
+ raise
190
+ end
191
+ # rubocop:enable Lint/LiteralAsCondition
192
+ end
193
+
194
+ it "won't override class definitions" do
195
+ another_mockable_model =
196
+ Class.new(MockableModel) do
197
+ def self.===(_other)
198
+ true
199
+ end
200
+ end
201
+
202
+ mock_model(another_mockable_model)
203
+
204
+ # rubocop:disable Lint/LiteralAsCondition
205
+ case "string"
206
+ when another_mockable_model then true
207
+ else
208
+ raise
209
+ end
210
+ # rubocop:enable Lint/LiteralAsCondition
211
+ end
212
+
213
+ it "works for multiple mocks of the same model" do
214
+ foo = mock_model(MockableModel)
215
+ bar = mock_model(MockableModel)
216
+ baz = mock_model(MockableModelNoPrimaryKey)
217
+ quz = mock_model(MockableModel)
218
+
219
+ expect(MockableModel === foo).to be(true)
220
+ expect(MockableModel === bar).to be(true)
221
+ expect(MockableModel === baz).to be(false)
222
+ expect(MockableModelNoPrimaryKey === baz).to be(true)
223
+ expect(MockableModel === quz).to be(true)
224
+ end
225
+ end
226
+
160
227
  describe "#kind_of?" do
161
228
  before(:each) do
162
229
  @model = mock_model(SubMockableModel)
@@ -196,7 +263,7 @@ describe "mock_model(RealModel)" do
196
263
  describe "#has_attribute?" do
197
264
  context "with an ActiveRecord model" do
198
265
  before(:each) do
199
- MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
266
+ MockableModel.stub(:column_names).and_return(%w[column_a column_b])
200
267
  @model = mock_model(MockableModel)
201
268
  end
202
269
 
@@ -223,7 +290,7 @@ describe "mock_model(RealModel)" do
223
290
  describe "#respond_to?" do
224
291
  context "with an ActiveRecord model" do
225
292
  before(:each) do
226
- allow(MockableModel).to receive(:column_names).and_return(["column_a", "column_b"])
293
+ allow(MockableModel).to receive(:column_names).and_return(%w[column_a column_b])
227
294
  @model = mock_model(MockableModel)
228
295
  end
229
296
 
@@ -416,6 +483,7 @@ describe "mock_model(RealModel)" do
416
483
  end
417
484
 
418
485
  describe "ActiveModel Lint tests" do
486
+ # rubocop:disable Lint/EmptyExpression,Metrics/BlockNesting
419
487
  begin
420
488
  require 'minitest/assertions'
421
489
  include Minitest::Assertions
@@ -451,9 +519,9 @@ describe "mock_model(RealModel)" do
451
519
  ERR
452
520
  end
453
521
  include Test::Unit::Assertions
454
- if defined?(Test::Unit::AutoRunner.need_auto_run = ())
522
+ if defined?((Test::Unit::AutoRunner.need_auto_run = ()))
455
523
  Test::Unit::AutoRunner.need_auto_run = false
456
- elsif defined?(Test::Unit.run = ())
524
+ elsif defined?((Test::Unit.run = ()))
457
525
  Test::Unit.run = false
458
526
  end
459
527
  else
@@ -464,20 +532,21 @@ describe "mock_model(RealModel)" do
464
532
  else
465
533
  require 'test/unit/assertions'
466
534
  include Test::Unit::Assertions
467
- if defined?(Test::Unit::AutoRunner.need_auto_run = ())
535
+ if defined?((Test::Unit::AutoRunner.need_auto_run = ()))
468
536
  Test::Unit::AutoRunner.need_auto_run = false
469
- elsif defined?(Test::Unit.run = ())
537
+ elsif defined?((Test::Unit.run = ()))
470
538
  Test::Unit.run = false
471
539
  end
472
540
  end
473
541
  end
542
+ # rubocop:enable Lint/EmptyExpression,Metrics/BlockNesting
474
543
 
475
544
  require 'active_model/lint'
476
545
  include ActiveModel::Lint::Tests
477
546
 
478
547
  # to_s is to support ruby-1.9
479
- ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
480
- example m.gsub('_',' ') do
548
+ ActiveModel::Lint::Tests.public_instance_methods.map {|m| m.to_s}.grep(/^test/).each do |m|
549
+ example m.gsub('_', ' ') do
481
550
  send m
482
551
  end
483
552
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe "stub_model" do
@@ -89,7 +90,8 @@ describe "stub_model" do
89
90
  it "raises when hitting the db" do
90
91
  expect do
91
92
  stub_model(MockableModel).connection
92
- end.to raise_error(RSpec::ActiveModel::Mocks::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
93
+ end.to raise_error(RSpec::ActiveModel::Mocks::IllegalDataAccessException,
94
+ /stubbed models are not allowed to access the database/)
93
95
  end
94
96
 
95
97
  it "increments the id" do
@@ -161,6 +163,36 @@ describe "stub_model" do
161
163
  end
162
164
  expect(model).to be(@block_arg)
163
165
  end
166
+ end
167
+
168
+ describe "#===" do
169
+ it "works with a case statement" do
170
+ case stub_model(MockableModel)
171
+ when MockableModel then true
172
+ else
173
+ raise
174
+ end
175
+
176
+ # rubocop:disable Lint/LiteralAsCondition
177
+ case :not_stub_model
178
+ when MockableModel then raise
179
+ else
180
+ true
181
+ end
182
+ # rubocop:enable Lint/LiteralAsCondition
183
+ end
164
184
 
185
+ it "works for multiple mocks of the same model" do
186
+ foo = stub_model(MockableModel)
187
+ bar = stub_model(MockableModel)
188
+ baz = stub_model(MockableModelNoPrimaryKey)
189
+ qux = stub_model(MockableModel)
190
+
191
+ expect(MockableModel === foo).to be(true)
192
+ expect(MockableModel === bar).to be(true)
193
+ expect(MockableModel === baz).to be(false)
194
+ expect(MockableModelNoPrimaryKey === baz).to be(true)
195
+ expect(MockableModel === qux).to be(true)
196
+ end
165
197
  end
166
198
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,16 @@
1
+ # frozen_string_literal: true
1
2
  require 'rspec/active_model/mocks'
2
3
  require 'active_record'
3
4
 
4
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
5
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
5
6
 
6
- class RSpec::Core::ExampleGroup
7
- def self.run_all(reporter=nil)
8
- run(reporter || RSpec::Mocks::Mock.new('reporter').as_null_object)
7
+ module RSpec
8
+ module Core
9
+ class ExampleGroup
10
+ def self.run_all(reporter=nil)
11
+ run(reporter || RSpec::Mocks::Mock.new('reporter').as_null_object)
12
+ end
13
+ end
9
14
  end
10
15
  end
11
16
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ActiveRecord::Base.establish_connection(
2
3
  :adapter => 'sqlite3',
3
4
  :database => ':memory:'
@@ -5,31 +6,31 @@ ActiveRecord::Base.establish_connection(
5
6
 
6
7
  module Connections
7
8
  def self.extended(host)
8
- host.connection.execute <<-eosql
9
+ host.connection.execute <<-EOSQL
9
10
  CREATE TABLE #{host.table_name} (
10
11
  #{host.primary_key} integer PRIMARY KEY AUTOINCREMENT,
11
12
  associated_model_id integer,
12
13
  mockable_model_id integer,
13
14
  nonexistent_model_id integer
14
15
  )
15
- eosql
16
+ EOSQL
16
17
  end
17
18
  end
18
19
 
19
20
  module ConnectionsView
20
21
  def self.extended(host)
21
- host.connection.execute <<-eosql
22
+ host.connection.execute <<-EOSQL
22
23
  CREATE TABLE some_table (
23
24
  associated_model_id integer,
24
25
  mockable_model_id integer,
25
26
  nonexistent_model_id integer
26
27
  )
27
- eosql
28
+ EOSQL
28
29
 
29
- host.connection.execute <<-eosql
30
+ host.connection.execute <<-EOSQL
30
31
  CREATE VIEW #{host.table_name} AS
31
32
  select * from some_table;
32
- eosql
33
+ EOSQL
33
34
  end
34
35
  end
35
36
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Helpers
2
3
  def stub_metadata(additional_metadata)
3
4
  stub_metadata = metadata_with(additional_metadata)
@@ -1,7 +1,8 @@
1
- RSpec::Matchers::define :be_included_in_files_in do |path|
1
+ # frozen_string_literal: true
2
+ RSpec::Matchers.define :be_included_in_files_in do |path|
2
3
  match do |mod|
3
4
  stub_metadata(
4
- :example_group => {:file_path => "#{path}whatever_spec.rb:15"}
5
+ :example_group => { :file_path => "#{path}whatever_spec.rb:15" }
5
6
  )
6
7
  group = RSpec::Core::ExampleGroup.describe
7
8
  group.included_modules.include?(mod)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Minitest requires you provide an assertions ivar for the context
2
3
  # it is running within. We need this so that ActiveModel::Lint tests
3
4
  # can successfully be run.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class NullObject
2
3
  private
3
4
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-activemodel-mocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
8
8
  - Andy Lindeman
9
9
  - Thomas Holmes
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain:
13
13
  - |
@@ -45,10 +45,10 @@ cert_chain:
45
45
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
46
46
  F3MdtaDehhjC
47
47
  -----END CERTIFICATE-----
48
- date: 2018-09-17 00:00:00.000000000 Z
48
+ date: 2024-10-02 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
- name: activesupport
51
+ name: activemodel
52
52
  requirement: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
@@ -62,7 +62,7 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: '3.0'
64
64
  - !ruby/object:Gem::Dependency
65
- name: activemodel
65
+ name: activesupport
66
66
  requirement: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
@@ -95,76 +95,6 @@ dependencies:
95
95
  - - "<"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '4.0'
98
- - !ruby/object:Gem::Dependency
99
- name: rake
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: 10.0.0
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: 10.0.0
112
- - !ruby/object:Gem::Dependency
113
- name: cucumber
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: 1.3.5
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: 1.3.5
126
- - !ruby/object:Gem::Dependency
127
- name: aruba
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "~>"
131
- - !ruby/object:Gem::Version
132
- version: 0.4.11
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: 0.4.11
140
- - !ruby/object:Gem::Dependency
141
- name: ZenTest
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - "~>"
145
- - !ruby/object:Gem::Version
146
- version: 4.9.5
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - "~>"
152
- - !ruby/object:Gem::Version
153
- version: 4.9.5
154
- - !ruby/object:Gem::Dependency
155
- name: activerecord
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: '3.0'
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: '3.0'
168
98
  description: RSpec test doubles for ActiveModel and ActiveRecord
169
99
  email: rspec@googlegroups.com
170
100
  executables: []
@@ -177,7 +107,6 @@ files:
177
107
  - features/mocks/mock_model.feature
178
108
  - features/mocks/stub_model.feature
179
109
  - features/step_definitions/additional_cli_steps.rb
180
- - features/step_definitions/model_steps.rb
181
110
  - features/support/env.rb
182
111
  - features/support/rubinius.rb
183
112
  - lib/rspec-activemodel-mocks.rb
@@ -195,8 +124,13 @@ files:
195
124
  homepage: https://github.com/rspec/rspec-activemodel-mocks
196
125
  licenses:
197
126
  - MIT
198
- metadata: {}
199
- post_install_message:
127
+ metadata:
128
+ bug_tracker_uri: https://github.com/rspec/rspec-activemodel-mocks/issues
129
+ documentation_uri: https://rspec.info/documentation/
130
+ mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
131
+ source_code_uri: https://github.com/rspec/rspec-activemodel-mocks
132
+ rubygems_mfa_required: 'true'
133
+ post_install_message:
200
134
  rdoc_options:
201
135
  - "--charset=UTF-8"
202
136
  require_paths:
@@ -212,16 +146,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
146
  - !ruby/object:Gem::Version
213
147
  version: '0'
214
148
  requirements: []
215
- rubyforge_project:
216
- rubygems_version: 2.7.6
217
- signing_key:
149
+ rubygems_version: 3.5.16
150
+ signing_key:
218
151
  specification_version: 4
219
- summary: rspec-activemodel-mocks-1.1.0
152
+ summary: rspec-activemodel-mocks-1.2.1
220
153
  test_files:
221
154
  - features/mocks/mock_model.feature
222
155
  - features/mocks/stub_model.feature
223
156
  - features/step_definitions/additional_cli_steps.rb
224
- - features/step_definitions/model_steps.rb
225
157
  - features/support/env.rb
226
158
  - features/support/rubinius.rb
227
159
  - spec/rspec/active_model/mocks/mock_model_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,3 +0,0 @@
1
- Given /a (\w+) model/ do |model_class_name|
2
- puts eval(model_class_name)
3
- end