mocha 2.8.0 → 3.0.0.pre.rc.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 (105) 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 +9 -28
  6. data/README.md +3 -4
  7. data/RELEASE.md +64 -0
  8. data/Rakefile +43 -22
  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 +6 -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 +7 -3
  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 -16
  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 +15 -8
  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/mocha.gemspec +10 -4
  99. metadata +18 -12
  100. data/lib/mocha/debug.rb +0 -9
  101. data/lib/mocha/integration/minitest/exception_translation.rb +0 -14
  102. data/lib/mocha/is_a.rb +0 -7
  103. data/lib/mocha/names.rb +0 -43
  104. data/lib/mocha/parameter_matchers/deprecations.rb +0 -46
  105. data/lib/mocha/receivers.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f100e1c21f105d22752ae4ffc7740ba8fb351559679d3972ae5eea253725e082
4
- data.tar.gz: 31729a24bdde2da814bbf7d995fb77fc4c08dd7c98775bdb85d6d36fead87a35
3
+ metadata.gz: 89867d8324e0ff09c1b10c13bb46ecbc68215098b8abd916d5be2ebe165d91fe
4
+ data.tar.gz: 835f460adaa854163671e2a2222f68e8674edb1eb80d714f8e7e58ce26705391
5
5
  SHA512:
6
- metadata.gz: 57b38d4f7b71f41156ea6dd278416864caed11866f1137a5605491000d3603b8793200d6275962b77ed71aaf09707333b88301451b809e9774e3180d594451cf
7
- data.tar.gz: 672e486d410a534ecf3eae8613294dfeb894c3fc8d324ae4414328e56ccd31ab9ebb46f13105b95cb3c1b0f35e5cd89eb6eeb5dee7493fbefe200dc03b251f0d
6
+ metadata.gz: 4ead2dc30052a85e96ad27728852ee61c120b40229c376508595a09eeee10c863fae71644c4abe917d2a2ae400690d67fd32774a2c4dc6d79fbacc443171d55a
7
+ data.tar.gz: 3cc439692bc5163961fc2cd44aee804634fdb903d01b245e1101c99818f92cb760c51d3a0dd0a8927bc7c29ccf1c0c202bda4cbd70a058c1c21c1a5beb341edb
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,15 @@ 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 'rdoc'
13
+ gem 'redcarpet'
14
+ gem 'yard'
15
+ end
35
16
  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
 
data/RELEASE.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # Release Notes
2
2
 
