mocktail 1.2.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +6 -5
  3. data/.gitignore +3 -0
  4. data/.standard.yml +8 -0
  5. data/CHANGELOG.md +14 -0
  6. data/Gemfile +6 -1
  7. data/Gemfile.lock +98 -25
  8. data/README.md +18 -922
  9. data/Rakefile +0 -1
  10. data/bin/console +1 -2
  11. data/bin/tapioca +29 -0
  12. data/lib/mocktail/collects_calls.rb +2 -0
  13. data/lib/mocktail/debug.rb +13 -10
  14. data/lib/mocktail/dsl.rb +2 -0
  15. data/lib/mocktail/errors.rb +2 -0
  16. data/lib/mocktail/explains_nils.rb +2 -0
  17. data/lib/mocktail/explains_thing.rb +7 -4
  18. data/lib/mocktail/grabs_original_method_parameters.rb +30 -0
  19. data/lib/mocktail/handles_dry_call/fulfills_stubbing/describes_unsatisfied_stubbing.rb +3 -1
  20. data/lib/mocktail/handles_dry_call/fulfills_stubbing/finds_satisfaction.rb +5 -1
  21. data/lib/mocktail/handles_dry_call/fulfills_stubbing.rb +2 -0
  22. data/lib/mocktail/handles_dry_call/logs_call.rb +2 -0
  23. data/lib/mocktail/handles_dry_call/validates_arguments.rb +6 -4
  24. data/lib/mocktail/handles_dry_call.rb +2 -0
  25. data/lib/mocktail/handles_dry_new_call.rb +2 -0
  26. data/lib/mocktail/imitates_type/ensures_imitation_support.rb +2 -0
  27. data/lib/mocktail/imitates_type/makes_double/declares_dry_class/reconstructs_call.rb +4 -1
  28. data/lib/mocktail/imitates_type/makes_double/declares_dry_class.rb +32 -20
  29. data/lib/mocktail/imitates_type/makes_double/gathers_fakeable_instance_methods.rb +2 -0
  30. data/lib/mocktail/imitates_type/makes_double.rb +3 -0
  31. data/lib/mocktail/imitates_type.rb +3 -1
  32. data/lib/mocktail/initialize_based_on_type_system_mode_switching.rb +9 -0
  33. data/lib/mocktail/initializes_mocktail.rb +5 -0
  34. data/lib/mocktail/matcher_presentation.rb +4 -2
  35. data/lib/mocktail/matchers/any.rb +4 -3
  36. data/lib/mocktail/matchers/base.rb +10 -2
  37. data/lib/mocktail/matchers/captor.rb +9 -0
  38. data/lib/mocktail/matchers/includes.rb +2 -0
  39. data/lib/mocktail/matchers/includes_hash.rb +9 -0
  40. data/lib/mocktail/matchers/includes_key.rb +9 -0
  41. data/lib/mocktail/matchers/includes_string.rb +9 -0
  42. data/lib/mocktail/matchers/is_a.rb +2 -0
  43. data/lib/mocktail/matchers/matches.rb +2 -0
  44. data/lib/mocktail/matchers/not.rb +2 -0
  45. data/lib/mocktail/matchers/numeric.rb +5 -4
  46. data/lib/mocktail/matchers/that.rb +2 -0
  47. data/lib/mocktail/matchers.rb +3 -0
  48. data/lib/mocktail/raises_neato_no_method_error.rb +2 -0
  49. data/lib/mocktail/records_demonstration.rb +2 -0
  50. data/lib/mocktail/registers_matcher.rb +8 -3
  51. data/lib/mocktail/registers_stubbing.rb +2 -0
  52. data/lib/mocktail/replaces_next.rb +7 -1
  53. data/lib/mocktail/replaces_type/redefines_new.rb +3 -1
  54. data/lib/mocktail/replaces_type/redefines_singleton_methods.rb +14 -2
  55. data/lib/mocktail/replaces_type/runs_sorbet_sig_blocks_before_replacement.rb +37 -0
  56. data/lib/mocktail/replaces_type.rb +6 -0
  57. data/lib/mocktail/resets_state.rb +2 -0
  58. data/lib/mocktail/share/bind.rb +7 -5
  59. data/lib/mocktail/share/cleans_backtrace.rb +3 -5
  60. data/lib/mocktail/share/creates_identifier.rb +16 -9
  61. data/lib/mocktail/share/determines_matching_calls.rb +4 -2
  62. data/lib/mocktail/share/stringifies_call.rb +6 -2
  63. data/lib/mocktail/share/stringifies_method_name.rb +3 -1
  64. data/lib/mocktail/simulates_argument_error/reconciles_args_with_params.rb +2 -0
  65. data/lib/mocktail/simulates_argument_error/recreates_message.rb +2 -0
  66. data/lib/mocktail/simulates_argument_error/transforms_params.rb +15 -8
  67. data/lib/mocktail/simulates_argument_error.rb +2 -0
  68. data/lib/mocktail/sorbet/mocktail/collects_calls.rb +18 -0
  69. data/lib/mocktail/sorbet/mocktail/debug.rb +54 -0
  70. data/lib/mocktail/sorbet/mocktail/dsl.rb +46 -0
  71. data/lib/mocktail/sorbet/mocktail/errors.rb +19 -0
  72. data/lib/mocktail/sorbet/mocktail/explains_nils.rb +41 -0
  73. data/lib/mocktail/sorbet/mocktail/explains_thing.rb +137 -0
  74. data/lib/mocktail/sorbet/mocktail/grabs_original_method_parameters.rb +33 -0
  75. data/lib/mocktail/sorbet/mocktail/handles_dry_call/fulfills_stubbing/describes_unsatisfied_stubbing.rb +27 -0
  76. data/lib/mocktail/sorbet/mocktail/handles_dry_call/fulfills_stubbing/finds_satisfaction.rb +24 -0
  77. data/lib/mocktail/sorbet/mocktail/handles_dry_call/fulfills_stubbing.rb +45 -0
  78. data/lib/mocktail/sorbet/mocktail/handles_dry_call/logs_call.rb +12 -0
  79. data/lib/mocktail/sorbet/mocktail/handles_dry_call/validates_arguments.rb +45 -0
  80. data/lib/mocktail/sorbet/mocktail/handles_dry_call.rb +25 -0
  81. data/lib/mocktail/sorbet/mocktail/handles_dry_new_call.rb +42 -0
  82. data/lib/mocktail/sorbet/mocktail/imitates_type/ensures_imitation_support.rb +16 -0
  83. data/lib/mocktail/sorbet/mocktail/imitates_type/makes_double/declares_dry_class/reconstructs_call.rb +73 -0
  84. data/lib/mocktail/sorbet/mocktail/imitates_type/makes_double/declares_dry_class.rb +136 -0
  85. data/lib/mocktail/sorbet/mocktail/imitates_type/makes_double/gathers_fakeable_instance_methods.rb +28 -0
  86. data/lib/mocktail/sorbet/mocktail/imitates_type/makes_double.rb +29 -0
  87. data/lib/mocktail/sorbet/mocktail/imitates_type.rb +29 -0
  88. data/lib/mocktail/sorbet/mocktail/initialize_based_on_type_system_mode_switching.rb +11 -0
  89. data/lib/mocktail/sorbet/mocktail/initializes_mocktail.rb +25 -0
  90. data/lib/mocktail/sorbet/mocktail/matcher_presentation.rb +21 -0
  91. data/lib/mocktail/sorbet/mocktail/matchers/any.rb +27 -0
  92. data/lib/mocktail/sorbet/mocktail/matchers/base.rb +39 -0
  93. data/lib/mocktail/sorbet/mocktail/matchers/captor.rb +76 -0
  94. data/lib/mocktail/sorbet/mocktail/matchers/includes.rb +32 -0
  95. data/lib/mocktail/sorbet/mocktail/matchers/includes_hash.rb +12 -0
  96. data/lib/mocktail/sorbet/mocktail/matchers/includes_key.rb +12 -0
  97. data/lib/mocktail/sorbet/mocktail/matchers/includes_string.rb +12 -0
  98. data/lib/mocktail/sorbet/mocktail/matchers/is_a.rb +17 -0
  99. data/lib/mocktail/sorbet/mocktail/matchers/matches.rb +19 -0
  100. data/lib/mocktail/sorbet/mocktail/matchers/not.rb +17 -0
  101. data/lib/mocktail/sorbet/mocktail/matchers/numeric.rb +27 -0
  102. data/lib/mocktail/sorbet/mocktail/matchers/that.rb +32 -0
  103. data/lib/mocktail/sorbet/mocktail/matchers.rb +19 -0
  104. data/lib/mocktail/sorbet/mocktail/raises_neato_no_method_error.rb +93 -0
  105. data/lib/mocktail/sorbet/mocktail/records_demonstration.rb +43 -0
  106. data/lib/mocktail/sorbet/mocktail/registers_matcher.rb +65 -0
  107. data/lib/mocktail/sorbet/mocktail/registers_stubbing.rb +31 -0
  108. data/lib/mocktail/sorbet/mocktail/replaces_next.rb +55 -0
  109. data/lib/mocktail/sorbet/mocktail/replaces_type/redefines_new.rb +32 -0
  110. data/lib/mocktail/sorbet/mocktail/replaces_type/redefines_singleton_methods.rb +80 -0
  111. data/lib/mocktail/sorbet/mocktail/replaces_type/runs_sorbet_sig_blocks_before_replacement.rb +39 -0
  112. data/lib/mocktail/sorbet/mocktail/replaces_type.rb +36 -0
  113. data/lib/mocktail/sorbet/mocktail/resets_state.rb +14 -0
  114. data/lib/mocktail/sorbet/mocktail/share/bind.rb +18 -0
  115. data/lib/mocktail/sorbet/mocktail/share/cleans_backtrace.rb +22 -0
  116. data/lib/mocktail/sorbet/mocktail/share/creates_identifier.rb +39 -0
  117. data/lib/mocktail/sorbet/mocktail/share/determines_matching_calls.rb +72 -0
  118. data/lib/mocktail/sorbet/mocktail/share/stringifies_call.rb +85 -0
  119. data/lib/mocktail/sorbet/mocktail/share/stringifies_method_name.rb +16 -0
  120. data/lib/mocktail/sorbet/mocktail/simulates_argument_error/reconciles_args_with_params.rb +27 -0
  121. data/lib/mocktail/sorbet/mocktail/simulates_argument_error/recreates_message.rb +34 -0
  122. data/lib/mocktail/sorbet/mocktail/simulates_argument_error/transforms_params.rb +58 -0
  123. data/lib/mocktail/sorbet/mocktail/simulates_argument_error.rb +36 -0
  124. data/lib/mocktail/sorbet/mocktail/sorbet.rb +3 -0
  125. data/lib/mocktail/sorbet/mocktail/stringifies_method_signature.rb +53 -0
  126. data/lib/mocktail/sorbet/mocktail/typed.rb +5 -0
  127. data/lib/mocktail/sorbet/mocktail/value/cabinet.rb +91 -0
  128. data/lib/mocktail/sorbet/mocktail/value/call.rb +51 -0
  129. data/lib/mocktail/sorbet/mocktail/value/demo_config.rb +10 -0
  130. data/lib/mocktail/sorbet/mocktail/value/double.rb +10 -0
  131. data/lib/mocktail/sorbet/mocktail/value/double_data.rb +15 -0
  132. data/lib/mocktail/sorbet/mocktail/value/explanation.rb +68 -0
  133. data/lib/mocktail/sorbet/mocktail/value/explanation_data.rb +19 -0
  134. data/lib/mocktail/sorbet/mocktail/value/fake_method_data.rb +11 -0
  135. data/lib/mocktail/sorbet/mocktail/value/matcher_registry.rb +27 -0
  136. data/lib/mocktail/sorbet/mocktail/value/no_explanation_data.rb +20 -0
  137. data/lib/mocktail/sorbet/mocktail/value/signature.rb +35 -0
  138. data/lib/mocktail/sorbet/mocktail/value/stubbing.rb +26 -0
  139. data/lib/mocktail/sorbet/mocktail/value/top_shelf.rb +79 -0
  140. data/lib/mocktail/sorbet/mocktail/value/type_replacement.rb +11 -0
  141. data/lib/mocktail/sorbet/mocktail/value/type_replacement_data.rb +19 -0
  142. data/lib/mocktail/sorbet/mocktail/value/unsatisfying_call.rb +9 -0
  143. data/lib/mocktail/sorbet/mocktail/value/unsatisfying_call_explanation.rb +24 -0
  144. data/lib/mocktail/sorbet/mocktail/value.rb +19 -0
  145. data/lib/mocktail/sorbet/mocktail/verifies_call/finds_verifiable_calls.rb +21 -0
  146. data/lib/mocktail/sorbet/mocktail/verifies_call/raises_verification_error/gathers_calls_of_method.rb +15 -0
  147. data/lib/mocktail/sorbet/mocktail/verifies_call/raises_verification_error.rb +74 -0
  148. data/lib/mocktail/sorbet/mocktail/verifies_call.rb +37 -0
  149. data/lib/mocktail/sorbet/mocktail/version.rb +12 -0
  150. data/lib/mocktail/sorbet/mocktail.rb +154 -0
  151. data/lib/mocktail/sorbet.rb +1 -0
  152. data/lib/mocktail/stringifies_method_signature.rb +2 -0
  153. data/lib/mocktail/typed.rb +3 -0
  154. data/lib/mocktail/value/cabinet.rb +8 -1
  155. data/lib/mocktail/value/call.rb +44 -12
  156. data/lib/mocktail/value/demo_config.rb +6 -7
  157. data/lib/mocktail/value/double.rb +6 -7
  158. data/lib/mocktail/value/double_data.rb +11 -7
  159. data/lib/mocktail/value/explanation.rb +28 -3
  160. data/lib/mocktail/value/explanation_data.rb +14 -0
  161. data/lib/mocktail/value/fake_method_data.rb +7 -6
  162. data/lib/mocktail/value/matcher_registry.rb +2 -0
  163. data/lib/mocktail/value/no_explanation_data.rb +16 -0
  164. data/lib/mocktail/value/signature.rb +19 -27
  165. data/lib/mocktail/value/stubbing.rb +11 -12
  166. data/lib/mocktail/value/top_shelf.rb +5 -0
  167. data/lib/mocktail/value/type_replacement.rb +7 -8
  168. data/lib/mocktail/value/type_replacement_data.rb +10 -7
  169. data/lib/mocktail/value/unsatisfying_call.rb +5 -6
  170. data/lib/mocktail/value/unsatisfying_call_explanation.rb +18 -0
  171. data/lib/mocktail/value.rb +5 -2
  172. data/lib/mocktail/verifies_call/finds_verifiable_calls.rb +2 -0
  173. data/lib/mocktail/verifies_call/raises_verification_error/gathers_calls_of_method.rb +2 -0
  174. data/lib/mocktail/verifies_call/raises_verification_error.rb +2 -0
  175. data/lib/mocktail/verifies_call.rb +3 -0
  176. data/lib/mocktail/version.rb +8 -1
  177. data/lib/mocktail.rb +46 -5
  178. data/mocktail.gemspec +8 -4
  179. data/rbi/mocktail-pregenerated.rbi +1865 -0
  180. data/rbi/mocktail.rbi +77 -0
  181. data/rbi/sorbet-runtime.rbi +29 -0
  182. data/spoom_report.html +1248 -0
  183. metadata +130 -3
