mocha 2.8.2 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +37 -3
  3. data/.rubocop_todo.yml +25 -13
  4. data/.yardopts +2 -0
  5. data/Gemfile +10 -28
  6. data/README.md +5 -6
  7. data/RELEASE.md +80 -4
  8. data/Rakefile +65 -24
  9. data/gemfiles/Gemfile.minitest.latest +3 -3
  10. data/gemfiles/Gemfile.rubocop +9 -0
  11. data/gemfiles/Gemfile.test-unit.latest +3 -3
  12. data/lib/mocha/any_instance_method.rb +6 -4
  13. data/lib/mocha/any_instance_receiver.rb +20 -0
  14. data/lib/mocha/api.rb +4 -2
  15. data/lib/mocha/argument_iterator.rb +5 -5
  16. data/lib/mocha/backtrace_filter.rb +2 -0
  17. data/lib/mocha/{block_matcher.rb → block_matchers.rb} +2 -0
  18. data/lib/mocha/cardinality.rb +2 -2
  19. data/lib/mocha/central.rb +4 -0
  20. data/lib/mocha/change_state_side_effect.rb +2 -0
  21. data/lib/mocha/class_methods.rb +14 -9
  22. data/lib/mocha/configuration.rb +18 -41
  23. data/lib/mocha/default_name.rb +15 -0
  24. data/lib/mocha/default_receiver.rb +13 -0
  25. data/lib/mocha/deprecation.rb +15 -9
  26. data/lib/mocha/detection/minitest.rb +2 -0
  27. data/lib/mocha/detection/test_unit.rb +4 -1
  28. data/lib/mocha/error_with_filtered_backtrace.rb +2 -0
  29. data/lib/mocha/exception_raiser.rb +3 -0
  30. data/lib/mocha/expectation.rb +57 -23
  31. data/lib/mocha/expectation_error.rb +2 -0
  32. data/lib/mocha/expectation_error_factory.rb +2 -0
  33. data/lib/mocha/expectation_list.rb +3 -1
  34. data/lib/mocha/hooks.rb +11 -4
  35. data/lib/mocha/ignoring_warning.rb +20 -0
  36. data/lib/mocha/impersonating_any_instance_name.rb +13 -0
  37. data/lib/mocha/impersonating_name.rb +13 -0
  38. data/lib/mocha/in_state_ordering_constraint.rb +2 -0
  39. data/lib/mocha/inspect.rb +13 -10
  40. data/lib/mocha/instance_method.rb +6 -4
  41. data/lib/mocha/integration/assertion_counter.rb +2 -0
  42. data/lib/mocha/integration/minitest/adapter.rb +8 -6
  43. data/lib/mocha/integration/minitest.rb +5 -4
  44. data/lib/mocha/integration/monkey_patcher.rb +4 -2
  45. data/lib/mocha/integration/test_unit/adapter.rb +10 -4
  46. data/lib/mocha/integration/test_unit.rb +5 -4
  47. data/lib/mocha/integration.rb +5 -0
  48. data/lib/mocha/invocation.rb +9 -6
  49. data/lib/mocha/logger.rb +2 -0
  50. data/lib/mocha/macos_version.rb +2 -0
  51. data/lib/mocha/method_matcher.rb +2 -0
  52. data/lib/mocha/minitest.rb +2 -1
  53. data/lib/mocha/mock.rb +16 -12
  54. data/lib/mocha/mockery.rb +35 -17
  55. data/lib/mocha/name.rb +13 -0
  56. data/lib/mocha/not_initialized_error.rb +2 -0
  57. data/lib/mocha/object_methods.rb +20 -6
  58. data/lib/mocha/object_receiver.rb +20 -0
  59. data/lib/mocha/parameter_matchers/all_of.rb +3 -6
  60. data/lib/mocha/parameter_matchers/any_of.rb +3 -6
  61. data/lib/mocha/parameter_matchers/any_parameters.rb +3 -6
  62. data/lib/mocha/parameter_matchers/anything.rb +3 -6
  63. data/lib/mocha/parameter_matchers/{base.rb → base_methods.rb} +2 -18
  64. data/lib/mocha/parameter_matchers/equals.rb +3 -6
  65. data/lib/mocha/parameter_matchers/equivalent_uri.rb +9 -10
  66. data/lib/mocha/parameter_matchers/has_entries.rb +4 -7
  67. data/lib/mocha/parameter_matchers/has_entry.rb +5 -7
  68. data/lib/mocha/parameter_matchers/has_key.rb +5 -7
  69. data/lib/mocha/parameter_matchers/has_keys.rb +5 -8
  70. data/lib/mocha/parameter_matchers/has_value.rb +5 -7
  71. data/lib/mocha/parameter_matchers/includes.rb +6 -12
  72. data/lib/mocha/parameter_matchers/instance_methods.rb +5 -3
  73. data/lib/mocha/parameter_matchers/instance_of.rb +3 -6
  74. data/lib/mocha/parameter_matchers/is_a.rb +4 -7
  75. data/lib/mocha/parameter_matchers/kind_of.rb +3 -6
  76. data/lib/mocha/parameter_matchers/not.rb +3 -6
  77. data/lib/mocha/parameter_matchers/optionally.rb +2 -5
  78. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +39 -19
  79. data/lib/mocha/parameter_matchers/regexp_matches.rb +4 -6
  80. data/lib/mocha/parameter_matchers/responds_with.rb +3 -6
  81. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +3 -6
  82. data/lib/mocha/parameter_matchers.rb +2 -1
  83. data/lib/mocha/parameters_matcher.rb +9 -1
  84. data/lib/mocha/raised_exception.rb +2 -0
  85. data/lib/mocha/return_values.rb +2 -0
  86. data/lib/mocha/ruby_version.rb +3 -0
  87. data/lib/mocha/sequence.rb +2 -0
  88. data/lib/mocha/single_return_value.rb +1 -1
  89. data/lib/mocha/state_machine.rb +3 -1
  90. data/lib/mocha/stubbed_method.rb +17 -9
  91. data/lib/mocha/stubbing_error.rb +2 -0
  92. data/lib/mocha/test_unit.rb +2 -1
  93. data/lib/mocha/thrower.rb +2 -0
  94. data/lib/mocha/thrown_object.rb +2 -0
  95. data/lib/mocha/version.rb +3 -1
  96. data/lib/mocha/yield_parameters.rb +2 -0
  97. data/lib/mocha.rb +20 -0
  98. data/mise.toml +2 -0
  99. data/mocha.gemspec +10 -4
  100. metadata +21 -17
  101. data/lib/mocha/debug.rb +0 -9
  102. data/lib/mocha/integration/minitest/exception_translation.rb +0 -14
  103. data/lib/mocha/is_a.rb +0 -7
  104. data/lib/mocha/names.rb +0 -43
  105. data/lib/mocha/parameter_matchers/deprecations.rb +0 -44
  106. data/lib/mocha/receivers.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9b6824de22258fd93ce5b15925529aa65d031f13c6498c5816ef922e55177ac
