ultra-fast-box 0.0.1

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 (140) hide show
  1. checksums.yaml +7 -0
  2. data/shoulda-matchers-8.0.1/LICENSE +22 -0
  3. data/shoulda-matchers-8.0.1/README.md +567 -0
  4. data/shoulda-matchers-8.0.1/docs/errors/NonCaseSwappableValueError.md +111 -0
  5. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/callback_matcher.rb +121 -0
  6. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +70 -0
  7. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/flash_store.rb +86 -0
  8. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/permit_matcher.rb +445 -0
  9. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +96 -0
  10. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb +84 -0
  11. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +145 -0
  12. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +115 -0
  13. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +148 -0
  14. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_matcher.rb +207 -0
  15. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_params.rb +62 -0
  16. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
  17. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +228 -0
  18. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_matcher.rb +163 -0
  19. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +107 -0
  20. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller.rb +24 -0
  21. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +45 -0
  22. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb +23 -0
  23. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +232 -0
  24. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +62 -0
  25. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +40 -0
  26. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +48 -0
  27. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_check.rb +14 -0
  28. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_setting.rb +14 -0
  29. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher.rb +695 -0
  30. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/comparison_matcher.rb +157 -0
  31. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +78 -0
  32. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/errors.rb +52 -0
  33. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +125 -0
  34. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/helpers.rb +37 -0
  35. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +45 -0
  36. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +67 -0
  37. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +45 -0
  38. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +44 -0
  39. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb +71 -0
  40. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb +53 -0
  41. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  42. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
  43. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
  44. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb +101 -0
  45. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +21 -0
  46. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers.rb +14 -0
  47. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +180 -0
  48. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +128 -0
  49. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_comparison_of_matcher.rb +567 -0
  50. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +185 -0
  51. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +272 -0
  52. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +664 -0
  53. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +575 -0
  54. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +711 -0
  55. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +428 -0
  56. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +62 -0
  57. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher.rb +195 -0
  58. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_message_finder.rb +63 -0
  59. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validator.rb +127 -0
  60. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model.rb +96 -0
  61. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +217 -0
  62. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matcher.rb +2134 -0
  63. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +74 -0
  64. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +62 -0
  65. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +41 -0
  66. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +105 -0
  67. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +101 -0
  68. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +89 -0
  69. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +142 -0
  70. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +71 -0
  71. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
  72. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +76 -0
  73. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +42 -0
  74. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +65 -0
  75. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  76. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +784 -0
  77. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/encrypt_matcher.rb +174 -0
  78. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_attached_matcher.rb +343 -0
  79. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +366 -0
  80. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +287 -0
  81. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +104 -0
  82. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +95 -0
  83. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
  84. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
  85. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/normalize_matcher.rb +151 -0
  86. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/serialize_matcher.rb +203 -0
  87. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/model.rb +58 -0
  88. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +39 -0
  89. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +49 -0
  90. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +55 -0
  91. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
  92. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1197 -0
  93. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record.rb +37 -0
  94. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/configuration.rb +31 -0
  95. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double.rb +103 -0
  96. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_collection.rb +60 -0
  97. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +31 -0
  98. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/method_call.rb +44 -0
  99. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/object_double.rb +43 -0
  100. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +32 -0
  101. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/stub_implementation.rb +31 -0
  102. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/world.rb +63 -0
  103. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak.rb +38 -0
  104. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/error.rb +29 -0
  105. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +15 -0
  106. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher.rb +540 -0
  107. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent.rb +11 -0
  108. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration.rb +70 -0
  109. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
  110. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
  111. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/action_controller.rb +33 -0
  112. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
  113. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
  114. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
  115. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/rails.rb +31 -0
  116. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/routing.rb +29 -0
  117. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries.rb +16 -0
  118. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/rails.rb +12 -0
  119. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/registry.rb +28 -0
  120. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
  121. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
  122. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
  123. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
  124. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
  125. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
  126. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
  127. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations.rb +43 -0
  128. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_collection.rb +99 -0
  129. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_context.rb +36 -0
  130. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/rails_shim.rb +190 -0
  131. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/routing.rb +10 -0
  132. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util/word_wrap.rb +211 -0
  133. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util.rb +110 -0
  134. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/version.rb +6 -0
  135. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/warn.rb +28 -0
  136. data/shoulda-matchers-8.0.1/lib/shoulda/matchers.rb +25 -0
  137. data/shoulda-matchers-8.0.1/lib/shoulda-matchers.rb +1 -0
  138. data/shoulda-matchers-8.0.1/shoulda-matchers.gemspec +43 -0
  139. data/ultra-fast-box.gemspec +12 -0
  140. metadata +179 -0
