with_model 2.1.6 → 2.2.0

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: b6da93806455c916606077722ee10e9e5f0fd4ec785471288d210949b3891507
4
- data.tar.gz: dad3a97b161ccb4d1256402eb7ebffd6746db155094dbd2341e2d860428f9437
3
+ metadata.gz: 809e5984c60e2fa27b71d3d3ce7664feae0a3b2c7a59f345e2a94a819affb623
4
+ data.tar.gz: 5e8b519ef7d338aa754755efd065af68b718e6dc1f96fe27632266752e7b4990
5
5
  SHA512:
6
- metadata.gz: 4f83311c48f5472bd2e3f0d00ddb58fedd14de54d483c06ac1594fdfb26c7344174eb92e3dd28593a4b99b582b5872f3a92941a681a2116e244625f18fa4759d
7
- data.tar.gz: fc9044c0f5e92d9ec0351d3ce912df3cdc3bc4aeddb238ec7d1258f6e63620c3caaaaa65ebf79ce639c2fa9aea2dcb44b098fa57b421d96483e825ad047ae57f
6
+ metadata.gz: cf09e4aabe724638f054a54199d62a61ae9efd0cca28485412f85fd082a99f104d4f538bd7041f1777c9380398e7d1497d5f01dcc07cb5fdacc116ad3e7dd69f
7
+ data.tar.gz: 6f795b756e9b33abd148d51010a0afb80e01660af35c76d1a98a634c6b2d31c38a616e94aeff99c6d8b19b019c69b994c9b5dc21e69439fbbcb004528dc3606b
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_BIN: bin
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "10:00"
8
+ open-pull-requests-limit: 10
@@ -6,8 +6,6 @@ on:
6
6
  - master
7
7
  - github-actions
8
8
  pull_request:
9
- branches:
10
- - master
11
9
 
12
10
  jobs:
13
11
  test:
@@ -17,39 +15,35 @@ jobs:
17
15
  strategy:
18
16
  fail-fast: false
19
17
  matrix:
20
- ruby-version: ['2.6', '2.7', '3.0', '3.1']
18
+ ruby-version: ['3.1', '3.2', '3.3', '3.4']
21
19
  active-record-version-env:
22
- - ACTIVE_RECORD_VERSION="~> 5.2.0"
23
- - ACTIVE_RECORD_VERSION="~> 6.0.0"
24
- - ACTIVE_RECORD_VERSION="~> 6.1.0"
25
20
  - ACTIVE_RECORD_VERSION="~> 7.0.0"
21
+ - ACTIVE_RECORD_VERSION="~> 7.1.0"
22
+ - ACTIVE_RECORD_VERSION="~> 7.2.0"
23
+ - ACTIVE_RECORD_VERSION="~> 8.0.0"
26
24
  allow-failure: [false]
27
- include:
25
+ exclude:
28
26
  - ruby-version: '3.1'
29
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.0.0"
27
+ active-record-version-env: ACTIVE_RECORD_VERSION="~> 8.0.0"
28
+ include:
29
+ - ruby-version: '3.4'
30
+ active-record-version-env: ACTIVE_RECORD_BRANCH="main"
30
31
  allow-failure: true
31
- - ruby-version: '3.1'
32
- active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
32
+ - ruby-version: '3.4'
33
+ active-record-version-env: ACTIVE_RECORD_BRANCH="8-0-stable"
33
34
  allow-failure: true
34
- - ruby-version: '3.1'
35
- active-record-version-env: ACTIVE_RECORD_BRANCH="6-1-stable"
35
+ - ruby-version: '3.4'
36
+ active-record-version-env: ACTIVE_RECORD_BRANCH="7-2-stable"
37
+ allow-failure: true
38
+ - ruby-version: '3.4'
39
+ active-record-version-env: ACTIVE_RECORD_BRANCH="7-1-stable"
40
+ allow-failure: true
41
+ - ruby-version: '3.4'
42
+ active-record-version-env: ACTIVE_RECORD_BRANCH="7-0-stable"
36
43
  allow-failure: true
