opal-rspec-cj 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.gitmodules +15 -0
  4. data/.travis.yml +13 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +25 -0
  7. data/Gemfile +8 -0
  8. data/README.md +147 -0
  9. data/Rakefile +26 -0
  10. data/config.ru +10 -0
  11. data/example/Gemfile +4 -0
  12. data/example/README.md +13 -0
  13. data/example/Rakefile +8 -0
  14. data/example/opal/user.rb +11 -0
  15. data/example/spec/user_spec.rb +15 -0
  16. data/lib/opal-rspec.rb +2 -0
  17. data/lib/opal/rspec.rb +20 -0
  18. data/lib/opal/rspec/rake_task.rb +63 -0
  19. data/lib/opal/rspec/version.rb +5 -0
  20. data/opal-rspec.gemspec +21 -0
  21. data/opal/opal-rspec.rb +1 -0
  22. data/opal/opal/rspec.rb +25 -0
  23. data/opal/opal/rspec/async.rb +289 -0
  24. data/opal/opal/rspec/browser_formatter.rb +188 -0
  25. data/opal/opal/rspec/fixes.rb +116 -0
  26. data/opal/opal/rspec/requires.rb +45 -0
  27. data/opal/opal/rspec/runner.rb +69 -0
  28. data/opal/opal/rspec/sprockets_runner.rb.erb +11 -0
  29. data/opal/opal/rspec/text_formatter.rb +74 -0
  30. data/spec/async_spec.rb +38 -0
  31. data/spec/example_spec.rb +163 -0
  32. data/spec/matchers_spec.rb +201 -0
  33. data/spec/mock_spec.rb +63 -0
  34. data/spec/named_subject_spec.rb +11 -0
  35. data/spec/should_syntax_spec.rb +17 -0
  36. data/vendor/spec_runner.js +50 -0
  37. data/vendor_lib/rspec-expectations.rb +1 -0
  38. data/vendor_lib/rspec.rb +3 -0
  39. data/vendor_lib/rspec/autorun.rb +2 -0
  40. data/vendor_lib/rspec/core.rb +203 -0
  41. data/vendor_lib/rspec/core/backport_random.rb +302 -0
  42. data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
  43. data/vendor_lib/rspec/core/command_line.rb +36 -0
  44. data/vendor_lib/rspec/core/configuration.rb +1129 -0
  45. data/vendor_lib/rspec/core/configuration_options.rb +143 -0
  46. data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
  47. data/vendor_lib/rspec/core/drb_options.rb +87 -0
  48. data/vendor_lib/rspec/core/dsl.rb +26 -0
  49. data/vendor_lib/rspec/core/example.rb +312 -0
  50. data/vendor_lib/rspec/core/example_group.rb +540 -0
  51. data/vendor_lib/rspec/core/filter_manager.rb +224 -0
  52. data/vendor_lib/rspec/core/flat_map.rb +17 -0
  53. data/vendor_lib/rspec/core/formatters.rb +54 -0
  54. data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
  55. data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
  56. data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
  57. data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
  58. data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
  59. data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
  60. data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
  61. data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
  62. data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
  63. data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
  64. data/vendor_lib/rspec/core/hooks.rb +535 -0
  65. data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
  66. data/vendor_lib/rspec/core/metadata.rb +313 -0
  67. data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
  68. data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
  69. data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
  70. data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
  71. data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
  72. data/vendor_lib/rspec/core/option_parser.rb +234 -0
  73. data/vendor_lib/rspec/core/ordering.rb +154 -0
  74. data/vendor_lib/rspec/core/pending.rb +110 -0
  75. data/vendor_lib/rspec/core/project_initializer.rb +88 -0
  76. data/vendor_lib/rspec/core/rake_task.rb +128 -0
  77. data/vendor_lib/rspec/core/reporter.rb +132 -0
  78. data/vendor_lib/rspec/core/ruby_project.rb +44 -0
  79. data/vendor_lib/rspec/core/runner.rb +97 -0
  80. data/vendor_lib/rspec/core/shared_context.rb +53 -0
  81. data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
  82. data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
  83. data/vendor_lib/rspec/core/version.rb +7 -0
  84. data/vendor_lib/rspec/core/warnings.rb +22 -0
  85. data/vendor_lib/rspec/core/world.rb +131 -0
  86. data/vendor_lib/rspec/expectations.rb +75 -0
  87. data/vendor_lib/rspec/expectations/differ.rb +154 -0
  88. data/vendor_lib/rspec/expectations/errors.rb +9 -0
  89. data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
  90. data/vendor_lib/rspec/expectations/extensions.rb +1 -0
  91. data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
  92. data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
  93. data/vendor_lib/rspec/expectations/handler.rb +68 -0
  94. data/vendor_lib/rspec/expectations/syntax.rb +182 -0
  95. data/vendor_lib/rspec/expectations/version.rb +8 -0
  96. data/vendor_lib/rspec/matchers.rb +633 -0
  97. data/vendor_lib/rspec/matchers/built_in.rb +39 -0
  98. data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
  99. data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
  100. data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
  101. data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
  102. data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
  103. data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
  104. data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
  105. data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
  106. data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
  107. data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
  108. data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
  109. data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
  110. data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
  111. data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
  112. data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
  113. data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
  114. data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
  115. data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
  116. data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
  117. data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
  118. data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
  119. data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
  120. data/vendor_lib/rspec/matchers/configuration.rb +113 -0
  121. data/vendor_lib/rspec/matchers/dsl.rb +23 -0
  122. data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
  123. data/vendor_lib/rspec/matchers/matcher.rb +301 -0
  124. data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
  125. data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
  126. data/vendor_lib/rspec/matchers/pretty.rb +70 -0
  127. data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
  128. data/vendor_lib/rspec/mocks.rb +100 -0
  129. data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
  130. data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
  131. data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
  132. data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
  133. data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
  134. data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  135. data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
  136. data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
  137. data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
  138. data/vendor_lib/rspec/mocks/configuration.rb +111 -0
  139. data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
  140. data/vendor_lib/rspec/mocks/errors.rb +12 -0
  141. data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
  142. data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
  143. data/vendor_lib/rspec/mocks/framework.rb +36 -0
  144. data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
  145. data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
  146. data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
  147. data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  148. data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
  149. data/vendor_lib/rspec/mocks/method_double.rb +209 -0
  150. data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
  151. data/vendor_lib/rspec/mocks/mock.rb +7 -0
  152. data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
  153. data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
  154. data/vendor_lib/rspec/mocks/order_group.rb +82 -0
  155. data/vendor_lib/rspec/mocks/proxy.rb +269 -0
  156. data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
  157. data/vendor_lib/rspec/mocks/space.rb +95 -0
  158. data/vendor_lib/rspec/mocks/standalone.rb +3 -0
  159. data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
  160. data/vendor_lib/rspec/mocks/syntax.rb +374 -0
  161. data/vendor_lib/rspec/mocks/targets.rb +90 -0
  162. data/vendor_lib/rspec/mocks/test_double.rb +109 -0
  163. data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
  164. data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  165. data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
  166. data/vendor_lib/rspec/mocks/version.rb +7 -0
  167. data/vendor_lib/rspec/support.rb +6 -0
  168. data/vendor_lib/rspec/support/caller_filter.rb +56 -0
  169. data/vendor_lib/rspec/support/spec.rb +14 -0
  170. data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
  171. data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
  172. data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
  173. data/vendor_lib/rspec/support/version.rb +7 -0
  174. data/vendor_lib/rspec/support/warnings.rb +41 -0
  175. data/vendor_lib/rspec/version.rb +5 -0
  176. metadata +268 -0