@@ -1,16 +1,14 @@
1
1
  module Mocktail
2
- Stubbing = Struct.new(
3
- :demonstration,
4
- :demo_config,
5
- :satisfaction_count,
6
- :recording,
7
- :effect,
8
- keyword_init: true
9
- ) do
10
- def initialize(**kwargs)
11
- super
12
- self.satisfaction_count ||= 0
13
- end
2
+ class Stubbing < T::Struct
3
+ extend T::Sig
4
+ extend T::Generic
5
+ MethodReturnType = type_member
6
+
7
+ const :demonstration
8
+ const :demo_config
9
+ prop :satisfaction_count, default: 0
10
+ const :recording
11
+ prop :effect
14
12
 
15
13
  def satisfied!
16
14
  self.satisfaction_count += 1
@@ -18,6 +16,7 @@ module Mocktail
18
16
 
19
17
  def with(&block)
20
18
  self.effect = block
19
+ nil
21
20
  end
22
21
  end
23
22
  end
@@ -1,5 +1,10 @@
1
1
  module Mocktail
2
+ # The TopShelf is where we keep all the more global, dangerous state.
3
+ # In particular, this is where Mocktail manages state related to singleton
4
+ # method replacements carried out with Mocktail.replace(ClassOrModule)
2
5
  class TopShelf