37
- exclude:
38
- - ruby-version: '3.0'
39
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
40
- allow-failure: false
41
- - ruby-version: '3.1'
42
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 5.2.0"
43
- allow-failure: false
44
- - ruby-version: '2.6'
45
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.0.0"
46
- allow-failure: false
47
- - ruby-version: '3.1'
48
- active-record-version-env: ACTIVE_RECORD_VERSION="~> 7.0.0"
49
- allow-failure: false
50
44
  continue-on-error: ${{ matrix.allow-failure }}
51
45
  steps:
52
- - uses: actions/checkout@v2
46
+ - uses: actions/checkout@v3
53
47
  - name: Set up Ruby
54
48
  uses: ruby/setup-ruby@v1
55
49
  with:
@@ -58,4 +52,4 @@ jobs:
58
52
  - name: Update bundle
59
53
  run: ${{ matrix.active-record-version-env }} bundle update
60
54
  - name: Run tests
61
- run: ${{ matrix.active-record-version-env }} bundle exec rake
55
+ run: ${{ matrix.active-record-version-env }} bin/rake
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .yardoc
2
2
  Gemfile.lock
3
3
  coverage
4
+ bin/
4
5
  doc/
5
6
  pkg
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --color
2
2
  --format documentation
3
- --order default
3
+ --order defined
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 2.2.0
2
+
3
+ - Fix dependency tracking issue when `cache_classes: true` is set in Rails 7+.
4
+ - Create table in same database as `superclass` (Joe Lind)
5
+ - Switch to standard instead of rubocop for linting.
6
+ - Add support for Active Record 7 and 8.
7
+ - Require Active Record 7 or later.
8
+ - Add support for Ruby 3.3.
9
+ - Require Ruby 3.1 or later.
10
+
11
+ ### 2.1.7
12
+ - Require Ruby 2.7 or later
13
+ - Add Ruby 3.2 support
14
+ - Require Active Record 6.0 or later
15
+ - Improve minitest support (Mark Edmondson)
16
+ - Limit scope when clearing descendants tracker (idea from Jean-Baptiste Jacquinot)
17
+
1
18
  ### 2.1.6
2
19
  - Require Ruby 2.6 or later
3
20
  - Add Ruby 3.0 and 3.1 support
data/Gemfile CHANGED
@@ -1,24 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- ar_branch = ENV['ACTIVE_RECORD_BRANCH']
8
- ar_version = ENV['ACTIVE_RECORD_VERSION']
9
- is_jruby = RUBY_PLATFORM == 'java'
7
+ ar_branch = ENV.fetch("ACTIVE_RECORD_BRANCH", nil)
8
+ ar_version = ENV.fetch("ACTIVE_RECORD_VERSION", nil)
10
9
 
11
10
  if ar_branch
12
- gem 'activerecord', git: 'https://github.com/rails/rails.git', branch: ar_branch
13
- if ar_branch == 'master'
14
- gem 'arel', git: 'https://github.com/rails/arel.git'
15
- gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter.git' if is_jruby
16
- end
11
+ gem "activerecord", git: "https://github.com/rails/rails.git", branch: ar_branch
12
+ gem "arel", git: "https://github.com/rails/arel.git" if ar_branch == "master"
17
13
  elsif ar_version
18
- gem 'activerecord', ar_version
19
- if is_jruby && !Gem::Requirement.new(ar_version).satisfied_by?(Gem::Version.new('5.2.0'))
20
- gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter.git'
21
- end
14
+ gem "activerecord", ar_version
22
15
  end
23
16
 
24
- gem 'sqlite3', '~> 1.4.1' unless is_jruby
17
+ gem "bigdecimal"
18
+ gem "bundler"
19
+ gem "debug"
20
+ gem "logger"
21
+ gem "minitest"
22
+ gem "mutex_m"
23
+ gem "rake"
24
+ gem "rspec"
25
+ gem "standard"
26
+
27
+ if ar_branch == "7-0-stable" || ar_version == "~> 7.0.0"
28
+ gem "sqlite3", "< 2"
29
+ else
30
+ gem "sqlite3"
31
+ end
data/Rakefile CHANGED
@@ -1,30 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
- require 'rake/testtask'
6
- require 'rubocop/rake_task'
3
+ require "bundler/gem_tasks"
7
4
 