4
- data.tar.gz: 8b9b87a21403c0b478dd1d8827401684d13b43c761acb3d3ade545bb620c851a
3
+ metadata.gz: 44d35f56fc0395b34a514c91a44a914ac782a500a4426db9e7c00aea8ae66c96
4
+ data.tar.gz: 2be9168ce81c71de23b3ba15593184274098938bdad1108226231c3a70fdb172
5
5
  SHA512:
6
- metadata.gz: 5162913f48075d311d6630d69ed3e1aa1d9bdcf1e260b88dd7e1e0ddffdca4c2a26c544cb38b5bad0750d3c44df50dc23cdad00e2915fb7e3c298dd645c1a9be
7
- data.tar.gz: 6c914b616fef69f33643a50d86f2593e495ede30a2887122df2d84dbfc1ae4d9bfcd4bdc073821d57dbe92e174f6907e7c59e68ea9eb948e33b278c561251ca0
6
+ metadata.gz: d2fe09345542097c73fdc4594ed43d6d737b5927dd29672b79e1d94fce9550ab580c38d0855524eb193eed9b7969078e6e2ad62f11a78156e48288d27b907c78
7
+ data.tar.gz: f17bfeb0fdc2ba83a65e69f515094c00da41b25de979b5bd75767b235fd9cc0e086673a7807d0b895474792a4760e81283b3bc0ba980e67899870f84c9dd638c
data/.rubocop.yml CHANGED
@@ -1,7 +1,22 @@
1
+ plugins:
2
+ - rubocop-rake
3
+
1
4
  inherit_from: .rubocop_todo.yml