3
+ ## 3.0.0-rc.2
4
+
5
+ ### External changes
6
+
7
+ * Fix compatibility with Ruby 3.5 (#755) - thanks to @Earlopain
8
+ * Add missing quotes to docs for `Mocha::ParameterMatchers::Methods#equivalent_uri` (#757) - thanks to @bensherman
9
+ * Increment assertion count on never expected invocation (#763 & #764)
10
+ * Remove deprecated `ParameterMatchers::Base` class; include `ParameterMatchers::BaseMethods` module instead (415ae768)
11
+ * Remove deprecated `ParameterMatcher` methods now available in `ParameterMatcher::Methods` (8de49979)
12
+ * Removed deprecated access to `ParameterMatcher` classes (6ea9e3f5)
13
+
14
+ ### Internal changes
15
+
16
+ * Remove workaround for JRuby jar-dependencies issue (#737)
17
+ * Add benchmark to `Gemfile` to fix warning (#733 & #740) - thanks to @nitishr
18
+ * Add documentation coverage check (#707, #743 & #745) - thanks to @nitishr
19
+ * Fix `Lint/LiteralAsCondition` violation (#746) - thanks to @nitishr
20
+ * Fix rdoc-related warning when running doc rake task (#741 & #747)
21
+ * Fail fast in CI builds on any Ruby warnings (#729 & #741) - thanks to @nitishr
22
+ * Add `ObjectMethods#stubba_respond_to?` and use instead of `Object#respond_to?` (#713, #742 & #750) - thanks to @nitishr
23
+ * Rename `#stubbee` -> `#stubba_object` and `#mock_owner` -> `#stubbee` (#463 & #751) - thanks to @nitishr
24
+ * Fix `enable-frozen-string-literal` in CI build (#752) - thanks to @nitishr
25
+ * Various rubocop fixed (#754 & #756)
26
+ * Fix `Layout/EmptyLinesAfterModuleInclusion` violations (3f683220)
27
+ * Auto-correct `Style/RedundantParentheses` violations (0277a592)
28
+ * Automatically retry failed CI builds (9bbdbc66)
29
+
30
+ ## 3.0.0-rc.1
31
+
32
+ ### External changes
33
+
34
+ * Improvements to docs for cardinality-related methods (#700)
35
+ * Drop support for Ruby v2.1 (#628 & #695)
36
+ * Improve gemspec description (#692 & #696)
37
+ * Remove docs for `use_test_unit_gem` option (eaf03493)
38
+ * Correct docs for `MOCHA_OPTIONS` "debug" value (69ef41c0)
39
+ * Use built-in Ruby debug option vs custom module (#714 & #715)
40
+ * Enable strict keyword argument matching by default in Ruby >= v3 (#697 & #718)
41
+ * Use Ruby v1.9 Hash syntax in `Hash#mocha_inspect` used in failure messages (#651 & #719)
42
+ * Improve `#mocha_inspect` for empty keyword argument `Hash` (#588 & #720) - thanks to @herwinw for reporting
43
+ * Improve error if `Mockery.teardown` called before `Mockery.setup` (#611, #646 & #721) - thanks to @riniculous for reporting
44
+ * Freeze string literals (#722)
45
+ * Remove support for running tests with Minitest < v5 (#727)
46
+ * Allow keyword arguments to match an expectation expecting *only* positional arguments (#593 & #732) - thanks to @seandilda
47
+ for reporting
48
+
49
+ ### Internal changes
50
+
51
+ * Add `Expectation#thrice` (#701) - thanks to @andrewn617
52
+ * Add `base64` to Gemfile for Ruby >= v3.3.0 to avoid warning (8c49314c & a76330d6)
53
+ * Include custom Gemfiles in Rubocop linting (04063f0d)
54
+ * Use ruby:3.4.0-rc1 vs ruby:3.4.0-preview2 in CI in preparation for the Ruby v3.4 release (b2127407)
55
+ * Add `ostruct` to Gemfile for Ruby >= v3.4.0 to avoid warning (2b05e09e)
56
+ * Add Ruby v3.4 to CI build matrix (#708)
57
+ * Fix Ruby v3.4 warnings in ObjectInspectTest (#709 & #710)
58
+ * Rubocop-related improvements (#702 & #705)
59
+ * Consistently use development group in Gemfiles (#706 & #716)
60
+ * Add missing requires for 'mocha/ruby_version' (7f99db69)
61
+ * Convert `ParameterMatchers::Base` class -> module (#712 & #723)
62
+ * Enable `ExpectMatchingDefinition` option on `Naming/FileName` cop (#726)
63
+ * Remove duplicate `DefaultReceiverTest` (39d99954)
64
+ * Improvements to keyword argument matching tests (#730)
65
+ * Improvements to keyword argument matcher unit test (#731)
66
+
3
67
  ## 2.8.0
4
68
 
5
69
  Many thanks to @etiennebarrie for his help in testing v3.0.0 release candidates which led to many of these 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'
@@ -81,6 +82,7 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
81
82
  end
82
83
  end
83
84
 
85
+ desc 'Run linters'
84
86
  task 'lint' do
85
87
  if defined?(RuboCop::RakeTask)
86
88
  RuboCop::RakeTask.new
@@ -90,7 +92,6 @@ task 'lint' do
90
92
  end
91
93
  end
92
94
 
93
- # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
94
95
  def benchmark_test_case(klass, iterations)
95
96
  require 'benchmark'
96
97
  require 'mocha/detection/minitest'
@@ -119,32 +120,52 @@ def benchmark_test_case(klass, iterations)
119
120
  Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, @silent_option) } }
120
121
  end
121
122
  end
122
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
123
-
124
123
  if ENV['MOCHA_GENERATE_DOCS']
125
124
  require 'yard'
126
125
 
127
- desc 'Remove generated documentation'
128
- task 'clobber_yardoc' do
129
- `rm -rf ./docs`
130
- end
126
+ namespace :docs do
127
+ desc 'Remove generated documentation'
128
+ task :clobber do
129
+ `rm -rf ./docs`
130
+ end
131
131
 
132
- desc 'Generate documentation'
133
- YARD::Rake::YardocTask.new('yardoc') do |task|
134
- task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
135
- end
132
+ desc 'Generate documentation'
133
+ YARD::Rake::YardocTask.new(:generate) do |task|
134
+ task.options = ['--title', "Mocha #{Mocha::VERSION}", '--fail-on-warning']
135
+ end
136
136
 
137
- task 'checkout_docs_cname' do
138
- `git checkout docs/CNAME`
139
- end
137
+ desc 'Ensure custom domain remains in place for docs on GitHub Pages'
138
+ task :ensure_cname do
139
+ `git checkout docs/CNAME`
140
+ end
140
141
 
141
- task 'checkout_docs_js' do
142
- `git checkout docs/js/app.js`
143
- `git checkout docs/js/jquery.js`
142
+ desc 'Ensure custom JavaScript files remain in place for docs on GitHub Pages'
143
+ task :ensure_js do
144
+ `git checkout docs/js/app.js`
145
+ `git checkout docs/js/jquery.js`
146
+ end
147
+
148
+ desc 'Check documentation coverage'
149
+ task :coverage do
150
+ stats_output = `yard stats --list-undoc`
151
+ puts stats_output
152
+
153
+ match = stats_output.match(/(?<coverage_percentage>\d+\.\d+)% documented/);
154
+ abort 'Error: Could not determine documentation coverage.' unless match
155
+
156
+ coverage_percentage = match[:coverage_percentage].to_f
157
+ minimum_percentage = 100.0
158
+
159
+ if coverage_percentage < minimum_percentage
160
+ abort "Documentation coverage is #{coverage_percentage}%, which is below the required #{minimum_percentage}%."
161
+ else
162
+ puts "Documentation coverage is #{coverage_percentage}%, which is at or above the required #{minimum_percentage}%."
163
+ end
164
+ end
144
165
  end
145
166
 
146
- desc 'Generate documentation'
147
- task 'generate_docs' => %w[clobber_yardoc yardoc checkout_docs_cname checkout_docs_js]
167
+ desc 'Prepare documentation for publication on GitHub Pages'
168
+ task 'docs' => %w[docs:clobber docs:generate docs:ensure_cname docs:ensure_js]
148
169
  end
149
170
 
150
171
  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)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/mockery'
2
4
  require 'mocha/any_instance_method'
3
5
 
@@ -10,7 +12,7 @@ module Mocha
10
12
  @stubba_object = klass
11
13
  end
12
14
 
13
- def mocha(instantiate = true)
15
+ def mocha(instantiate: true)
14
16
  if instantiate
15
17
  @mocha ||= Mocha::Mockery.instance.mock_impersonating_any_instance_of(@stubba_object)
16
18
  else
@@ -26,8 +28,8 @@ module Mocha
26
28
  @stubba_object
27
29
  end
28
30
 
29
- def respond_to?(symbol, include_all = false)
30
- @stubba_object.allocate.respond_to?(symbol.to_sym, include_all)
31
+ def stubba_respond_to?(symbol)
32
+ @stubba_object.allocate.respond_to?(symbol.to_sym)
31
33
  end
32
34
 
33
35
  attr_reader :stubba_object
@@ -46,17 +48,20 @@ module Mocha
46
48
  if frozen?
47
49
  raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}.any_instance", caller)
48
50
  end
51
+
49
52
  @any_instance ||= AnyInstance.new(self)
50
53
  end
51
54
 
52
55
  # @private
53
- # rubocop:disable Metrics/CyclomaticComplexity
54
- def __method_visibility__(method, include_public_methods = true)
55
- (include_public_methods && public_method_defined?(method) && :public) ||
56
- (protected_method_defined?(method) && :protected) ||
57
- (private_method_defined?(method) && :private)
56
+ def __method_visibility__(method, include_public_methods: true)
57
+ if include_public_methods && public_method_defined?(method)
58
+ :public
59
+ elsif protected_method_defined?(method)
60
+ :protected
61
+ else
62
+ private_method_defined?(method) ? :private : nil
63
+ end
58
64
  end
59
- # rubocop:enable Metrics/CyclomaticComplexity
60
65
  alias_method :__method_exists__?, :__method_visibility__
61
66
  end
62
67
  end