8
- desc 'Run specs'
9
- RSpec::Core::RakeTask.new(:spec) do |t|
10
- t.pattern = Dir.glob('spec/**/*_spec.rb')
11
- end
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new
12
7
 
13
- desc 'Run tests'
14
- Rake::TestTask.new(:test) do |t|
15
- t.libs << 'test'
16
- t.libs << 'lib'
17
- t.pattern = 'test/**/*_test.rb'
18
- end
8
+ require "minitest/test_task"
9
+ Minitest::TestTask.create
19
10
 
20
- desc 'Run lint'
21
- RuboCop::RakeTask.new
11
+ # standard rake task
12
+ require "standard/rake"
22
13
 
23
- namespace 'doc' do
24
- desc 'Generate README and preview in browser'
25
- task 'readme' do
26
- sh 'markdown README.md > README.html && open README.html'
27
- end
28
- end
29
-
30
- task default: %i[spec test rubocop]
14
+ task default: %i[spec test standard]
@@ -37,7 +37,7 @@ module WithModel
37
37
  end
38
38
 
39
39
  def lookup_list
40
- @const_name.to_s.split('::')
40
+ @const_name.to_s.split("::")
41
41
  end
42
42
 
43
43
  def basename
@@ -0,0 +1,87 @@
1
+ require "active_support/descendants_tracker"
2
+
3
+ module WithModel
4
+ # Based on https://github.com/rails/rails/blob/491afff27e2dd3d5f301b478b9a43d3c31709af8/activesupport/lib/active_support/descendants_tracker.rb
5
+ module DescendantsTracker
6
+ if RUBY_ENGINE == "ruby"
7
+ # On MRI `ObjectSpace::WeakMap` keys are weak references.
8
+ # So we can simply use WeakMap as a `Set`.
9
+ class WeakSet < ObjectSpace::WeakMap # :nodoc:
10
+ alias_method :to_a, :keys
11
+
12
+ def <<(object)
13
+ self[object] = true
14
+ end
15
+ end
16
+ else
17
+ # On TruffleRuby `ObjectSpace::WeakMap` keys are strong references.
18
+ # So we use `object_id` as a key and the actual object as a value.
19
+ #
20
+ # JRuby for now doesn't have Class#descendant, but when it will, it will likely
21
+ # have the same WeakMap semantic than Truffle so we future proof this as much as possible.
22
+ class WeakSet # :nodoc:
23
+ def initialize
24
+ @map = ObjectSpace::WeakMap.new
25
+ end
26
+
27
+ def [](object)
28
+ @map.key?(object.object_id)
29
+ end
30
+ alias_method :include?, :[]
31
+
32
+ def []=(object, _present)
33
+ @map[object.object_id] = object
34
+ end
35
+
36
+ def to_a
37
+ @map.values
38
+ end
39
+
40
+ def <<(object)
41
+ self[object] = true
42
+ end
43
+ end
44
+ end
45
+ @excluded_descendants = WeakSet.new
46
+
47
+ class << self
48
+ def clear(classes) # :nodoc:
49
+ classes.each do |klass|
50
+ @excluded_descendants << klass
51
+ klass.descendants.each do |descendant|
52
+ @excluded_descendants << descendant
53
+ end
54
+ end
55
+ end
56
+
57
+ def reject!(classes) # :nodoc:
58
+ if @excluded_descendants
59
+ classes.reject! { |d| @excluded_descendants.include?(d) }
60
+ end
61
+ classes
62
+ end
63
+ end
64
+
65
+ module DestroyedClassesFiltering
66
+ def subclasses
67
+ WithModel::DescendantsTracker.reject!(super)
68
+ end
69
+
70
+ def descendants
71
+ WithModel::DescendantsTracker.reject!(super)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ class ActiveRecord::Base
78
+ extend WithModel::DescendantsTracker::DestroyedClassesFiltering
79
+ end
80
+
81
+ module ActiveSupport
82
+ module DescendantsTracker
83
+ class << self
84
+ attr_reader :clear_disabled
85
+ end
86
+ end
87
+ end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
4
- require 'active_support/core_ext/string/inflections'
5
- require 'English'
6
- require 'with_model/constant_stubber'
7
- require 'with_model/methods'
8
- require 'with_model/table'
3
+ require "logger"
4
+ require "active_record"
5
+ require "active_support/core_ext/string/inflections"
6
+ require "English"
7
+ require "with_model/constant_stubber"
8
+ require "with_model/descendants_tracker"
9
+ require "with_model/methods"
10
+ require "with_model/table"
9
11
 