6
+ extend T::Sig
7
+
3
8
  def self.instance
4
9
  Thread.current[:mocktail_top_shelf] ||= new
5
10
  end
@@ -1,10 +1,9 @@
1
1
  module Mocktail
2
- TypeReplacement = Struct.new(
3
- :type,
4
- :original_methods,
5
- :replacement_methods,
6
- :original_new,
7
- :replacement_new,
8
- keyword_init: true
9
- )
2
+ class TypeReplacement < T::Struct
3
+ const :type
4
+ prop :original_methods
5
+ prop :replacement_methods
6
+ prop :original_new
7
+ prop :replacement_new
8
+ end
10
9
  end
@@ -1,11 +1,14 @@
1
1
  module Mocktail
2
- TypeReplacementData = Struct.new(
3
- :type,
4
- :replaced_method_names,
5
- :calls,
6
- :stubbings,
7
- keyword_init: true
8
- ) do
2
+ class TypeReplacementData < T::Struct
3
+ extend T::Sig
4
+
5
+ const :type
6
+ const :replaced_method_names
7
+ const :calls
8
+ const :stubbings
9
+
10
+ include ExplanationData
11
+
9
12
  def double
10
13
  type
11
14
  end
@@ -1,8 +1,7 @@
1
1
  module Mocktail
