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,75 @@
1
+ require 'rspec/support/caller_filter'
2
+ require 'rspec/support/warnings'
3
+
4
+ require 'rspec/expectations/extensions'
5
+ require 'rspec/matchers'
6
+ require 'rspec/expectations/expectation_target'
7
+ require 'rspec/matchers/configuration'
8
+ require 'rspec/expectations/fail_with'
9
+ require 'rspec/expectations/errors'
10
+ require 'rspec/expectations/handler'
11
+ require 'rspec/expectations/version'
12
+ require 'rspec/expectations/differ'
13
+
14
+ module RSpec
15
+ # RSpec::Expectations adds two instance methods to every object:
16
+ #
17
+ # should(matcher=nil)
18
+ # should_not(matcher=nil)
19
+ #
20
+ # Both methods take an optional matcher object (See
21
+ # [RSpec::Matchers](../RSpec/Matchers)). When `should` is invoked with a
22
+ # matcher, it turns around and calls `matcher.matches?(self)`. For example,
23
+ # in the expression:
24
+ #
25
+ # order.total.should eq(Money.new(5.55, :USD))
26
+ #
27
+ # the `should` method invokes the equivalent of `eq.matches?(order.total)`. If
28
+ # `matches?` returns true, the expectation is met and execution continues. If
29
+ # `false`, then the spec fails with the message returned by
30
+ # `eq.failure_message_for_should`.
31
+ #
32
+ # Given the expression:
33
+ #
34
+ # order.entries.should_not include(entry)
35
+ #
36
+ # the `should_not` method invokes the equivalent of
37
+ # `include.matches?(order.entries)`, but it interprets `false` as success, and
38
+ # `true` as a failure, using the message generated by
39
+ # `eq.failure_message_for_should_not`.
40
+ #
41
+ # rspec-expectations ships with a standard set of useful matchers, and writing
42
+ # your own matchers is quite simple.
43
+ #
44
+ # See [RSpec::Matchers](../RSpec/Matchers) for more information about the
45
+ # built-in matchers that ship with rspec-expectations, and how to write your
46
+ # own custom matchers.
47
+ module Expectations
48
+
49
+ # @api private
50
+ KERNEL_METHOD_METHOD = ::Kernel.instance_method(:method)
51
+
52
+ # @api private
53
+ #
54
+ # Used internally to get a method handle for a particular object
55
+ # and method name.
56
+ #
57
+ # Includes handling for a few special cases:
58
+ #
59
+ # - Objects that redefine #method (e.g. an HTTPRequest struct)
60
+ # - BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)
61
+ if RUBY_VERSION.to_i >= 2
62
+ def self.method_handle_for(object, method_name)
63
+ KERNEL_METHOD_METHOD.bind(object).call(method_name)
64
+ end
65
+ else
66
+ def self.method_handle_for(object, method_name)
67
+ if ::Kernel === object
68
+ KERNEL_METHOD_METHOD.bind(object).call(method_name)
69
+ else
70
+ object.method(method_name)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,154 @@
1
+ require 'diff/lcs'
2
+ require 'diff/lcs/hunk'
3
+ require 'pp'
4
+
5
+ module RSpec
6
+ module Expectations
7
+ class Differ
8
+
9
+ # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
10
+ def diff_as_string(input_data_new, input_data_old)
11
+ encoding = pick_encoding input_data_new, input_data_old
12
+ output = matching_encoding("", encoding)
13
+ data_old = input_data_old.split(matching_encoding("\n", encoding)).map! { |e| e.chomp }
14
+ data_new = input_data_new.split(matching_encoding("\n", encoding)).map! { |e| e.chomp }
15
+ diffs = Diff::LCS.diff(data_old, data_new)
16
+ return output if diffs.empty?
17
+ oldhunk = hunk = nil
18
+ file_length_difference = 0
19
+ diffs.each do |piece|
20
+ begin
21
+ hunk = Diff::LCS::Hunk.new(
22
+ data_old, data_new, piece, context_lines, file_length_difference
23
+ )
24
+ file_length_difference = hunk.file_length_difference
25
+ next unless oldhunk
26
+ # Hunks may overlap, which is why we need to be careful when our
27
+ # diff includes lines of context. Otherwise, we might print
28
+ # redundant lines.
29
+ if (context_lines > 0) and hunk.overlaps?(oldhunk)
30
+ if hunk.respond_to?(:merge)
31
+ # diff-lcs 1.2.x
32
+ hunk.merge(oldhunk)
33
+ else
34
+ # diff-lcs 1.1.3
35
+ hunk.unshift(oldhunk)
36
+ end
37
+ else
38
+ output << matching_encoding(oldhunk.diff(format).to_s, encoding)
39
+ end
40
+ ensure
41
+ oldhunk = hunk
42
+ output << matching_encoding("\n", encoding)
43
+ end
44
+ end
45
+ #Handle the last remaining hunk
46
+ output << matching_encoding(oldhunk.diff(format).to_s, encoding)
47
+ output << matching_encoding("\n", encoding)
48
+ color_diff output
49
+ rescue Encoding::CompatibilityError
50
+ if input_data_new.encoding != input_data_old.encoding
51
+ "Could not produce a diff because the encoding of the actual string (#{input_data_old.encoding}) "+
52
+ "differs from the encoding of the expected string (#{input_data_new.encoding})"
53
+ else
54
+ "Could not produce a diff because of the encoding of the string (#{input_data_old.encoding})"
55
+ end
56
+ end
57
+
58
+ def diff_as_object(actual, expected)
59
+ actual_as_string = object_to_string(actual)
60
+ expected_as_string = object_to_string(expected)
61
+ if diff = diff_as_string(actual_as_string, expected_as_string)
62
+ color_diff diff
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ def format
69
+ :unified
70
+ end
71
+
72
+ def context_lines
73
+ 3
74
+ end
75
+
76
+ def color(text, color_code)
77
+ "\e[#{color_code}m#{text}\e[0m"
78
+ end
79
+
80
+ def red(text)
81
+ color(text, 31)
82
+ end
83
+
84
+ def green(text)
85
+ color(text, 32)
86
+ end
87
+
88
+ def blue(text)
89
+ color(text, 34)
90
+ end
91
+
92
+ def color_diff(diff)
93
+ return diff unless RSpec::Matchers.configuration.color?
94
+
95
+ diff.lines.map { |line|
96
+ case line[0].chr
97
+ when "+"
98
+ green line
99
+ when "-"
100
+ red line
101
+ when "@"
102
+ line[1].chr == "@" ? blue(line) : line
103
+ else
104
+ line
105
+ end
106
+ }.join
107
+ end
108
+
109
+ def object_to_string(object)
110
+ case object
111
+ when Hash
112
+ object.keys.sort_by { |k| k.to_s }.map do |key|
113
+ pp_key = PP.singleline_pp(key, "")
114
+ pp_value = PP.singleline_pp(object[key], "")
115
+
116
+ # on 1.9.3 PP seems to minimise to US-ASCII, ensure we're matching source encoding
117
+ #
118
+ # note, PP is used to ensure the ordering of the internal values of key/value e.g.
119
+ # <# a: b: c:> not <# c: a: b:>
120
+ encoding = pick_encoding pp_key, pp_value
121
+ matching_encoding("#{pp_key} => #{pp_value}", encoding)
122
+ end.join(",\n")
123
+ when String
124
+ object =~ /\n/ ? object : object.inspect
125
+ else
126
+ PP.pp(object,"")
127
+ end
128
+ end
129
+
130
+ private
131
+
132
+ if String.method_defined?(:encoding)
133
+ def pick_encoding(source_a, source_b)
134
+ Encoding.compatible?(source_a, source_b) || Encoding.default_external
135
+ end
136
+
137
+ def matching_encoding(string, encoding)
138
+ string.encode encoding
139
+ rescue Encoding::UndefinedConversionError
140
+ string.encode(encoding, :undef => :replace)
141
+ end
142
+ else
143
+ def pick_encoding(source_a, source_b)
144
+ end
145
+
146
+ def matching_encoding(string, encoding)
147
+ string
148
+ end
149
+ end
150
+ end
151
+
152
+ end
153
+ end
154
+
@@ -0,0 +1,9 @@
1
+ module RSpec
2
+ module Expectations
3
+ if defined?(Test::Unit::AssertionFailedError)
4
+ class ExpectationNotMetError < Test::Unit::AssertionFailedError; end
5
+ else
6
+ class ExpectationNotMetError < ::StandardError; end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,87 @@
1
+ module RSpec
2
+ module Expectations
3
+ # Wraps the target of an expectation.
4
+ # @example
5
+ # expect(something) # => ExpectationTarget wrapping something
6
+ #
7
+ # # used with `to`
8
+ # expect(actual).to eq(3)
9
+ #
10
+ # # with `not_to`
11
+ # expect(actual).not_to eq(3)
12
+ class ExpectationTarget
13
+ class << self
14
+ attr_accessor :deprecated_should_enabled
15
+ alias deprecated_should_enabled? deprecated_should_enabled
16
+ end
17
+
18
+ # @api private
19
+ def initialize(target)
20
+ @target = target
21
+ end
22
+
23
+ # Runs the given expectation, passing if `matcher` returns true.
24
+ # @example
25
+ # expect(value).to eq(5)
26
+ # expect { perform }.to raise_error
27
+ # @param [Matcher]
28
+ # matcher
29
+ # @param [String or Proc] message optional message to display when the expectation fails
30
+ # @return [Boolean] true if the expectation succeeds (else raises)
31
+ # @see RSpec::Matchers
32
+ def to(matcher=nil, message=nil, &block)
33
+ prevent_operator_matchers(:to, matcher)
34
+ RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, message, &block)
35
+ end
36
+
37
+ # Runs the given expectation, passing if `matcher` returns false.
38
+ # @example
39
+ # expect(value).not_to eq(5)
40
+ # @param [Matcher]
41
+ # matcher
42
+ # @param [String or Proc] message optional message to display when the expectation fails
43
+ # @return [Boolean] false if the negative expectation succeeds (else raises)
44
+ # @see RSpec::Matchers
45
+ def not_to(matcher=nil, message=nil, &block)
46
+ prevent_operator_matchers(:not_to, matcher)
47
+ RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, message, &block)
48
+ end
49
+ alias to_not not_to
50
+
51
+ def self.enable_deprecated_should
52
+ return if deprecated_should_enabled?
53
+
54
+ def should(*args)
55
+ RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`"
56
+ @target.should(*args)
57
+ end
58
+
59
+ def should_not(*args)
60
+ RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`"
61
+ @target.should_not(*args)
62
+ end
63
+
64
+ self.deprecated_should_enabled = true
65
+ end
66
+
67
+ def self.disable_deprecated_should
68
+ return unless deprecated_should_enabled?
69
+
70
+ remove_method :should
71
+ remove_method :should_not
72
+
73
+ self.deprecated_should_enabled = false
74
+ end
75
+
76
+ private
77
+
78
+ def prevent_operator_matchers(verb, matcher)
79
+ return if matcher
80
+
81
+ raise ArgumentError, "The expect syntax does not support operator matchers, " +
82
+ "so you must pass a matcher to `##{verb}`."
83
+ end
84
+ end
85
+ end
86
+ end
87
+
@@ -0,0 +1 @@
1
+ require 'rspec/expectations/extensions/object'
@@ -0,0 +1,29 @@
1
+ module RSpec
2
+ module Expectations
3
+ module DeprecatedConstants
4
+ # Displays deprecation warning when it captures Rspec and Spec. Otherwise
5
+ # delegates to super.
6
+ def const_missing(name)
7
+ case name
8
+ when :Rspec, :Spec
9
+ RSpec.deprecate(name.to_s, :replacement => "RSpec")
10
+ RSpec
11
+ else
12
+ begin
13
+ super
14
+ rescue Exception => e
15
+ e.backtrace.reject! {|l| l =~ Regexp.compile(__FILE__) }
16
+ raise e
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ # @deprecated (no replacement)
23
+ def differ=(ignore)
24
+ RSpec.deprecate("RSpec::Expectations.differ=(differ)")
25
+ end
26
+ end
27
+ end
28
+
29
+ extend RSpec::Expectations::DeprecatedConstants
@@ -0,0 +1,79 @@
1
+ module RSpec
2
+ module Expectations
3
+ class << self
4
+ # @private
5
+ def differ
6
+ @differ ||= Differ.new
7
+ end
8
+
9
+ # Raises an RSpec::Expectations::ExpectationNotMetError with message.
10
+ # @param [String] message
11
+ # @param [Object] expected
12
+ # @param [Object] actual
13
+ #
14
+ # Adds a diff to the failure message when `expected` and `actual` are
15
+ # both present.
16
+ def fail_with(message, expected=nil, actual=nil)
17
+ if !message
18
+ raise ArgumentError, "Failure message is nil. Does your matcher define the " +
19
+ "appropriate failure_message_for_* method to return a string?"
20
+ end
21
+
22
+ if actual && expected
23
+ if all_strings?(actual, expected)
24
+ if any_multiline_strings?(actual, expected)
25
+ message << "\nDiff:" << differ.diff_as_string(coerce_to_string(actual), coerce_to_string(expected))
26
+ end
27
+ elsif no_procs?(actual, expected) && no_numbers?(actual, expected)
28
+ message << "\nDiff:" << differ.diff_as_object(actual, expected)
29
+ end
30
+ end
31
+
32
+ raise(RSpec::Expectations::ExpectationNotMetError.new(message))
33
+ end
34
+
35
+ private
36
+
37
+ def no_procs?(*args)
38
+ args.flatten.none? {|a| Proc === a}
39
+ end
40
+
41
+ def all_strings?(*args)
42
+ args.flatten.all? {|a| String === a}
43
+ end
44
+
45
+ def any_multiline_strings?(*args)
46
+ all_strings?(*args) && args.flatten.any? { |a| multiline?(a) }
47
+ end
48
+
49
+ def no_numbers?(*args)
50
+ args.flatten.none? {|a| Numeric === a}
51
+ end
52
+
53
+ def coerce_to_string(string_or_array)
54
+ return string_or_array unless Array === string_or_array
55
+ diffably_stringify(string_or_array).join("\n")
56
+ end
57
+
58
+ def diffably_stringify(array)
59
+ array.map do |entry|
60
+ if Array === entry
61
+ entry.inspect
62
+ else
63
+ entry.to_s.gsub("\n", "\\n")
64
+ end
65
+ end
66
+ end
67
+
68
+ if String.method_defined?(:encoding)
69
+ def multiline?(string)
70
+ string.include?("\n".encode(string.encoding))
71
+ end
72
+ else
73
+ def multiline?(string)
74
+ string.include?("\n")
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,68 @@
1
+ module RSpec
2
+ module Expectations
3
+
4
+ class ExpectationHandler
5
+ def self.check_message(msg)
6
+ unless msg.nil? || msg.respond_to?(:to_str) || msg.respond_to?(:call)
7
+ ::Kernel.warn [
8
+ "WARNING: ignoring the provided expectation message argument (",
9
+ msg.inspect,
10
+ ") since it is not a string or a proc."
11
+ ].join
12
+ end
13
+ end
14
+ end
15
+
16
+ class PositiveExpectationHandler < ExpectationHandler
17
+
18
+ def self.handle_matcher(actual, matcher, message=nil, &block)
19
+ check_message(message)
20
+ ::RSpec::Matchers.last_should = :should
21
+ ::RSpec::Matchers.last_matcher = matcher
22
+ return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) if matcher.nil?
23
+
24
+ match = matcher.matches?(actual, &block)
25
+ return match if match
26
+
27
+ message = message.call if message.respond_to?(:call)
28
+
29
+ message ||= matcher.respond_to?(:failure_message_for_should) ?
30
+ matcher.failure_message_for_should :
31
+ matcher.failure_message
32
+
33
+ if matcher.respond_to?(:diffable?) && matcher.diffable?
34
+ ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
35
+ else
36
+ ::RSpec::Expectations.fail_with message
37
+ end
38
+ end
39
+ end
40
+
41
+ class NegativeExpectationHandler < ExpectationHandler
42
+ def self.handle_matcher(actual, matcher, message=nil, &block)
43
+ check_message(message)
44
+ ::RSpec::Matchers.last_should = :should_not
45
+ ::RSpec::Matchers.last_matcher = matcher
46
+ return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) if matcher.nil?
47
+
48
+ match = matcher.respond_to?(:does_not_match?) ?
49
+ !matcher.does_not_match?(actual, &block) :
50
+ matcher.matches?(actual, &block)
51
+ return match unless match
52
+
53
+ message = message.call if message.respond_to?(:call)
54
+
55
+ message ||= matcher.respond_to?(:failure_message_for_should_not) ?
56
+ matcher.failure_message_for_should_not :
57
+ matcher.negative_failure_message
58
+
59
+ if matcher.respond_to?(:diffable?) && matcher.diffable?
60
+ ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual
61
+ else
62
+ ::RSpec::Expectations.fail_with message
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+