10
12
  module WithModel
11
13
  # In general, direct use of this class should be avoided. Instead use
@@ -38,6 +40,7 @@ module WithModel
38
40
  cleanup_descendants_tracking
39
41
  reset_dependencies_cache
40
42
  table.destroy
43
+ WithModel::DescendantsTracker.clear([@model])
41
44
  @model = nil
42
45
  end
43
46
 
@@ -54,15 +57,8 @@ module WithModel
54
57
  end
55
58
 
56
59
  def cleanup_descendants_tracking
57
- if defined?(ActiveSupport::DescendantsTracker)
58
- if ActiveSupport::VERSION::MAJOR >= 7
59
- ActiveSupport::DescendantsTracker.clear([ActiveRecord::Base])
60
- else
61
- ActiveSupport::DescendantsTracker.class_variable_get(:@@direct_descendants).delete(ActiveRecord::Base)
62
- end
63
- elsif @model.superclass.respond_to?(:direct_descendants)
64
- @model.superclass.direct_descendants.delete(@model)
65
- end
60
+ ActiveSupport::DescendantsTracker.clear([@model]) \
61
+ unless ActiveSupport::DescendantsTracker.clear_disabled
66
62
  end
67
63
 
68
64
  def reset_dependencies_cache
@@ -76,7 +72,7 @@ module WithModel
76
72
  end
77
73
 
78
74
  def table
79
- @table ||= Table.new table_name, @table_options, &@table_block
75
+ @table ||= Table.new table_name, @table_options, connection: @superclass.connection, &@table_block
80
76
  end
81
77
 
82
78
  def table_name
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
3
+ require "active_record"
4
4
 
5
5
  module WithModel
6
6
  # In general, direct use of this class should be avoided. Instead use
@@ -8,12 +8,14 @@ module WithModel
8
8
  class Table
9
9
  # @param [Symbol] name The name of the table to create.
10
10
  # @param options Passed to ActiveRecord `create_table`.
11
+ # @param connection The connection to use for creating the table.
11
12
  # @param block Passed to ActiveRecord `create_table`.
12
13
  # @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-create_table
13
- def initialize(name, options = {}, &block)
14
+ def initialize(name, options = {}, connection: ActiveRecord::Base.connection, &block)
14
15
  @name = name.freeze
15
16
  @options = options.freeze
16
17
  @block = block
18
+ @connection = connection
17
19
  end
18
20
 
19
21
  # Creates the table with the initialized options. Drops the table if
@@ -29,6 +31,8 @@ module WithModel
29
31
 
30
32
  private
31
33
 
34
+ attr_reader :connection
35
+
32
36
  def exists?
33
37
  if connection.respond_to?(:data_source_exists?)
34
38
  connection.data_source_exists?(@name)
@@ -36,9 +40,5 @@ module WithModel
36
40
  connection.table_exists?(@name)
37
41
  end
38
42
  end
39
-
40
- def connection
41
- ActiveRecord::Base.connection
42
- end
43
43
  end
44
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WithModel
4
- VERSION = '2.1.6'
4
+ VERSION = "2.2.0"
5
5
  end