2
- UnsatisfyingCall = Struct.new(
3
- :call,
4
- :other_stubbings,
5
- :backtrace,
6
- keyword_init: true
7
- )
2
+ class UnsatisfyingCall < T::Struct
3
+ const :call
4
+ const :other_stubbings
5
+ const :backtrace
6
+ end
8
7
  end
@@ -0,0 +1,18 @@
1
+ module Mocktail
2
+ class UnsatisfyingCallExplanation
3
+ extend T::Sig
4
+
5
+ attr_reader :reference
6
+
7
+ attr_reader :message
8
+
9
+ def initialize(reference, message)
10
+ @reference = reference
11
+ @message = message
12
+ end
13
+
14
+ def type
15
+ self.class
16
+ end
17
+ end
18
+ end
@@ -1,14 +1,17 @@
1
1
  require_relative "value/cabinet"
2
2
  require_relative "value/call"
3
3
  require_relative "value/demo_config"
4
+ require_relative "value/explanation"
5
+ require_relative "value/explanation_data"
4
6
  require_relative "value/double"
5
7
  require_relative "value/double_data"
6
- require_relative "value/explanation"
7
8
  require_relative "value/fake_method_data"
8
9
  require_relative "value/matcher_registry"
10
+ require_relative "value/no_explanation_data"
9
11
  require_relative "value/signature"