2
5
 
6
+ inherit_mode:
7
+ merge:
8
+ - Include
9
+
3
10
  AllCops:
4
- TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 2.1'
11
+ TargetRubyVersion: 2.2
12
+
13
+ Include:
14
+ - "**/Gemfile.*"
15
+
16
+ Exclude:
17
+ - "**/Gemfile*.lock"
18
+
19
+ NewCops: enable
5
20
 
6
21
  # Even the reference in the documentation suggests that you should prefer
7
22
  # `alias_method` vs `alias`, so I don't understand why that isn't the default.
@@ -50,9 +65,28 @@ Layout/AccessModifierIndentation:
50
65
  Enabled: false
51
66
 
52
67
  # Allow long comment lines, e.g. YARD documentation
53
- Metrics/LineLength:
54
- IgnoredPatterns: ['\A\s*#']
68
+ Layout/LineLength:
69
+ AllowedPatterns: ['\A\s*#']
55
70
 
56
71
  # It's not possible to set TargetRubyVersion to Ruby < v2.2
57
72
  Gemspec/RequiredRubyVersion:
58
73
  Enabled: false
74
+
75
+ # This cop is useful for required environment variables, but not for optional ones
76
+ Style/FetchEnvVar:
77
+ AllowedVars:
78
+ - MOCHA_RUN_INTEGRATION_TESTS
79
+
80
+ Naming/FileName:
81
+ ExpectMatchingDefinition: true
82
+ Exclude:
83
+ - lib/mocha/version.rb
84
+ - lib/mocha/minitest.rb
85
+ - lib/mocha/test_unit.rb
86
+ - lib/mocha/ruby_version.rb
87
+ - lib/mocha/macos_version.rb
88
+ - test/test_helper.rb
89
+
90
+ Metrics/BlockLength:
91
+ Exclude:
92
+ - "Rakefile"
data/.rubocop_todo.yml CHANGED
@@ -1,27 +1,39 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-11-16 18:15:36 +0000 using RuboCop version 0.58.2.
3
+ # on 2025-01-03 14:37:32 UTC using RuboCop version 1.69.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 57
9
+ # Offense count: 34
10
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
10
11
  Metrics/AbcSize:
11
- Max: 26
12
+ Max: 27
12
13
 
13
- # Offense count: 23
14
- # Configuration parameters: CountComments.
14
+ # Offense count: 28
15
+ # Configuration parameters: CountComments, CountAsOne.
15
16
  Metrics/ClassLength:
16
- Max: 366
17
+ Max: 381
17
18
 
18
- # Offense count: 172
19
- # Configuration parameters: CountComments.
19
+ # Offense count: 2
20
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 9
23
+
24
+ # Offense count: 200
25
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
20
26
  Metrics/MethodLength:
21
- Max: 31
27
+ Max: 27
28
+
29
+ # Offense count: 3
30
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
31
+ Metrics/PerceivedComplexity:
32
+ Max: 10
22
33
 
23
- # Offense count: 545
24
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
34
+ # Offense count: 68
35
+ # This cop supports safe autocorrection (--autocorrect).
36
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
25
37
  # URISchemes: http, https
26
- Metrics/LineLength:
27
- Max: 180
38
+ Layout/LineLength:
39
+ Max: 173
data/.yardopts CHANGED
@@ -1,5 +1,6 @@
1
1
  --output-dir docs
2
2
  --no-private
3
+ lib/mocha.rb
3
4
  lib/mocha/api.rb
4
5
  lib/mocha/hooks.rb
5
6
  lib/mocha/mock.rb
@@ -15,6 +16,7 @@ lib/mocha/expectation_error_factory.rb
15
16
  lib/mocha/expectation_error.rb
16
17
  lib/mocha/stubbing_error.rb
17
18
  lib/mocha/unexpected_invocation.rb