data/lib/with_model.rb CHANGED
@@ -1,11 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'with_model/model'
4
- require 'with_model/model/dsl'
5
- require 'with_model/table'
6
- require 'with_model/version'
3
+ require "with_model/model"
4
+ require "with_model/model/dsl"
5
+ require "with_model/table"
6
+ require "with_model/version"
7
7
 
8
8
  module WithModel
9
+ class MiniTestLifeCycle < Module
10
+ def initialize(object)
11
+ define_method :before_setup do
12
+ object.create
13
+ super() if defined?(super)
14
+ end
15
+
16
+ define_method :after_teardown do
17
+ object.destroy
18
+ super() if defined?(super)
19
+ end
20
+ end
21
+
22
+ def self.call(object)
23
+ new(object)
24
+ end
25
+ end
26
+
9
27
  class << self
10
28
  attr_writer :runner
11
29
  end
@@ -42,7 +60,8 @@ module WithModel
42
60
 
43
61
  # @param [Object] object The new model object instance to create
44
62
  # @param scope Passed to `before`/`after` in the test context. Rspec only.
45
- def setup_object(object, scope: nil, runner: nil) # rubocop:disable Metrics/MethodLength
63
+ # @param [Symbol] runner The test running, either :rspec or :minitest, defaults to :rspec
64
+ def setup_object(object, scope: nil, runner: nil)
46
65
  case runner || WithModel.runner
47
66
  when :rspec
48
67
  before(*scope) do
@@ -53,13 +72,11 @@ module WithModel
53
72
  object.destroy
54
73
  end
55
74
  when :minitest
56
- object.create
57
-
58
- Minitest.after_run do
59
- object.destroy
75
+ class_eval do
76
+ include MiniTestLifeCycle.call(object)
60
77
  end
61
78
  else
62
- raise ArgumentError, 'Unsupported test runner set, expected :rspec or :minitest'
79
+ raise ArgumentError, "Unsupported test runner set, expected :rspec or :minitest"
63
80
  end
64
81
  end
65
82
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
- describe 'ActiveRecord behaviors' do
6
- describe 'a temporary ActiveRecord model created with with_model' do
7
- context 'that has a named scope' do
5
+ describe "ActiveRecord behaviors" do
6
+ describe "a temporary ActiveRecord model created with with_model" do
7
+ context "that has a named scope" do
8
8
  before do
9
9
  @regular_model = Class.new ActiveRecord::Base do
10
- self.table_name = 'regular_models'
11
- scope :title_is_foo, -> { where(title: 'foo') }
10
+ self.table_name = "regular_models"
11
+ scope :title_is_foo, -> { where(title: "foo") }
12
12
  end
13
13
 
14
14
  @regular_model.connection.create_table(@regular_model.table_name, force: true) do |t|
15
- t.string 'title'
16
- t.text 'content'
15
+ t.string "title"
16
+ t.text "content"
17
17
  t.timestamps null: false
18
18
  end
19
19
  end
@@ -24,37 +24,37 @@ describe 'ActiveRecord behaviors' do
24
24
 
25
25
  with_model :BlogPost do
26
26
  table do |t|
27
- t.string 'title'
28
- t.text 'content'
27
+ t.string "title"
28
+ t.text "content"
29
29
  t.timestamps null: false
30
30
  end
31
31
 
32
32
  model do
33
- scope :title_is_foo, -> { where(title: 'foo') }
33
+ scope :title_is_foo, -> { where(title: "foo") }
34
34
  end
35
35
  end
36
36
 
37
- describe 'the named scope' do
38
- it 'works like a regular named scope' do
39
- included = @regular_model.create!(title: 'foo', content: 'Include me!')
40
- @regular_model.create!(title: 'bar', content: 'Include me!')
37
+ describe "the named scope" do
38
+ it "works like a regular named scope" do
39
+ included = @regular_model.create!(title: "foo", content: "Include me!")
40
+ @regular_model.create!(title: "bar", content: "Include me!")
41
41
 