@@ -0,0 +1,17 @@
1
+ module Marshal
2
+ class << self
3
+ # Duplicates any mock objects before serialization. Otherwise,
4
+ # serialization will fail because methods exist on the singleton class.
5
+ def dump_with_mocks(object, *rest)
6
+ if ::RSpec::Mocks.space.nil? || !::RSpec::Mocks.space.registered?(object) || NilClass === object
7
+ dump_without_mocks(object, *rest)
8
+ else
9
+ dump_without_mocks(object.dup, *rest)
10
+ end
11
+ end
12
+
13
+ alias_method :dump_without_mocks, :dump
14
+ undef_method :dump
15
+ alias_method :dump, :dump_with_mocks
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # Require everything except the global extensions of class and object. This
2
+ # supports wrapping rspec's mocking functionality without invading every
3
+ # object in the system.
4
+
5
+ require 'rspec/support/caller_filter'
6
+ require 'rspec/support/warnings'
7
+ require 'rspec/mocks/instance_method_stasher'
8
+ require 'rspec/mocks/method_double'
9
+ require 'rspec/mocks/argument_matchers'
10
+ require 'rspec/mocks/example_methods'
11
+ require 'rspec/mocks/proxy'
12
+ require 'rspec/mocks/proxy_for_nil'
13
+ require 'rspec/mocks/test_double'
14
+ require 'rspec/mocks/mock'
15
+ require 'rspec/mocks/argument_list_matcher'
16
+ require 'rspec/mocks/message_expectation'
17
+ require 'rspec/mocks/order_group'
18
+ require 'rspec/mocks/errors'
19
+ require 'rspec/mocks/error_generator'
20
+ require 'rspec/mocks/space'
21
+ require 'rspec/mocks/extensions/marshal'
22
+ require 'rspec/mocks/any_instance/chain'
23
+ require 'rspec/mocks/any_instance/stub_chain'
24
+ require 'rspec/mocks/any_instance/stub_chain_chain'
25
+ require 'rspec/mocks/any_instance/expectation_chain'
26
+ require 'rspec/mocks/any_instance/message_chains'
27
+ require 'rspec/mocks/any_instance/recorder'
28
+ require 'rspec/mocks/mutate_const'
29
+ require 'rspec/mocks/matchers/have_received'
30
+ require 'rspec/mocks/matchers/receive'
31
+ require 'rspec/mocks/matchers/receive_messages'
32
+ require 'rspec/mocks/stub_chain'
33
+ require 'rspec/mocks/targets'
34
+ require 'rspec/mocks/syntax'
35
+ require 'rspec/mocks/configuration'
36
+ require 'rspec/mocks/verifying_double'
@@ -0,0 +1,112 @@
1
+ module RSpec
2
+ module Mocks
3
+ # @private
4
+ class InstanceMethodStasher
5
+ def initialize(object, method)
6
+ @object = object
7
+ @method = method
8
+ @klass = (class << object; self; end)
9
+
10
+ @original_method = nil
11
+ @method_is_stashed = false
12
+ end
13
+
14
+ attr_reader :original_method
15
+
16
+ if RUBY_VERSION.to_f < 1.9
17
+ # @private
18
+ def method_is_stashed?
19
+ @method_is_stashed
20
+ end
21
+
22
+ # @private
23
+ def stash
24
+ return if !method_defined_directly_on_klass? || @method_is_stashed
25
+
26
+ @klass.__send__(:alias_method, stashed_method_name, @method)
27
+ @method_is_stashed = true
28
+ end
29
+
30
+ # @private
31
+ def stashed_method_name
32
+ "obfuscated_by_rspec_mocks__#{@method}"
33
+ end
34
+ private :stashed_method_name
35
+
36
+ # @private
37
+ def restore
38
+ return unless @method_is_stashed
39
+
40
+ if @klass.__send__(:method_defined?, @method)
41
+ @klass.__send__(:undef_method, @method)
42
+ end
43
+ @klass.__send__(:alias_method, @method, stashed_method_name)
44
+ @klass.__send__(:remove_method, stashed_method_name)
45
+ @method_is_stashed = false
46
+ end
47
+ else
48
+
49
+ # @private
50
+ def method_is_stashed?
51
+ !!@original_method
52
+ end
53
+
54
+ # @private
55
+ def stash
56
+ return if !method_defined_directly_on_klass?
57
+ @original_method ||= ::RSpec::Mocks.method_handle_for(@object, @method)
58
+ end
59
+
60
+ # @private
61
+ def restore
62
+ return unless @original_method
63
+
64
+ if @klass.__send__(:method_defined?, @method)
65
+ @klass.__send__(:undef_method, @method)
66
+ end
67
+
68
+ @klass.__send__(:define_method, @method, @original_method)
69
+ @original_method = nil
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ # @private
76
+ def method_defined_directly_on_klass?
77
+ method_defined_on_klass? && method_owned_by_klass?
78
+ end
79
+
80
+ # @private
81
+ def method_defined_on_klass?(klass = @klass)
82
+ klass.method_defined?(@method) || klass.private_method_defined?(@method)
83
+ end
84
+
85
+ def method_owned_by_klass?
86
+ owner = @klass.instance_method(@method).owner
87
+
88
+ # On Ruby 2.0.0+ the owner of a method on a class which has been
89
+ # `prepend`ed may actually be an instance, e.g.
90
+ # `#<MyClass:0x007fbb94e3cd10>`, rather than the expected `MyClass`.
91
+ owner = owner.class unless Module === owner
92
+
93
+ # On some 1.9s (e.g. rubinius) aliased methods
94
+ # can report the wrong owner. Example:
95
+ # class MyClass
96
+ # class << self
97
+ # alias alternate_new new
98
+ # end
99
+ # end
100
+ #
101
+ # MyClass.owner(:alternate_new) returns `Class` when incorrect,
102
+ # but we need to consider the owner to be `MyClass` because
103
+ # it is not actually available on `Class` but is on `MyClass`.
104
+ # Hence, we verify that the owner actually has the method defined.
105
+ # If the given owner does not have the method defined, we assume
106
+ # that the method is actually owned by @klass.
107
+ owner == @klass || !(method_defined_on_klass?(owner))
108
+ end
109
+ end
110
+ end
111
+ end
112
+
@@ -0,0 +1,99 @@
1
+ module RSpec
2
+ module Mocks
3
+ module Matchers
4
+ class HaveReceived
5
+ COUNT_CONSTRAINTS = %w(exactly at_least at_most times once twice)
6
+ ARGS_CONSTRAINTS = %w(with)
7
+ CONSTRAINTS = COUNT_CONSTRAINTS + ARGS_CONSTRAINTS + %w(ordered)
8
+
9
+ def initialize(method_name, &block)
10
+ @method_name = method_name
11
+ @block = block
12
+ @constraints = []
13
+ @subject = nil
14
+ end
15
+
16
+ def name
17
+ "have_received"
18
+ end
19
+
20
+ def matches?(subject, &block)
21
+ @block ||= block
22
+ @subject = subject
23
+ @expectation = expect
24
+ expected_messages_received_in_order?
25
+ end
26
+
27
+ def does_not_match?(subject)
28
+ @subject = subject
29
+ ensure_count_unconstrained
30
+ @expectation = expect.never
31
+ expected_messages_received_in_order?
32
+ end
33
+
34
+ def failure_message
35
+ generate_failure_message
36
+ end
37
+
38
+ def negative_failure_message
39
+ generate_failure_message
40
+ end
41
+
42
+ def description
43
+ expect.description
44
+ end
45
+
46
+ CONSTRAINTS.each do |expectation|
47
+ define_method expectation do |*args|
48
+ @constraints << [expectation, *args]
49
+ self
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def expect
56
+ expectation = mock_proxy.build_expectation(@method_name)
57
+ apply_constraints_to expectation
58
+ expectation
59
+ end
60
+
61
+ def apply_constraints_to(expectation)
62
+ @constraints.each do |constraint|
63
+ expectation.send(*constraint)
64
+ end
65
+ end
66
+
67
+ def ensure_count_unconstrained
68
+ if count_constraint
69
+ raise RSpec::Mocks::MockExpectationError,
70
+ "can't use #{count_constraint} when negative"
71
+ end
72
+ end
73
+
74
+ def count_constraint
75
+ @constraints.map(&:first).detect do |constraint|
76
+ COUNT_CONSTRAINTS.include?(constraint)
77
+ end
78
+ end
79
+
80
+ def generate_failure_message
81
+ mock_proxy.check_for_unexpected_arguments(@expectation)
82
+ @expectation.generate_error
83
+ rescue RSpec::Mocks::MockExpectationError => error
84
+ error.message
85
+ end
86
+
87
+ def expected_messages_received_in_order?
88
+ mock_proxy.replay_received_message_on @expectation, &@block
89
+ @expectation.expected_messages_received? && @expectation.ensure_expected_ordering_received!
90
+ end
91
+
92
+ def mock_proxy
93
+ RSpec::Mocks.proxy_for(@subject)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+
@@ -0,0 +1,112 @@
1
+ module RSpec
2
+ module Mocks
3
+ module Matchers
4
+ class Receive
5
+ def initialize(message, block)
6
+ @message = message
7
+ @block = block
8
+ @recorded_customizations = []
9
+
10
+ # MRI, JRuby and RBX report the caller inconsistently; MRI
11
+ # reports an extra "in `new'" line in the backtrace that the
12
+ # others do not include. The safest way to find the right
13
+ # line is to search for the first line BEFORE rspec/mocks/syntax.rb.
14
+ @backtrace_line = CallerFilter.first_non_rspec_line
15
+ end
16
+
17
+ def name
18
+ "receive"
19
+ end
20
+
21
+ def setup_expectation(subject, &block)
22
+ warn_if_any_instance("expect", subject)
23
+ setup_mock_proxy_method_substitute(subject, :add_message_expectation, block)
24
+ end
25
+ alias matches? setup_expectation
26
+
27
+ def setup_negative_expectation(subject, &block)
28
+ # ensure `never` goes first for cases like `never.and_return(5)`,
29
+ # where `and_return` is meant to raise an error
30
+ @recorded_customizations.unshift Customization.new(:never, [], nil)
31
+
32
+ warn_if_any_instance("expect", subject)
33
+
34
+ setup_expectation(subject, &block)
35
+ end
36
+ alias does_not_match? setup_negative_expectation
37
+
38
+ def setup_allowance(subject, &block)
39
+ warn_if_any_instance("allow", subject)
40
+ setup_mock_proxy_method_substitute(subject, :add_stub, block)
41
+ end
42
+
43
+ def setup_any_instance_expectation(subject, &block)
44
+ setup_any_instance_method_substitute(subject, :should_receive, block)
45
+ end
46
+
47
+ def setup_any_instance_negative_expectation(subject, &block)
48
+ setup_any_instance_method_substitute(subject, :should_not_receive, block)
49
+ end
50
+
51
+ def setup_any_instance_allowance(subject, &block)
52
+ setup_any_instance_method_substitute(subject, :stub, block)
53
+ end
54
+
55
+ MessageExpectation.public_instance_methods(false).each do |method|
56
+ next if method_defined?(method)
57
+
58
+ define_method(method) do |*args, &block|
59
+ @recorded_customizations << Customization.new(method, args, block)
60
+ self
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def warn_if_any_instance(expression, subject)
67
+ if AnyInstance::Recorder === subject
68
+ RSpec.warning(
69
+ "`#{expression}(#{subject.klass}.any_instance).to` " <<
70
+ "is probably not what you meant, it does not operate on " <<
71
+ "any instance of `#{subject.klass}`. " <<
72
+ "Use `#{expression}_any_instance_of(#{subject.klass}).to` instead."
73
+ )
74
+ end
75
+ end
76
+
77
+ def setup_mock_proxy_method_substitute(subject, method, block)
78
+ proxy = ::RSpec::Mocks.proxy_for(subject)
79
+ setup_method_substitute(proxy, method, block, @backtrace_line)
80
+ end
81
+
82
+ def setup_any_instance_method_substitute(subject, method, block)
83
+ any_instance_recorder = ::RSpec::Mocks.any_instance_recorder_for(subject)
84
+ setup_method_substitute(any_instance_recorder, method, block)
85
+ end
86
+
87
+ def setup_method_substitute(host, method, block, *args)
88
+ args << @message.to_sym
89
+ expectation = host.__send__(method, *args, &(@block || block))
90
+
91
+ @recorded_customizations.each do |customization|
92
+ customization.playback_onto(expectation)
93
+ end
94
+ expectation
95
+ end
96
+
97
+ class Customization
98
+ def initialize(method_name, args, block)
99
+ @method_name = method_name
100
+ @args = args
101
+ @block = block
102
+ end
103
+
104
+ def playback_onto(expectation)
105
+ expectation.__send__(@method_name, *@args, &@block)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+
@@ -0,0 +1,72 @@
1
+ module RSpec
2
+ module Mocks
3
+ module Matchers
4
+ class ReceiveMessages
5
+
6
+ def initialize(message_return_value_hash)
7
+ @message_return_value_hash = message_return_value_hash
8
+ @backtrace_line = CallerFilter.first_non_rspec_line
9
+ end
10
+
11
+ def name
12
+ "receive_messages"
13
+ end
14
+
15
+ def setup_expectation(subject)
16
+ warn_about_block if block_given?
17
+ each_message_on( proxy_on(subject) ) do |host, message, return_value|
18
+ host.add_simple_expectation(message, return_value, @backtrace_line)
19
+ end
20
+ end
21
+ alias matches? setup_expectation
22
+
23
+ def setup_negative_expectation(subject)
24
+ raise NegationUnsupportedError,
25
+ "`expect(...).to_not receive_messages` is not supported since it " +
26
+ "doesn't really make sense. What would it even mean?"
27
+ end
28
+ alias does_not_match? setup_negative_expectation
29
+
30
+ def setup_allowance(subject)
31
+ warn_about_block if block_given?
32
+ each_message_on( proxy_on(subject) ) do |host, message, return_value|
33
+ host.add_simple_stub(message, return_value)
34
+ end
35
+ end
36
+
37
+ def setup_any_instance_expectation(subject)
38
+ warn_about_block if block_given?
39
+ each_message_on( any_instance_of(subject) ) do |host, message, return_value|
40
+ host.should_receive(message).and_return(return_value)
41
+ end
42
+ end
43
+
44
+ def setup_any_instance_allowance(subject)
45
+ warn_about_block if block_given?
46
+ any_instance_of(subject).stub(@message_return_value_hash)
47
+ end
48
+
49
+ def warn_about_block
50
+ raise "Implementation blocks aren't supported with `receive_messages`"
51
+ end
52
+
53
+ private
54
+
55
+ def proxy_on(subject)
56
+ ::RSpec::Mocks.proxy_for(subject)
57
+ end
58
+
59
+ def any_instance_of(subject)
60
+ ::RSpec::Mocks.any_instance_recorder_for(subject)
61
+ end
62
+
63
+ def each_message_on(host)
64
+ @message_return_value_hash.each do |message, value|
65
+ yield host, message, value
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end