19
+ lib/mocha/integration.rb
18
20
  lib/mocha/integration/test_unit/adapter.rb
19
21
  lib/mocha/integration/minitest/adapter.rb
20
22
  -
data/Gemfile CHANGED
@@ -2,34 +2,16 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- # rubocop:disable Bundler/DuplicatedGem
6
- if RUBY_VERSION < '2.2'
7
- gem 'rake', '~> 12.3.3'
8
- else
5
+ group :development do
6
+ gem 'benchmark'
7
+ gem 'introspection', '~> 0.0.1'
8
+ gem 'minitest'
9
9
  gem 'rake'
10
- end
11
- # rubocop:enable Bundler/DuplicatedGem
12
-
13
- gem 'introspection', '~> 0.0.1'
14
-
15
- # Avoid breaking change in psych v4 (https://bugs.ruby-lang.org/issues/17866)
16
- if RUBY_VERSION >= '3.1.0'
17
- gem 'psych', '< 4'
18
- end
19
10
 
20
- if RUBY_VERSION >= '2.2.0'
21
- # No test libraries in standard library
22
- gem 'minitest'
23
- end
24
- if RUBY_VERSION >= '2.2.0'
25
- gem 'jaro_winkler', '>= 1.5.5'
26
- gem 'rubocop', '> 0.56', '<= 0.58.2'
27
- end
28
- if RUBY_ENGINE == 'jruby'
29
- # Workaround for https://github.com/jruby/jruby/issues/8488
30
- gem 'jar-dependencies', '~> 0.4.1'
31
- end
32
- if ENV['MOCHA_GENERATE_DOCS']
33
- gem 'redcarpet'
34
- gem 'yard'
11
+ if ENV['MOCHA_GENERATE_DOCS']
12
+ gem 'irb'
13
+ gem 'rdoc'
14
+ gem 'redcarpet'
15
+ gem 'yard'
16
+ end
35
17
  end
data/README.md CHANGED
@@ -292,10 +292,9 @@ If you want, Mocha can generate a warning or raise an exception when:
292
292
 
293
293
  See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) for `Mocha::Configuration` for further details.
294
294
 
295
- ##### MOCHA_OPTIONS
296
- `MOCHA_OPTIONS` is an environment variable whose value can be set to a comma-separated list, so that we can specify multiple options e.g. `MOCHA_OPTIONS=debug,use_test_unit_gem`.
297
- Only the following values are currently recognized and have an effect:
298
- * `debug`: Enables a debug mode which will output backtraces for each deprecation warning. This is useful for finding where in the test suite the deprecated calls are.
295
+ ### Debugging
296
+
297
+ Mocha provides some extra output to help with debugging when the standard Ruby debug option (`-d`) is set.
299
298
 
300
299
  ### Semantic versioning
301
300
 
