rr 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +3 -43
  3. data/CHANGES.md +46 -0
  4. data/CREDITS.md +5 -0
  5. data/Gemfile +3 -12
  6. data/README.md +25 -24
  7. data/Rakefile +16 -38
  8. data/doc/02_syntax_comparison.md +1 -0
  9. data/lib/rr/core_ext/array.rb +2 -0
  10. data/lib/rr/core_ext/hash.rb +2 -0
  11. data/lib/rr/deprecations.rb +97 -0
  12. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +1 -1
  13. data/lib/rr/double_definitions/double_injections/instance.rb +2 -2
  14. data/lib/rr/dsl.rb +152 -0
  15. data/lib/rr/injections/method_missing_injection.rb +6 -2
  16. data/lib/rr/integrations/minitest_4.rb +1 -1
  17. data/lib/rr/integrations/minitest_4_active_support.rb +1 -1
  18. data/lib/rr/integrations/rspec/invocation_matcher.rb +0 -8
  19. data/lib/rr/integrations/rspec_2.rb +20 -2
  20. data/lib/rr/recorded_call.rb +29 -0
  21. data/lib/rr/recorded_calls.rb +8 -4
  22. data/lib/rr/space.rb +1 -1
  23. data/lib/rr/spy_verification.rb +13 -5
  24. data/lib/rr/version.rb +1 -1
  25. data/lib/rr/wildcard_matchers.rb +10 -10
  26. data/lib/rr/without_autohook.rb +5 -13
  27. data/rr.gemspec +3 -3
  28. data/spec/defines_spec_suite_tasks.rb +12 -0
  29. data/spec/global_helper.rb +5 -0
  30. data/spec/spec_suite_configuration.rb +1 -7
  31. data/spec/suites.yml +1 -1
  32. data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +133 -33
  33. data/spec/suites/rspec_2/functional/dont_allow_spec.rb +13 -8
  34. data/spec/suites/rspec_2/functional/mock_bang_spec.rb +20 -0
  35. data/spec/suites/rspec_2/functional/mock_instance_of_spec.rb +14 -0
  36. data/spec/suites/rspec_2/functional/mock_instance_of_strong_spec.rb +15 -0
  37. data/spec/suites/rspec_2/functional/mock_proxy_instance_of_spec.rb +15 -0
  38. data/spec/suites/rspec_2/functional/mock_proxy_spec.rb +14 -0
  39. data/spec/suites/rspec_2/functional/mock_spec.rb +8 -232
  40. data/spec/suites/rspec_2/functional/mock_strong_spec.rb +14 -0
  41. data/spec/suites/rspec_2/functional/received_spec.rb +16 -0
  42. data/spec/suites/rspec_2/functional/spy_spec.rb +89 -28
  43. data/spec/suites/rspec_2/functional/stub_bang_spec.rb +20 -0
  44. data/spec/suites/rspec_2/functional/stub_instance_of_spec.rb +15 -0
  45. data/spec/suites/rspec_2/functional/stub_instance_of_strong_spec.rb +15 -0
  46. data/spec/suites/rspec_2/functional/stub_proxy_instance_of_spec.rb +16 -0
  47. data/spec/suites/rspec_2/functional/stub_proxy_spec.rb +45 -0
  48. data/spec/suites/rspec_2/functional/stub_spec.rb +42 -161
  49. data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -0
  50. data/spec/suites/rspec_2/helper.rb +2 -2
  51. data/spec/suites/rspec_2/support/mixins/double_definition_creator_helpers.rb +173 -0
  52. data/spec/suites/rspec_2/support/mixins/mock_definition_creator_helpers.rb +45 -0
  53. data/spec/suites/rspec_2/support/mixins/proxy_definition_creator_helpers.rb +33 -0
  54. data/spec/suites/rspec_2/support/mixins/stub_creator_helpers.rb +43 -0
  55. data/spec/suites/rspec_2/support/mixins/stub_definition_creator_helpers.rb +45 -0
  56. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_never_called_qualifier.rb +39 -0
  57. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_times_called_qualifier.rb +50 -0
  58. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_without_qualifiers.rb +131 -0
  59. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/dont_allow.rb +148 -0
  60. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb +26 -0
  61. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of_strong.rb +28 -0
  62. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_proxy.rb +11 -0
  63. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_strong.rb +37 -0
  64. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mocking.rb +107 -0
  65. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of.rb +32 -0
  66. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb +39 -0
  67. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_proxy.rb +11 -0
  68. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_strong.rb +37 -0
  69. data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stubbing.rb +57 -0
  70. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/array_flatten_bug.rb +35 -0
  71. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/block_form.rb +31 -0
  72. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/comparing_arity.rb +63 -0
  73. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/object_is_proxy.rb +43 -0
  74. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/sequential_invocations.rb +26 -0
  75. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/setting_implementation.rb +51 -0
  76. data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/yields.rb +81 -0
  77. data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +0 -28
  78. data/spec/suites/rspec_2/unit/deprecations_spec.rb +27 -0
  79. data/spec/suites/rspec_2/unit/dsl/double_creators_spec.rb +133 -0
  80. data/spec/suites/rspec_2/unit/dsl/space_spec.rb +99 -0
  81. data/spec/suites/rspec_2/unit/dsl/wildcard_matchers_spec.rb +67 -0
  82. data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +4 -19
  83. data/spec/suites/rspec_2/unit/space_spec.rb +5 -3
  84. data/spec/suites/rspec_2/unit/spy_verification_spec.rb +1 -1
  85. data/spec/support/adapter.rb +1 -1
  86. data/spec/support/adapter_tests/rspec.rb +19 -15
  87. data/spec/support/project/generator.rb +0 -4
  88. metadata +55 -48
  89. data/gemfiles/ruby_18_rspec_1.gemfile +0 -14
  90. data/gemfiles/ruby_18_rspec_1.gemfile.lock +0 -38
  91. data/gemfiles/ruby_18_rspec_1_rails_2.gemfile +0 -18
  92. data/gemfiles/ruby_18_rspec_1_rails_2.gemfile.lock +0 -64
  93. data/gemfiles/ruby_19_rspec_2_rails_3.gemfile +0 -15
  94. data/gemfiles/ruby_19_rspec_2_rails_3.gemfile.lock +0 -123
  95. data/lib/rr/adapters.rb +0 -34
  96. data/lib/rr/adapters/rr_methods.rb +0 -142
  97. data/lib/rr/integrations/rspec_1.rb +0 -46
  98. data/lib/rr/integrations/test_unit_1.rb +0 -63
  99. data/lib/rr/integrations/test_unit_2.rb +0 -17
  100. data/lib/rr/integrations/test_unit_200.rb +0 -27
  101. data/lib/rr/integrations/test_unit_200_active_support.rb +0 -25
  102. data/lib/rr/integrations/test_unit_2_active_support.rb +0 -38
  103. data/spec/suites/rspec_1/helper.rb +0 -24
  104. data/spec/suites/rspec_1/integration/rspec_1_spec.rb +0 -93
  105. data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +0 -102
  106. data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +0 -109
  107. data/spec/suites/rspec_1/spec_helper.rb +0 -3
  108. data/spec/suites/rspec_1_rails_2/integration/astc_rails_2_spec.rb +0 -141
  109. data/spec/suites/rspec_1_rails_2/integration/rspec_1_rails_2_spec.rb +0 -132
  110. data/spec/suites/rspec_1_rails_2/integration/test_unit_1_rails_2_spec.rb +0 -141
  111. data/spec/suites/rspec_1_rails_2/integration/test_unit_2_rails_2_spec.rb +0 -148
  112. data/spec/suites/rspec_1_rails_2/spec_helper.rb +0 -3
  113. data/spec/suites/rspec_2/functional/dsl_spec.rb +0 -13
  114. data/spec/suites/rspec_2/functional/instance_of_spec.rb +0 -14
  115. data/spec/suites/rspec_2/functional/proxy_spec.rb +0 -136
  116. data/spec/suites/rspec_2/functional/strong_spec.rb +0 -79
  117. data/spec/suites/rspec_2/integration/test_unit_200_spec.rb +0 -102
  118. data/spec/suites/rspec_2/integration/test_unit_2_spec.rb +0 -109
  119. data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +0 -135
  120. data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +0 -101
  121. data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +0 -69
  122. data/spec/suites/rspec_2_rails_3/integration/astc_rails_3_spec.rb +0 -141
  123. data/spec/suites/rspec_2_rails_3/integration/minitest_4_rails_3_spec.rb +0 -148
  124. data/spec/suites/rspec_2_rails_3/integration/rspec_2_rails_3_spec.rb +0 -172
  125. data/spec/suites/rspec_2_rails_3/integration/test_unit_200_rails_3_spec.rb +0 -141
  126. data/spec/suites/rspec_2_rails_3/integration/test_unit_2_rails_3_spec.rb +0 -148
  127. data/spec/suites/rspec_2_rails_3/spec_helper.rb +0 -3
  128. data/spec/suites/rspec_2_rails_4/integration/test_unit_200_rails_4_spec.rb +0 -142
  129. data/spec/suites/rspec_2_rails_4/integration/test_unit_2_rails_4_spec.rb +0 -149
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ permutations =
4
+ %w(stub strong).permutation.map { |parts| parts.join('.') } +
5
+ %w(strong)
6
+
7
+ permutations.each do |permutation|
8
+ describe permutation, is_strong: true do
9
+ include_context 'stub + strong'
10
+
11
+ define_method(:double_definition_creator_for) do |object, &block|
12
+ eval(permutation + '(object, &block)')
13
+ end
14
+ end
15
+ end
@@ -24,5 +24,5 @@ RSpec.configure do |c|
24
24
  c.order = :random