10
12
  require_relative "value/stubbing"
11
- require_relative "value/top_shelf"
12
13
  require_relative "value/type_replacement"
13
14
  require_relative "value/type_replacement_data"
15
+ require_relative "value/unsatisfying_call_explanation"
14
16
  require_relative "value/unsatisfying_call"
17
+ require_relative "value/top_shelf"
@@ -2,6 +2,8 @@ require_relative "../share/determines_matching_calls"
2
2
 
3
3
  module Mocktail
4
4
  class FindsVerifiableCalls
5
+ extend T::Sig
6
+
5
7
  def initialize
6
8
  @determines_matching_calls = DeterminesMatchingCalls.new
7
9
  end
@@ -1,5 +1,7 @@
1
1
  module Mocktail
2
2
  class GathersCallsOfMethod
3
+ extend T::Sig
4
+
3
5
  def gather(dry_call)
4
6
  Mocktail.cabinet.calls.select { |call|
5
7
  call.double == dry_call.double &&
@@ -4,6 +4,8 @@ require_relative "../share/stringifies_call"
4
4
 
5
5
  module Mocktail
6
6
  class RaisesVerificationError
7
+ extend T::Sig
8
+
7
9
  def initialize
8
10
  @gathers_calls_of_method = GathersCallsOfMethod.new
9
11
  @stringifies_method_name = StringifiesMethodName.new
@@ -4,6 +4,8 @@ require_relative "verifies_call/raises_verification_error"
4
4
 
5
5
  module Mocktail
6
6
  class VerifiesCall
7
+ extend T::Sig
8
+
7
9
  def initialize
8
10
  @records_demonstration = RecordsDemonstration.new
9
11
  @finds_verifiable_calls = FindsVerifiableCalls.new
@@ -17,6 +19,7 @@ module Mocktail
17
19
  unless verification_satisfied?(verifiable_calls.size, demo_config)
18
20
  @raises_verification_error.raise(recording, verifiable_calls, demo_config)
19
21
  end
22
+ nil
20
23
  end
21
24
 
22
25
  private
@@ -1,3 +1,10 @@
1
1
  module Mocktail
2
- VERSION = "1.2.3"
2
+ # The gemspec will define Module::VERSION as loaded from lib/, but if the
3
+ # user loads mocktail/sorbet, its version file will be effectively redefining
4
+ # it. Undef it first to ensure we don't spew warnings
5
+ if defined?(VERSION)
6
+ Mocktail.send(:remove_const, :VERSION)
7
+ end
8
+
9
+ VERSION = "2.0.0"
3
10
  end
data/lib/mocktail.rb CHANGED
@@ -1,9 +1,23 @@
1
+ require "pathname"
2
+
3
+ if defined?(Mocktail::TYPED)
4
+ if eval("Mocktail::TYPED", binding, __FILE__, __LINE__)
5
+ warn "`require \"mocktail\"' was called, but Mocktail was already required as `require \"mocktail/sorbet\"', so we're NOT going to load it to avoid constants from being redefined. If you want to use Mocktail WITHOUT sorbet runtime checks, remove whatever is requiring `mocktail/sorbet'."
6
+ else
7
+ warn "`require \"mocktail/sorbet\"' was called, but Mocktail was already required as `require \"mocktail\"', so we're NOT going to load it to avoid constants from being redefined. If you want to use Mocktail WITH sorbet runtime checks, remove whatever is requiring `mocktail'."
8
+ end
9
+ return
10
+ end
11
+
12
+ require_relative "mocktail/initialize_based_on_type_system_mode_switching"
13
+
1
14
  require_relative "mocktail/collects_calls"
2
15
  require_relative "mocktail/debug"
3
16
  require_relative "mocktail/dsl"
4
17
  require_relative "mocktail/errors"
5
18
  require_relative "mocktail/explains_thing"
6
19
  require_relative "mocktail/explains_nils"
20
+ require_relative "mocktail/grabs_original_method_parameters"
7
21
  require_relative "mocktail/handles_dry_call"
8
22
  require_relative "mocktail/handles_dry_new_call"
9
23
  require_relative "mocktail/imitates_type"
@@ -23,20 +37,44 @@ require_relative "mocktail/verifies_call"
23
37
  require_relative "mocktail/version"
24
38
 
25
39
  module Mocktail
40
+ extend T::Sig
41
+ extend DSL
42
+ BASE_PATH = (Pathname.new(__FILE__) + "..").to_s
43
+
26
44
  # Returns an instance of `type` whose implementation is mocked out
45
+
27
46
  def self.of(type)
28
47
  ImitatesType.new.imitate(type)
29
48
  end
30
49
 
31
50
  # Returns an instance of `klass` whose implementation is mocked out AND
32
51
  # stubs its constructor to return that fake the next time klass.new is called
52
+
33
53
  def self.of_next(type, count: 1)
34
- ReplacesNext.new.replace(type, count)
54
+ count ||= 1
55
+ if count == 1
56
+ ReplacesNext.new.replace_once(type)
57
+ elsif !Mocktail::TYPED || T::Private::RuntimeLevels.default_checked_level == :never
58
+ ReplacesNext.new.replace(type, count)
59
+ else
60
+ raise TypeCheckingError.new <<~MSG
61
+ Calling `Mocktail.of_next()' with a `count' value other than 1 is not supported when
62
+ type checking is enabled. There are two ways to fix this:
63
+
64
+ 1. Use `Mocktail.of_next_with_count(type, count)' instead, which will always return
65
+ an array of fake objects.
66
+
67
+ 2. Disable runtime type checking by setting `T::Private::RuntimeLevels.default_checked_level = :never'
68
+ or by setting the envronment variable `SORBET_RUNTIME_DEFAULT_CHECKED_LEVEL=never'
69
+ MSG
70
+ end
35
71
  end
36
72
 
37
- # See lib/mocktail/dsl.rb
38
- define_singleton_method :stubs, DSL.instance_method(:stubs)
39
- define_singleton_method :verify, DSL.instance_method(:verify)
73
+ # An alias of of_next that always returns an array of fakes
74
+
75
+ def self.of_next_with_count(type, count)
76
+ ReplacesNext.new.replace(type, count)
77
+ end
40
78
 
41
79
  def self.matchers
42
80
  MatcherPresentation.new
@@ -52,6 +90,7 @@ module Mocktail
52
90
 
53
91
  # Replaces every singleton method on `type` with a fake, and when instantiated
54
92
  # or included will also fake instance methods
93
+
55
94
  def self.replace(type)
56
95
  ReplacesType.new.replace(type)
57
96
  nil
@@ -72,13 +111,15 @@ module Mocktail
72
111
  # An alias for Mocktail.explain(double).reference.calls
73
112
  # Takes an optional second parameter of the method name to filter only
74
113
  # calls to that method
114
+
75
115
  def self.calls(double, method_name = nil)
76
- CollectsCalls.new.collect(double, method_name)
116
+ CollectsCalls.new.collect(double, method_name&.to_sym)
77
117
  end
78
118
 
79
119
  # Stores most transactional state about calls & stubbing configurations
80
120
  # Anything returned by this is undocumented and could change at any time, so
81
121
  # don't commit code that relies on it!
122
+
82
123
  def self.cabinet
83
124
  Thread.current[:mocktail_store] ||= Cabinet.new
84
125
  end
data/mocktail.gemspec CHANGED
@@ -1,4 +1,8 @@
1
- require_relative "lib/mocktail/version"
1
+ begin
2
+ require_relative "lib/mocktail/version"
3
+ rescue LoadError
4
+ require_relative "src/mocktail/version"
5
+ end
2
6
 
3
7
  Gem::Specification.new do |spec|
4
8
  spec.name = "mocktail"
@@ -18,14 +22,14 @@ Gem::Specification.new do |spec|
18
22
  # Specify which files should be added to the gem when it is released.
19
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
24
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|src|sub_projects|spoom_data|sorbet|script|docs)/}) }
22
26
  end
23
27
  spec.bindir = "exe"
24
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
29
  spec.require_paths = ["lib"]
26
30
 
27
- # Uncomment to register a new dependency of your gem
28
- # spec.add_dependency "example-gem", "~> 1.0"
31
+ spec.add_dependency "sorbet-runtime", "~> 0.5.9204"
32
+ spec.add_dependency "sorbet-eraser", "~> 0.3.1"
29
33
 
30
34
  # For more information and examples about making a new gem, checkout our
31
35
  # guide at: https://bundler.io/guides/creating_gem.html