42
42
  expect(@regular_model.title_is_foo).to eq [included]
43
43
 
44
- included = BlogPost.create!(title: 'foo', content: 'Include me!')
45
- BlogPost.create!(title: 'bar', content: 'Include me!')
44
+ included = BlogPost.create!(title: "foo", content: "Include me!")
45
+ BlogPost.create!(title: "bar", content: "Include me!")
46
46
 
47
47
  expect(BlogPost.title_is_foo).to eq [included]
48
48
  end
49
49
  end
50
50
  end
51
51
 
52
- context 'that has a polymorphic belongs_to' do
52
+ context "that has a polymorphic belongs_to" do
53
53
  before do
54
54
  animal = Class.new ActiveRecord::Base do
55
55
  has_many :tea_cups, as: :pet
56
56
  end
57
- stub_const 'Animal', animal
57
+ stub_const "Animal", animal
58
58
  end
59
59
 
60
60
  with_model :TeaCup do
@@ -74,24 +74,24 @@ describe 'ActiveRecord behaviors' do
74
74
  end
75
75
  end
76
76
 
77
- describe 'the polymorphic belongs_to' do
78
- it 'works like a regular polymorphic belongs_to' do
77
+ describe "the polymorphic belongs_to" do
78
+ it "works like a regular polymorphic belongs_to" do
79
79
  animal = Animal.create!
80
80
  stuffed_animal = StuffedAnimal.create!
81
81
 
82
82
  tea_cup_for_animal = TeaCup.create!(pet: animal)
83
- expect(tea_cup_for_animal.pet_type).to eq 'Animal'
83
+ expect(tea_cup_for_animal.pet_type).to eq "Animal"
84
84
  expect(animal.tea_cups).to include(tea_cup_for_animal)
85
85
 
86
86
  tea_cup_for_stuffed_animal = TeaCup.create!(pet: stuffed_animal)
87
- expect(tea_cup_for_stuffed_animal.pet_type).to eq 'StuffedAnimal'
87
+ expect(tea_cup_for_stuffed_animal.pet_type).to eq "StuffedAnimal"
88
88
  expect(stuffed_animal.tea_cups).to include(tea_cup_for_stuffed_animal)
89
89
  end
90
90
  end
91
91
  end
92
92
  end
93
93
 
94
- context 'with an association' do
94
+ context "with an association" do
95
95
  with_model :Province do
96
96
  table do |t|
97
97
  t.belongs_to :country
@@ -103,13 +103,13 @@ describe 'ActiveRecord behaviors' do
103
103
 
104
104
  with_model :Country
105
105
 
106
- context 'in earlier examples' do
107
- it 'works as normal' do
108
- Province.create!(country: Country.create!)
106
+ context "in earlier examples" do
107
+ it "works as normal" do
108
+ expect { Province.create!(country: Country.create!) }.not_to raise_error
109
109
  end
110
110
  end
111
111
 
112
- context 'in later examples' do
112
+ context "in later examples" do
113
113
  it "does not hold a reference to earlier example groups' classes" do
114
114
  expect(Province.reflect_on_association(:country).klass).to eq Country
115
115
  end
@@ -1,19 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  module WithModel
6
6
  describe ConstantStubber do
7
- it 'allows calling unstub_const multiple times' do
8
- stubber = described_class.new('Foo')
7
+ it "allows calling unstub_const multiple times" do
8
+ stubber = described_class.new("Foo")
9
9
  stubber.stub_const(1)
10
- stubber.unstub_const
11
- stubber.unstub_const
10
+ expect { 2.times { stubber.unstub_const } }.not_to raise_error
12
11
  end
13
12
 
14
- it 'allows calling unstub_const without stub_const' do
15
- stubber = described_class.new('Foo')
16
- stubber.unstub_const
13
+ it "allows calling unstub_const without stub_const" do
14
+ stubber = described_class.new("Foo")
15
+ expect { stubber.unstub_const }.not_to raise_error
17
16
  end
18
17
  end
19
18
  end