@@ -0,0 +1,37 @@
1
+ require 'shoulda/matchers/active_record/association_matcher'
2
+ require 'shoulda/matchers/active_record/association_matchers'
3
+ require 'shoulda/matchers/active_record/association_matchers/counter_cache_matcher'
4
+ require 'shoulda/matchers/active_record/association_matchers/inverse_of_matcher'
5
+ require 'shoulda/matchers/active_record/association_matchers/join_table_matcher'
6
+ require 'shoulda/matchers/active_record/association_matchers/order_matcher'
7
+ require 'shoulda/matchers/active_record/association_matchers/through_matcher'
8
+ require 'shoulda/matchers/active_record/association_matchers/dependent_matcher'
9
+ require 'shoulda/matchers/active_record/association_matchers/required_matcher'
10
+ require 'shoulda/matchers/active_record/association_matchers/optional_matcher'
11
+ require 'shoulda/matchers/active_record/association_matchers/source_matcher'
12
+ require 'shoulda/matchers/active_record/association_matchers/model_reflector'
13
+ require 'shoulda/matchers/active_record/association_matchers/model_reflection'
14
+ require 'shoulda/matchers/active_record/association_matchers/option_verifier'
15
+ require 'shoulda/matchers/active_record/have_db_column_matcher'
16
+ require 'shoulda/matchers/active_record/have_db_index_matcher'
17
+ require 'shoulda/matchers/active_record/have_implicit_order_column'
18
+ require 'shoulda/matchers/active_record/have_readonly_attribute_matcher'
19
+ require 'shoulda/matchers/active_record/have_rich_text_matcher'
20
+ require 'shoulda/matchers/active_record/have_secure_token_matcher'
21
+ require 'shoulda/matchers/active_record/serialize_matcher'
22
+ require 'shoulda/matchers/active_record/accept_nested_attributes_for_matcher'
23
+ require 'shoulda/matchers/active_record/define_enum_for_matcher'
24
+ require 'shoulda/matchers/active_record/uniqueness'
25
+ require 'shoulda/matchers/active_record/validate_uniqueness_of_matcher'
26
+ require 'shoulda/matchers/active_record/have_attached_matcher'
27
+ require 'shoulda/matchers/active_record/normalize_matcher'
28
+ require 'shoulda/matchers/active_record/encrypt_matcher'
29
+
30
+ module Shoulda
31
+ module Matchers
32
+ # This module provides matchers that are used to test behavior within
33
+ # ActiveRecord classes.
34
+ module ActiveRecord
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Shoulda
2
+ module Matchers
3
+ # @private
4
+ def self.configure
5
+ yield configuration
6
+ end
7
+
8
+ # @private
9
+ def self.integrations
10
+ configuration.integrations
11
+ end
12
+
13
+ # @private
14
+ def self.configuration
15
+ @_configuration ||= Configuration.new
16
+ end
17
+
18
+ # @private
19
+ class Configuration
20
+ attr_reader :integrations
21
+
22
+ def initialize
23
+ @integrations = nil
24
+ end
25
+
26
+ def integrate(&block)
27
+ @integrations = Integrations::Configuration.apply(&block)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,103 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class Double
6
+ attr_reader :calls
7
+
8
+ def initialize(world, klass, method_name, implementation)
9
+ @world = world
10
+ @klass = klass
11
+ @method_name = method_name
12
+ @implementation = implementation
13
+ @activated = false
14
+ @calls = []
15
+
16
+ if world.doubles_activated?
17
+ activate
18
+ end
19
+ end
20
+
21
+ def activated?
22
+ @activated
23
+ end
24
+
25
+ def to_return(value = nil, &block)
26
+ if block
27
+ implementation.returns(&block)
28
+ else
29
+ implementation.returns(value)
30
+ end
31
+ end
32
+
33
+ def activate
34
+ unless @activated
35
+ store_original_method
36
+ replace_method_with_double
37
+ @activated = true
38
+ end
39
+ end
40
+
41
+ def deactivate
42
+ if @activated
43
+ restore_original_method
44
+ @activated = false
45
+ end
46
+ end
47
+
48
+ def record_call(call)
49
+ calls << call
50
+ end
51
+
52
+ def call_original_method(call)
53
+ unbound_method = world.original_method_for(klass, call.method_name)
54
+
55
+ if unbound_method
56
+ unbound_method.bind(call.object).call(*call.args, &call.block)
57
+ end
58
+ end
59
+
60
+ protected
61
+
62
+ attr_reader :world, :klass, :method_name, :implementation,
63
+ :original_method
64
+
65
+ def store_original_method
66
+ world.store_original_method_for(klass, method_name)
67
+ end
68
+
69
+ def replace_method_with_double
70
+ double = self
71
+ implementation = @implementation
72
+ _method_name = method_name
73
+
74
+ if klass.instance_methods(false).include?(method_name)
75
+ klass.__send__(:remove_method, method_name)
76
+ end
77
+
78
+ klass.__send__(:define_method, method_name) do |*args, &block|
79
+ call = MethodCall.new(
80
+ double:,
81
+ object: self,
82
+ method_name: _method_name,
83
+ args:,
84
+ block:,
85
+ caller:,
86
+ )
87
+ implementation.call(call)
88
+ end
89
+ end
90
+
91
+ def restore_original_method
92
+ original_method = world.original_method_for(klass, method_name)
93
+
94
+ klass.__send__(:remove_method, method_name)
95
+
96
+ klass.__send__(:define_method, method_name) do |*args, &block|
97
+ original_method.bind(self).call(*args, &block)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,60 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class DoubleCollection
6
+ def initialize(world, klass)
7
+ @world = world
8
+ @klass = klass
9
+ @doubles_by_method_name = {}
10
+ end
11
+
12
+ def register_stub(method_name)
13
+ register_double(method_name, :stub)
14
+ end
15
+
16
+ def register_proxy(method_name)
17
+ register_double(method_name, :proxy)
18
+ end
19
+
20
+ def activate
21
+ doubles_by_method_name.each_value(&:activate)
22
+ end
23
+
24
+ def deactivate
25
+ doubles_by_method_name.each_value(&:deactivate)
26
+ end
27
+
28
+ def calls_by_method_name
29
+ doubles_by_method_name.inject({}) do |hash, (method_name, double)|
30
+ hash.merge! method_name => double.calls.map(&:args)
31
+ end
32
+ end
33
+
34
+ def calls_to(method_name)
35
+ double = doubles_by_method_name[method_name]
36
+
37
+ if double
38
+ double.calls
39
+ else
40
+ []
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ attr_reader :world, :klass, :doubles_by_method_name
47
+
48
+ def register_double(method_name, implementation_type)
49
+ doubles_by_method_name.fetch(method_name) do
50
+ implementation =
51
+ DoubleImplementationRegistry.find(implementation_type)
52
+ double = Double.new(world, klass, method_name, implementation)
53
+ doubles_by_method_name[method_name] = double
54
+ double
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,31 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ module DoubleImplementationRegistry
6
+ class << self
7
+ def find(type)
8
+ find_class!(type).create
9
+ end
10
+
11
+ def register(klass, type)
12
+ registry[type] = klass
13
+ end
14
+
15
+ private
16
+
17
+ def find_class!(type)
18
+ registry.fetch(type) do
19
+ raise ArgumentError, 'No double implementation class found for'\
20
+ " '#{type}'"
21
+ end
22
+ end
23
+
24
+ def registry
25
+ @_registry ||= {}
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,44 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class MethodCall
6
+ attr_accessor :return_value
7
+ attr_reader :method_name, :args, :caller, :block, :object, :double
8
+
9
+ def initialize(args)
10
+ @method_name = args.fetch(:method_name)
11
+ @args = args.fetch(:args)
12
+ @caller = args.fetch(:caller)
13
+ @block = args[:block]
14
+ @double = args[:double]
15
+ @object = args[:object]
16
+ @return_value = nil
17
+ end
18
+
19
+ def with_return_value(return_value)
20
+ dup.tap do |call|
21
+ call.return_value = return_value
22
+ end
23
+ end
24
+
25
+ def ==(other)
26
+ other.is_a?(self.class) &&
27
+ method_name == other.method_name &&
28
+ args == other.args &&
29
+ block == other.block &&
30
+ double == other.double &&
31
+ object == other.object
32
+ end
33
+
34
+ def to_hash
35
+ { method_name:, args: }
36
+ end
37
+
38
+ def inspect
39
+ "#<#{self.class.name} #{to_hash.inspect}>"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class ObjectDouble < BasicObject
6
+ attr_reader :calls
7
+
8
+ def initialize
9
+ @calls = []
10
+ @calls_by_method_name = {}
11
+ end
12
+
13
+ def calls_to(method_name)
14
+ @calls_by_method_name[method_name] || []
15
+ end
16
+
17
+ def respond_to?(_name, _include_private = nil)
18
+ true
19
+ end
20
+
21
+ def respond_to_missing?(_name, _include_all)
22
+ true
23
+ end
24
+
25
+ def method_missing(method_name, *args, &block)
26
+ call = MethodCall.new(
27
+ method_name:,
28
+ args:,
29
+ block:,
30
+ caller: ::Kernel.caller,
31
+ )
32
+ calls << call
33
+ (calls_by_method_name[method_name] ||= []) << call
34
+ nil
35
+ end
36
+
37
+ protected
38
+
39
+ attr_reader :calls_by_method_name
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class ProxyImplementation
6
+ extend Forwardable
7
+
8
+ DoubleImplementationRegistry.register(self, :proxy)
9
+
10
+ def_delegators :stub_implementation, :returns
11
+
12
+ def self.create
13
+ new(StubImplementation.new)
14
+ end
15
+
16
+ def initialize(stub_implementation)
17
+ @stub_implementation = stub_implementation
18
+ end
19
+
20
+ def call(call)
21
+ return_value = call.double.call_original_method(call)
22
+ stub_implementation.call(call.with_return_value(return_value))
23
+ return_value
24
+ end
25
+
26
+ protected
27
+
28
+ attr_reader :stub_implementation
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class StubImplementation
6
+ DoubleImplementationRegistry.register(self, :stub)
7
+
8
+ def self.create
9
+ new
10
+ end
11
+
12
+ def initialize
13
+ @implementation = proc { nil }
14
+ end
15
+
16
+ def returns(value = nil, &block)
17
+ @implementation = block || proc { value }
18
+ end
19
+
20
+ def call(call)
21
+ call.double.record_call(call)
22
+ implementation.call(call)
23
+ end
24
+
25
+ protected
26
+
27
+ attr_reader :implementation
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Doublespeak
4
+ # @private
5
+ class World
6
+ def initialize
7
+ @doubles_activated = false
8
+ end
9
+
10
+ def double_collection_for(klass)
11
+ double_collections_by_class[klass] ||=
12
+ DoubleCollection.new(self, klass)
13
+ end
14
+
15
+ def store_original_method_for(klass, method_name)
16
+ original_methods_for_class(klass)[method_name] ||=
17
+ klass.instance_method(method_name)
18
+ end
19
+
20
+ def original_method_for(klass, method_name)
21
+ if original_methods_by_class.key?(klass)
22
+ original_methods_by_class[klass][method_name]
23
+ end
24
+ end
25
+
26
+ def with_doubles_activated
27
+ @doubles_activated = true
28
+ activate
29
+ yield
30
+ ensure
31
+ @doubles_activated = false
32
+ deactivate
33
+ end
34
+
35
+ def doubles_activated?
36
+ @doubles_activated
37
+ end
38
+
39
+ private
40
+
41
+ def activate
42
+ double_collections_by_class.each_value(&:activate)
43
+ end
44
+
45
+ def deactivate
46
+ double_collections_by_class.each_value(&:deactivate)
47
+ end
48
+
49
+ def double_collections_by_class
50
+ @_double_collections_by_class ||= {}
51
+ end
52
+
53
+ def original_methods_by_class
54
+ @_original_methods_by_class ||= {}
55
+ end
56
+
57
+ def original_methods_for_class(klass)
58
+ original_methods_by_class[klass] ||= {}
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,38 @@
1
+ require 'forwardable'
2
+
3
+ module Shoulda
4
+ module Matchers
5
+ # @private
6
+ module Doublespeak
7
+ class << self
8
+ extend Forwardable
9
+
10
+ def_delegators :world, :double_collection_for,
11
+ :with_doubles_activated
12
+
13
+ def world
14
+ @_world ||= World.new
15
+ end
16
+
17
+ def debugging_enabled?
18
+ ENV['DEBUG_DOUBLESPEAK'] == '1'
19
+ end
20
+
21
+ def debug(&block)
22
+ if debugging_enabled?
23
+ puts block.call # rubocop:disable Rails/Output
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ require 'shoulda/matchers/doublespeak/double'
32
+ require 'shoulda/matchers/doublespeak/double_collection'
33
+ require 'shoulda/matchers/doublespeak/double_implementation_registry'
34
+ require 'shoulda/matchers/doublespeak/method_call'
35
+ require 'shoulda/matchers/doublespeak/object_double'
36
+ require 'shoulda/matchers/doublespeak/proxy_implementation'
37
+ require 'shoulda/matchers/doublespeak/stub_implementation'
38
+ require 'shoulda/matchers/doublespeak/world'
@@ -0,0 +1,29 @@
1
+ module Shoulda
2
+ module Matchers
3
+ # @private
4
+ class Error < StandardError
5
+ def self.create(attributes)
6
+ allocate.tap do |error|
7
+ attributes.each do |name, value|
8
+ error.__send__("#{name}=", value)
9
+ end
10
+
11
+ error.__send__(:initialize)
12
+ end
13
+ end
14
+
15
+ def initialize(*args)
16
+ super
17
+ @message = message
18
+ end
19
+
20
+ def message
21
+ ''
22
+ end
23
+
24
+ def inspect
25
+ %(#<#{self.class}: #{message}>)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module Independent
4
+ class DelegateMethodMatcher
5
+ # @private
6
+ class DelegateObjectNotSpecified < StandardError
7
+ def message
8
+ 'Delegation needs a target. Use the #to method to define one, e.g.
9
+ `post_office.should delegate(:deliver_mail).to(:mailman)`'.squish
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end