@@ -331,7 +330,7 @@ See this [list of contributors](https://github.com/freerange/mocha/graphs/contri
331
330
  ```bash
332
331
  $ MOCHA_GENERATE_DOCS=true bundle install
333
332
 
334
- $ MOCHA_GENERATE_DOCS=true rake generate_docs
333
+ $ MOCHA_GENERATE_DOCS=true bundle exec rake docs
335
334
  ```
336
335
  * Commit documentation & push to GitHub
337
336
  * Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
@@ -343,7 +342,7 @@ $ curl -u <email-address> -H 'OTP:<one-time-password>' https://rubygems.org/api/
343
342
  * Release gem to Rubygems:
344
343
 
345
344
  ```bash
346
- $ rake release
345
+ $ bundle exec rake release
347
346
  [runs tests]
348
347
  mocha 1.2.0 built to pkg/mocha-1.2.0.gem.
349
348
  Tagged v1.2.0.
data/RELEASE.md CHANGED
@@ -1,5 +1,85 @@
1
1
  # Release Notes
2
2
 
3
+ ## 3.0.2
4
+
5
+ ### External changes
6
+
7
+ * Fix `NoMethodError` on deprecation warning - broken since v3.0.0 (#790)
8
+
9
+ ### Internal changes
10
+
11
+ * Update commands in release docs to use `bundle exec` (7692c735)
12
+ * Fix `test:performance` rake task for minitest v6 (d925ad27)
13
+ * Fix prism gem install on JRuby (683c27b4)
14
+ * Add Ruby v4.0-rc to CI build matrix and change weekly build to nightly (#777)
15
+ * Add Ruby v4.0 to CI build matrix (6ced2025)
16
+ * Add irb to `Gemfile` to fix warning in Ruby v4 (a0fc7798)
17
+ * Auto-correct `Style/EmptyClassDefinition` violation (9ba0a09f)
18
+ * Ensure every test can run in isolation (be12ef06)
19
+ * Rename `run-fail-fast` CircleCI command -> `run-fail-on-warning` (72fc6fe8)
20
+
21
+ ## 3.0.1
22
+
23
+ ### External changes
24
+
25
+ * Fix Mocha/RSpec integration by reinstating argument default value for `Hooks#mocha_setup` (#768 & #769) - thanks to @mackuba for reporting.
26
+
27
+ ## 3.0.0
28
+
29
+ ### External changes
30
+
31
+ * Improvements to docs for cardinality-related methods (#700)
32
+ * Drop support for Ruby v2.1 (#628 & #695)
33
+ * Improve gemspec description (#692 & #696)
34
+ * Remove docs for `use_test_unit_gem` option (eaf03493)
35
+ * Correct docs for `MOCHA_OPTIONS` "debug" value (69ef41c0)
36
+ * Use built-in Ruby debug option vs custom module (#714 & #715)
37
+ * Enable strict keyword argument matching by default in Ruby >= v3 (#697 & #718)
38
+ * Use Ruby v1.9 Hash syntax in `Hash#mocha_inspect` used in failure messages (#651 & #719)
39
+ * Improve `#mocha_inspect` for empty keyword argument `Hash` (#588 & #720) - thanks to @herwinw for reporting
40
+ * Improve error if `Mockery.teardown` called before `Mockery.setup` (#611, #646 & #721) - thanks to @riniculous for reporting
41
+ * Freeze string literals (#722)
42
+ * Allow keyword arguments to match an expectation expecting *only* positional arguments (#593 & #732) - thanks to @seandilda
43
+ for reporting
44
+ * Fix compatibility with Ruby 3.5 (#755) - thanks to @Earlopain
45
+ * Add missing quotes to docs for `Mocha::ParameterMatchers::Methods#equivalent_uri` (#757) - thanks to @bensherman
46
+ * Increment assertion count on never expected invocation (#763 & #764)
47
+ * Remove deprecated `ParameterMatchers::Base` class; include `ParameterMatchers::BaseMethods` module instead (415ae768)
48
+ * Remove deprecated `ParameterMatcher` methods now available in `ParameterMatcher::Methods` (8de49979)
49
+ * Removed deprecated access to `ParameterMatcher` classes (6ea9e3f5)
50
+
51
+ ### Internal changes
52
+
53
+ * Add `Expectation#thrice` (#701) - thanks to @andrewn617
54
+ * Add `base64` to Gemfile for Ruby >= v3.3.0 to avoid warning (8c49314c & a76330d6)
55
+ * Include custom Gemfiles in Rubocop linting (04063f0d)
56
+ * Use ruby:3.4.0-rc1 vs ruby:3.4.0-preview2 in CI in preparation for the Ruby v3.4 release (b2127407)
57
+ * Add `ostruct` to Gemfile for Ruby >= v3.4.0 to avoid warning (2b05e09e)
58
+ * Add Ruby v3.4 to CI build matrix (#708)
59
+ * Fix Ruby v3.4 warnings in ObjectInspectTest (#709 & #710)
60
+ * Rubocop-related improvements (#702 & #705)
61
+ * Consistently use development group in Gemfiles (#706 & #716)
62
+ * Add missing requires for 'mocha/ruby_version' (7f99db69)
63
+ * Convert `ParameterMatchers::Base` class -> module (#712 & #723)
64
+ * Enable `ExpectMatchingDefinition` option on `Naming/FileName` cop (#726)
65
+ * Remove duplicate `DefaultReceiverTest` (39d99954)
66
+ * Improvements to keyword argument matching tests (#730)
67
+ * Improvements to keyword argument matcher unit test (#731)
68
+ * Remove support for running tests with Minitest < v5 (#727)
69
+ * Remove workaround for JRuby jar-dependencies issue (#737)
70
+ * Add benchmark to `Gemfile` to fix warning (#733 & #740) - thanks to @nitishr
71
+ * Add documentation coverage check (#707, #743 & #745) - thanks to @nitishr
72
+ * Fix `Lint/LiteralAsCondition` violation (#746) - thanks to @nitishr
73
+ * Fix rdoc-related warning when running doc rake task (#741 & #747)
74
+ * Fail fast in CI builds on any Ruby warnings (#729 & #741) - thanks to @nitishr
75
+ * Add `ObjectMethods#stubba_respond_to?` and use instead of `Object#respond_to?` (#713, #742 & #750) - thanks to @nitishr
76
+ * Rename `#stubbee` -> `#stubba_object` and `#mock_owner` -> `#stubbee` (#463 & #751) - thanks to @nitishr
77
+ * Fix `enable-frozen-string-literal` in CI build (#752) - thanks to @nitishr
78
+ * Various rubocop fixed (#754 & #756)
79
+ * Fix `Layout/EmptyLinesAfterModuleInclusion` violations (3f683220)
80
+ * Auto-correct `Style/RedundantParentheses` violations (0277a592)
81
+ * Automatically retry failed CI builds (9bbdbc66)
82
+
3
83
  ## 2.8.2
4
84
 
5
85
  ### External changes
@@ -28,10 +108,6 @@ Many thanks to @etiennebarrie for his help in testing v3.0.0 release candidates
28
108
 
29
109
  * Move `ParameterMatchers#parse_option` -> `HasEntry.parse_option` (9e2a6f66)
30
110
 
31
- **WARNING: This release accidentally removed access to ParameterMatchers classes**
32
- * Fully-qualified access from within a test/spec class still works, e.g. `Mocha::ParameterMatchers::HasKey`, but unqualified access does not work, e.g. `HasKey`.
33
- * The mistake has been fixed in v2.8.1 where unqualified access is restored but deprecated. Unqualified access will be removed in v3.
34
-
35
111
  ## 2.7.1
36
112
 
37
113
  ### External changes
data/Rakefile CHANGED
@@ -6,9 +6,10 @@ require 'bundler/setup'
6
6
 
7
7
  require 'rake/testtask'
8
8
  begin
9
- # Only available with default Gemfile and in Ruby >= v2.2
9
+ # Only available with `gemfiles/Gemfile.rubocop`
10
10
  require 'rubocop/rake_task'
11
- rescue LoadError # rubocop:disable Lint/HandleExceptions
11
+ rescue LoadError
12
+ warn "Unable to load 'rubocop/rake_task', but continuing anyway" if $DEBUG
12
13
  end
13
14
 
14
15
  desc 'Run all linters and tests'
@@ -24,7 +25,7 @@ task 'test' do
24
25
  end
25
26
  end
26
27
 
27
- namespace 'test' do # rubocop:disable Metrics/BlockLength
28
+ namespace 'test' do
28
29
  desc 'Run unit tests'
29
30
  Rake::TestTask.new('units') do |t|
30
31
  t.libs << 'test'
@@ -41,6 +42,25 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
41
42
  t.warning = true
42
43
  end
43
44
 
45
+ desc 'Run each test in isolation'
46
+ task 'isolated' do
47
+ test_files = FileList['test/unit/**/*_test.rb', 'test/acceptance/*_test.rb']
48
+ failed_tests = []
49
+
50
+ test_files.each do |test_file|
51
+ puts "\n=== Running #{test_file} in isolation ==="
52
+ system("ruby -Itest -w #{test_file}") || (failed_tests << test_file)
53
+ end
54
+
55
+ if failed_tests.any?
56
+ puts "\n❌ #{failed_tests.size} test file(s) failed:"
57
+ failed_tests.each { |f| puts " - #{f}" }
58
+ exit 1
59
+ else
60
+ puts "\n✅ All #{test_files.size} test files passed in isolation!"
61
+ end
62
+ end
63
+
44
64
  namespace 'integration' do
45
65
  desc 'Run Minitest integration tests (intended to be run in its own process)'
46
66
  Rake::TestTask.new('minitest') do |t|
@@ -81,6 +101,7 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
81
101
  end
82
102
  end
83
103
 
104
+ desc 'Run linters'
84
105
  task 'lint' do
85
106
  if defined?(RuboCop::RakeTask)
86
107
  RuboCop::RakeTask.new
@@ -90,16 +111,16 @@ task 'lint' do
90
111
  end
91
112
  end
92
113
 
93
- # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
94
- def benchmark_test_case(klass, iterations)
114
+ def benchmark_test_case(klass, iterations) # rubocop:disable Metrics/AbcSize
95
115
  require 'benchmark'
96
116
  require 'mocha/detection/minitest'
97
117
 
98
118
  if defined?(Minitest)
99
119
  minitest_version = Gem::Version.new(Mocha::Detection::Minitest.version)
100
120
  if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
121
+ run_method = Gem::Requirement.new('>= 6.0.0').satisfied_by?(minitest_version) ? :run_suite : :run
101
122
  Minitest.seed = 1
102
- result = Benchmark.realtime { iterations.times { |_i| klass.run(Minitest::CompositeReporter.new) } }
123
+ result = Benchmark.realtime { iterations.times { |_i| klass.public_send(run_method, Minitest::CompositeReporter.new) } }
103
124
  Minitest::Runnable.runnables.delete(klass)
104
125
  result
105
126
  else
@@ -119,32 +140,52 @@ def benchmark_test_case(klass, iterations)
119
140
  Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, @silent_option) } }
120
141
  end
121
142
  end
122
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
123
-
124
143
  if ENV['MOCHA_GENERATE_DOCS']
125
144
  require 'yard'
126
145
 
127
- desc 'Remove generated documentation'
128
- task 'clobber_yardoc' do
129
- `rm -rf ./docs`
130
- end
146
+ namespace :docs do
147
+ desc 'Remove generated documentation'
148
+ task :clobber do
149
+ `rm -rf ./docs`
150
+ end
131
151
 
132
- desc 'Generate documentation'
133
- YARD::Rake::YardocTask.new('yardoc') do |task|
134
- task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
135
- end
152
+ desc 'Generate documentation'
153
+ YARD::Rake::YardocTask.new(:generate) do |task|
154
+ task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
155
+ end
136
156
 
137
- task 'checkout_docs_cname' do
138
- `git checkout docs/CNAME`
139
- end
157
+ desc 'Ensure custom domain remains in place for docs on GitHub Pages'
158
+ task :ensure_cname do
159
+ `git checkout docs/CNAME`
160
+ end
161
+
162
+ desc 'Ensure custom JavaScript files remain in place for docs on GitHub Pages'
163
+ task :ensure_js do
164
+ `git checkout docs/js/app.js`
165
+ `git checkout docs/js/jquery.js`
166
+ end
140
167
 
141
- task 'checkout_docs_js' do
142
- `git checkout docs/js/app.js`
143
- `git checkout docs/js/jquery.js`
168
+ desc 'Check documentation coverage'
169
+ task :coverage do
170
+ stats_output = `yard stats --list-undoc`
171
+ puts stats_output
172
+
173
+ match = stats_output.match(/(?<coverage_percentage>\d+\.\d+)% documented/);
174
+ abort 'Error: Could not determine documentation coverage.' unless match
175
+
176
+ coverage_percentage = match[:coverage_percentage].to_f
177
+ minimum_percentage = 100.0
178
+
179
+ if coverage_percentage < minimum_percentage
180
+ abort "Documentation coverage is #{coverage_percentage}%, which is below the required #{minimum_percentage}%."
181
+ else
182
+ puts "Documentation coverage is #{coverage_percentage}%, which is at or above the required #{minimum_percentage}%."
183
+ end
184
+ end
144
185
  end
145
186
 
146
- desc 'Generate documentation'
147
- task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
187
+ desc 'Prepare documentation for publication on GitHub Pages'
188
+ task 'docs' => %w[docs:clobber docs:generate docs:ensure_cname docs:ensure_js]
148
189
  end
149
190
 
150
191
  task 'release' => ['default', 'rubygems:release']
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec :path=>"../"
3
+ gemspec path: '../'
4
4
 
5
5
  group :development do
6
- gem "rake"
7
- gem "minitest"
6
+ gem 'rake'
7
+ gem 'minitest'
8
8
  end
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'rubocop'
8
+ gem 'rubocop-rake'
9
+ end
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec :path=>"../"
3
+ gemspec path: '../'
4
4
 
5
5
  group :development do
6
- gem "rake"
7
- gem "test-unit"
6
+ gem 'rake'
7
+ gem 'test-unit'
8
8
  end
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/stubbed_method'
2
4
 
3
5
  module Mocha
4
6
  class AnyInstanceMethod < StubbedMethod
5
7
  private
6
8
 
7
- def mock_owner
8
- stubbee.any_instance
9
+ def stubbee
10
+ stubba_object.any_instance
9
11
  end
10
12
 
11
13
  def stubbee_method(method_name)
12
- stubbee.instance_method(method_name)
14
+ stubba_object.instance_method(method_name)
13
15
  end
14
16
 
15
17
  def original_method_owner
16
- stubbee
18
+ stubba_object
17
19
  end
18
20
  end
19
21
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mocha
4
+ class AnyInstanceReceiver
5
+ def initialize(klass)
6
+ @klass = klass
7
+ end
8
+
9
+ def mocks
10
+ klass = @klass
11
+ mocks = []
12
+ while klass
13
+ mocha = klass.any_instance.mocha(instantiate: false)
14
+ mocks << mocha if mocha
15
+ klass = klass.superclass
16
+ end
17
+ mocks
18
+ end
19
+ end
20
+ end
data/lib/mocha/api.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/ruby_version'
2
4
  require 'mocha/parameter_matchers'
3
5
  require 'mocha/hooks'
@@ -37,8 +39,8 @@ module Mocha
37
39
 
38
40
  # @private
39
41
  def self.included(_mod)
40
- Object.send(:include, Mocha::ObjectMethods)
41
- Class.send(:include, Mocha::ClassMethods)
42
+ Object.include Mocha::ObjectMethods
43
+ Class.include Mocha::ClassMethods
42
44
  end
43
45
 
44
46
  # @private
@@ -1,16 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class ArgumentIterator
3
5
  def initialize(argument)
4
6
  @argument = argument
5
7
  end
6
8
 
7
- def each
9
+ def each(&block)
8
10
  if @argument.is_a?(Hash)
9
- @argument.each do |method_name, return_value|
10
- yield method_name, return_value
11
- end
11
+ @argument.each(&block)
12
12
  else
13
- yield @argument
13
+ block.call(@argument)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class BacktraceFilter
3
5
  LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), '..')) + File::SEPARATOR
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  module BlockMatchers
3
5
  class OptionalBlock
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class Cardinality
3
5
  INFINITY = 1 / 0.0
@@ -58,7 +60,6 @@ module Mocha
58
60
  @invocations.any? || maximum.zero?
59
61
  end
60
62
 
61
- # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
62
63
  def anticipated_times
63
64
  if allowed_any_number_of_times?
64
65
  'allowed any number of times'
@@ -74,7 +75,6 @@ module Mocha
74
75
  "expected between #{required} and #{count(maximum)}"
75
76
  end
76
77
  end
77
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
78
78
 
79
79
  def invoked_times
80
80
  "invoked #{count(@invocations.size)}"
data/lib/mocha/central.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class Central
3
5
  class Null < self
@@ -23,12 +25,14 @@ module Mocha
23
25
 
24
26
  def stub(method)
25
27
  return if stubba_methods.detect { |m| m.matches?(method) }
28
+
26
29
  method.stub
27
30
  stubba_methods.push(method)
28
31
  end
29
32
 
30
33
  def unstub(method)
31
34
  return unless (existing = stubba_methods.detect { |m| m.matches?(method) })
35
+
32
36
  existing.unstub
33
37
  stubba_methods.delete(existing)
34
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class ChangeStateSideEffect
3
5
  def initialize(state)