25
25
  end
26
26
 
27
- Dir[ File.expand_path('../shared/*.rb', __FILE__) ].each {|fn| require fn }
28
- Dir[ File.expand_path('../support/**/*.rb', __FILE__) ].each {|fn| require fn }
27
+ Dir[ File.expand_path('../shared/*.rb', __FILE__) ].sort.each {|fn| require fn }
28
+ Dir[ File.expand_path('../support/**/*.rb', __FILE__) ].sort.each {|fn| require fn }
@@ -0,0 +1,173 @@
1
+ module DoubleDefinitionCreatorHelpers
2
+ module ClassMethods
3
+ def methods_being_doubled_exist_already?
4
+ metadata[:methods_exist] || supports_proxying? || supports_mocking?
5
+ end
6
+
7
+ def type_of_methods_being_tested
8
+ metadata[:method_type]
9
+ end
10
+
11
+ def supports_proxying?
12
+ metadata[:is_proxy]
13
+ end
14
+
15
+ def supports_instance_of?
16
+ metadata[:is_instance_of]
17
+ end
18
+
19
+ def supports_mocking?
20
+ metadata[:is_mock]
21
+ end
22
+
23
+ def supports_strong?
24
+ metadata[:is_strong]
25
+ end
26
+
27
+ def supports_dont_allow?
28
+ metadata[:is_dont_allow]
29
+ end
30
+ end
31
+
32
+ def self.included(base)
33
+ base.extend(ClassMethods)
34
+ end
35
+
36
+ def build_object_with_possible_methods(methods = {}, actually_add_methods = methods_being_doubled_exist_already?)
37
+ subject =
38
+ if type_of_methods_being_tested == :class
39
+ Class.new
40
+ else
41
+ Object.new
42
+ end
43
+
44
+ if actually_add_methods
45
+ if supports_instance_of?
46
+ add_methods_to_class(subject, methods)
47
+ else
48
+ add_methods_to_class(subject.singleton_class, methods)
49
+ end
50
+ end
51
+
52
+ object =
53
+ if type_of_methods_being_tested == :class && supports_instance_of?
54
+ subject.new
55
+ else
56
+ subject
57
+ end
58
+
59
+ if block_given?
60
+ yield subject, object
61
+ end
62
+
63
+ object
64
+ end
65
+
66
+ def build_object_with_methods(methods = {}, &block)
67
+ build_object_with_possible_methods(methods, true, &block)
68
+ end
69
+ alias_method :build_object, :build_object_with_methods
70
+
71
+ def add_methods_to_class(klass, methods)
72
+ klass.class_eval do
73
+ methods.each do |method_name, implementation|
74
+ implementation ||= ->(*args) { }
75
+ define_method(method_name, &implementation)
76
+ end
77
+ end
78
+ end
79
+
80
+ def expect_method_to_have_value_or_be_absent(return_value, object, method_name, *args, &block)
81
+ if methods_being_doubled_exist_already?
82
+ expect(object.__send__(method_name, *args, &block)).to eq return_value
83
+ else
84
+ expect_method_to_not_exist(object, method_name)
85
+ end
86
+ end
87
+
88
+ def expect_method_to_not_exist(object, method_name)
89
+ expect { object.method_name }.to raise_error(NoMethodError)
90
+ # Commenting this out for now since this is broken.
91
+ # See: btakita/rr #43
92
+ #expect(object).not_to respond_to(method_name)
93
+ end
94
+
95
+ def build_object_with_doubled_method_which_is_called(original_value, new_value=nil, opts={}, &define_double)
96
+ method_name = :some_method
97
+
98
+ object = build_object_with_methods(method_name => -> { original_value }) do |subject|
99
+ double_creator = double_definition_creator_for(subject)
100
+
101
+ if define_double
102
+ define_double.call(double_creator, method_name, new_value)
103
+ else
104
+ double_creator.__send__(method_name)
105
+ end
106
+ end
107
+
108
+ if opts[:before_method_call]
109
+ opts[:before_method_call].call
110
+ end
111
+
112
+ return_value = object.__send__(method_name)
113
+ [object, method_name, return_value]
114
+ end
115
+
116
+ def build_object_with_doubled_method_which_is_reset_and_called(original_value, new_value, opts={})
117
+ opts = opts.merge(before_method_call: -> { RR.reset })
118
+ build_object_with_doubled_method_which_is_called(original_value, new_value, opts)
119
+ end
120
+
121
+ def call_possible_method_on(object, method_name, *args, &block)
122
+ object.__send__(method_name, *args, &block)
123
+ rescue NoMethodError
124
+ end
125
+
126
+ def expect_call_to_return_or_raise_times_called_error(return_value, object, method_name, *args, &block)
127
+ if supports_dont_allow?
128
+ expect { object.__send__(method_name, *args, &block) }.
129
+ to raise_error(RR::Errors::TimesCalledError)
130
+ else
131
+ expect(object.__send__(method_name, *args, &block)).to eq return_value
132
+ end
133
+ end
134
+
135
+ def call_method_rescuing_times_called_error(object, method_name, *args, &block)
136
+ if supports_dont_allow?
137
+ begin
138
+ object.__send__(method_name, *args, &block)
139
+ rescue RR::Errors::TimesCalledError
140
+ end
141
+ else
142
+ object.__send__(method_name, *args, &block)
143
+ end
144
+ end
145
+
146
+ def methods_being_doubled_exist_already?
147
+ self.class.methods_being_doubled_exist_already?
148
+ end
149
+
150
+ def type_of_methods_being_tested
151
+ self.class.type_of_methods_being_tested
152
+ end
153
+
154
+ def supports_proxying?
155
+ self.class.supports_proxying?
156
+ end
157
+
158
+ def supports_instance_of?
159
+ self.class.supports_instance_of?
160
+ end
161
+
162
+ def supports_mocking?
163
+ self.class.supports_mocking?
164
+ end
165
+
166
+ def supports_strong?
167
+ self.class.supports_strong?
168
+ end
169
+
170
+ def supports_dont_allow?
171
+ self.class.supports_dont_allow?
172
+ end
173
+ end
@@ -0,0 +1,45 @@
1
+ module MockDefinitionCreatorHelpers
2
+ include DoubleDefinitionCreatorHelpers
3
+
4
+ def expect_that_double_can_be_defined_without_block
5
+ _, _, return_value =
6
+ build_object_with_doubled_method_which_is_called('value')
7
+ expect(return_value).to eq nil
8
+ end
9
+
10
+ def expect_that_double_sets_implementation(&block)
11
+ _, _, return_value =
12
+ build_object_with_doubled_method_which_is_called('old value', -> { 'new value' }, &block)
13
+ expect(return_value).to eq 'new value'
14
+ end
15
+
16
+ def expect_that_double_sets_implementation_and_resets(&block)
17
+ object, method_name, return_value =
18
+ build_object_with_doubled_method_which_is_reset_and_called('old value', -> { 'new value' }, &block)
19
+
20
+ if methods_being_doubled_exist_already?
21
+ # This doesn't work quite yet - see btakita#44
22
+ #expect(object).not_to respond_to(method_name)
23
+ else
24
+ expect(return_value).to eq 'old value'
25
+ end
26
+ end
27
+
28
+ def expect_that_double_sets_value(&block)
29
+ _, _, return_value =
30
+ build_object_with_doubled_method_which_is_called('old value', 'new value', &block)
31
+ expect(return_value).to eq 'new value'
32
+ end
33
+
34
+ def expect_that_double_sets_value_and_resets(&block)
35
+ _, _, return_value =
36
+ build_object_with_doubled_method_which_is_reset_and_called('old value', 'new value', &block)
37
+
38
+ if methods_being_doubled_exist_already?
39
+ # This doesn't work quite yet - see btakita#44
40
+ #expect(object).not_to respond_to(method_name)
41
+ else
42
+ expect(return_value).to eq 'old value'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ module ProxyDefinitionCreatorHelpers
2
+ include DoubleDefinitionCreatorHelpers
3
+
4
+ def expect_that_double_can_be_defined_without_block
5
+ _, _, return_value =
6
+ build_object_with_doubled_method_which_is_called('value', nil)
7
+ expect(return_value).to eq 'value'
8
+ end
9
+
10
+ def expect_that_double_sets_implementation(&block)
11
+ _, _, return_value =
12
+ build_object_with_doubled_method_which_is_called('value', ->(v) { v.upcase }, &block)
13
+ expect(return_value).to eq 'VALUE'
14
+ end
15
+
16
+ def expect_that_double_sets_implementation_and_resets(&block)
17
+ _, _, return_value =
18
+ build_object_with_doubled_method_which_is_reset_and_called('value', ->(v) { v.upcase }, &block)
19
+ expect(return_value).to eq 'value'
20
+ end
21
+
22
+ def expect_that_double_sets_value(&block)
23
+ _, _, return_value =
24
+ build_object_with_doubled_method_which_is_called('old value', 'new value', &block)
25
+ expect(return_value).to eq 'new value'
26
+ end
27
+
28
+ def expect_that_double_sets_value_and_resets(&block)
29
+ _, _, return_value =
30
+ build_object_with_doubled_method_which_is_reset_and_called('old value', 'new value', &block)
31
+ expect(return_value).to eq 'old value'
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ module StubDefinitionCreatorHelpers
2
+ def expect_that_double_can_be_defined_without_block
3
+ _, _, return_value =
4
+ build_object_with_doubled_method_which_is_called('value', nil)
5
+ expect(return_value).to eq nil
6
+ end
7
+
8
+ def expect_that_double_sets_implementation(&block)
9
+ _, _, return_value =
10
+ build_object_with_doubled_method_which_is_called('old value', -> { 'new value' }, &block)
11
+ expect(return_value).to eq 'new value'
12
+ end
13
+
14
+ def expect_that_double_sets_implementation_and_resets(&block)
15
+ object, method_name, return_value =
16
+ build_object_with_doubled_method_which_is_reset_and_called('old value', -> { 'new value' }, &block)
17
+
18
+ if methods_being_doubled_exist_already?
19
+ # This doesn't work quite yet - see btakita#44
20
+ #expect(object).not_to respond_to(method_name)
21
+ else
22
+ expect(return_value).to eq 'old value'
23
+ end
24
+ end
25
+
26
+ def expect_that_double_sets_value(&block)
27
+ _, _, return_value =
28
+ build_object_with_doubled_method_which_is_called('old value', 'new value', &block)
29
+ expect(return_value).to eq 'new value'
30
+ end
31
+
32
+ def expect_that_double_sets_value_and_resets(&block)
33
+ _, _, return_value =
34
+ build_object_with_doubled_method_which_is_reset_and_called('old value', 'new value', &block)
35
+
36
+ if methods_being_doubled_exist_already?
37
+ # This doesn't work quite yet - see btakita#44
38
+ #expect(object).not_to respond_to(method_name)
39
+ else
40
+ expect(return_value).to eq 'old value'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ module StubDefinitionCreatorHelpers
2
+ include DoubleDefinitionCreatorHelpers
3
+
4
+ def expect_that_double_can_be_defined_without_block
5
+ _, _, return_value =
6
+ build_object_with_doubled_method_which_is_called('value', nil)
7
+ expect(return_value).to eq nil
8
+ end
9
+
10
+ def expect_that_double_sets_implementation(&block)
11
+ _, _, return_value =
12
+ build_object_with_doubled_method_which_is_called('old value', -> { 'new value' }, &block)
13
+ expect(return_value).to eq 'new value'
14
+ end
15
+
16
+ def expect_that_double_sets_implementation_and_resets(&block)
17
+ object, method_name, return_value =
18
+ build_object_with_doubled_method_which_is_reset_and_called('old value', -> { 'new value' }, &block)
19
+
20
+ if methods_being_doubled_exist_already?
21
+ # This doesn't work quite yet - see btakita#44
22
+ #expect(object).not_to respond_to(method_name)
23
+ else
24
+ expect(return_value).to eq 'old value'
25
+ end
26
+ end
27
+
28
+ def expect_that_double_sets_value(&block)
29
+ _, _, return_value =
30
+ build_object_with_doubled_method_which_is_called('old value', 'new value', &block)
31
+ expect(return_value).to eq 'new value'
32
+ end
33
+
34
+ def expect_that_double_sets_value_and_resets(&block)
35
+ _, _, return_value =
36
+ build_object_with_doubled_method_which_is_reset_and_called('old value', 'new value', &block)
37
+
38
+ if methods_being_doubled_exist_already?
39
+ # This doesn't work quite yet - see btakita#44
40
+ #expect(object).not_to respond_to(method_name)
41
+ else
42
+ expect(return_value).to eq 'old value'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ shared_context 'using 1 of 2 ways to define a mock with an argument expectation with a never-called qualifier' do
2
+ include DoubleDefinitionCreatorHelpers
3
+
4
+ it "works as long as the invocation never occurs" do
5
+ build_object_with_possible_methods(some_method: lambda {|arg| }) do |subject|
6
+ double_creator = double_definition_creator_for(subject)
7
+ define_double_with_argument_expectation(double_creator, :some_method, 1).never
8
+ end
9
+ end
10
+
11
+ it "works as long as the invocation never occurs even if other invocations occur" do
12
+ object = build_object_with_possible_methods(some_method: lambda {|arg| }) do |subject|
13
+ double_creator = double_definition_creator_for(subject)
14
+ define_double_with_argument_expectation(double_creator, :some_method, 1).never
15
+ end
16
+ stub(object).some_method.with_any_args
17
+ object.some_method(2)
18
+ end
19
+
20
+ specify "TimesCalledError is raised as soon as the invocation occurs" do
21
+ object = build_object_with_possible_methods(some_method: lambda {|arg| }) do |subject|
22
+ double_creator = double_definition_creator_for(subject)
23
+ define_double_with_argument_expectation(double_creator, :some_method, 1).never
24
+ end
25
+ expect { object.some_method(1) }.to raise_error(RR::Errors::TimesCalledError)
26
+ RR.reset
27
+ end
28
+
29
+ specify "nothing happens upon being reset" do
30
+ object = build_object_with_possible_methods(some_method: lambda {|arg| }) do |subject|
31
+ double_creator = double_definition_creator_for(subject)
32
+ define_double_with_argument_expectation(double_creator, :some_method, 1).never
33
+ end
34
+ RR.reset
35
+ expect {
36
+ call_possible_method_on(object, :some_method, 1)
37
+ }.not_to raise_error
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ shared_context 'using 1 of 2 ways to define a mock with an argument expectation with a times-called qualifier' do
2
+ include DoubleDefinitionCreatorHelpers
3
+
4
+ context 'upon verification after the invocation occurs too few times' do
5
+ specify "TimesCalledError is raised" do
6
+ object = build_object_with_possible_methods(some_method: ->(arg) {}) do |subject|
7
+ double_creator = double_definition_creator_for(subject)
8
+ define_double_with_argument_expectation(double_creator, :some_method, 1).times(2)
9
+ end
10
+ call_possible_method_on(object, :some_method, 1)
11
+ expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
12
+ end
13
+
14
+ specify "nothing happens upon reset" do
15
+ object = build_object_with_possible_methods(some_method: ->(arg) {}) do |subject|
16
+ double_creator = double_definition_creator_for(subject)
17
+ define_double_with_argument_expectation(double_creator, :some_method, 1).times(2)
18
+ end
19
+ RR.reset
20
+ call_possible_method_on(object, :some_method, 1)
21
+ expect { RR.verify }.not_to raise_error
22
+ end
23
+ end
24
+
25
+ context 'the moment the invocation occurs one too many times' do
26
+ specify "TimesCalledError is raised" do
27
+ object = build_object_with_possible_methods(some_method: ->(arg) {}) do |subject|
28
+ double_creator = double_definition_creator_for(subject)
29
+ define_double_with_argument_expectation(double_creator, :some_method, 1).times(2)
30
+ end
31
+ call_possible_method_on(object, :some_method, 1)
32
+ call_possible_method_on(object, :some_method, 1)
33
+ expect { object.some_method(1) }.to raise_error(RR::Errors::TimesCalledError)
34
+ RR.reset
35
+ end
36
+
37
+ specify "nothing happens upon reset" do
38
+ object = build_object_with_possible_methods(some_method: ->(arg) {}) do |subject|
39
+ double_creator = double_definition_creator_for(subject)
40
+ define_double_with_argument_expectation(double_creator, :some_method, 1).times(2)
41
+ end
42
+ RR.reset
43
+ call_possible_method_on(object, :some_method, 1)
44
+ call_possible_method_on(object, :some_method, 1)
45
+ expect {
46
+ call_possible_method_on(object, :some_method, 1)
47
+ }.not_to raise_error
48
+ end
49
+ end
50
+ end