opal-rspec 0.4.0.beta3 → 0.4.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitmodules +15 -0
  4. data/.travis.yml +12 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +3 -1
  7. data/Gemfile +6 -7
  8. data/README.md +2 -0
  9. data/Rakefile +12 -50
  10. data/lib/opal/rspec/version.rb +1 -1
  11. data/lib/opal/rspec.rb +14 -0
  12. data/opal/opal/rspec/async.rb +146 -11
  13. data/opal/opal/rspec/fixes.rb +18 -8
  14. data/opal/opal/rspec/requires.rb +45 -0
  15. data/opal/opal/rspec.rb +1 -24
  16. data/opal-rspec.gemspec +1 -1
  17. data/spec/async_spec.rb +4 -5
  18. data/spec/matchers_spec.rb +20 -0
  19. data/spec/named_subject_spec.rb +11 -0
  20. data/spec/should_syntax_spec.rb +17 -0
  21. data/vendor_lib/rspec/autorun.rb +2 -0
  22. data/vendor_lib/rspec/core/backport_random.rb +302 -0
  23. data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
  24. data/vendor_lib/rspec/core/command_line.rb +36 -0
  25. data/vendor_lib/rspec/core/configuration.rb +1129 -0
  26. data/vendor_lib/rspec/core/configuration_options.rb +143 -0
  27. data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
  28. data/vendor_lib/rspec/core/drb_options.rb +87 -0
  29. data/vendor_lib/rspec/core/dsl.rb +26 -0
  30. data/vendor_lib/rspec/core/example.rb +312 -0
  31. data/vendor_lib/rspec/core/example_group.rb +540 -0
  32. data/vendor_lib/rspec/core/filter_manager.rb +224 -0
  33. data/vendor_lib/rspec/core/flat_map.rb +17 -0
  34. data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
  35. data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
  36. data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
  37. data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
  38. data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
  39. data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
  40. data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
  41. data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
  42. data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
  43. data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
  44. data/vendor_lib/rspec/core/formatters.rb +54 -0
  45. data/vendor_lib/rspec/core/hooks.rb +535 -0
  46. data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
  47. data/vendor_lib/rspec/core/metadata.rb +313 -0
  48. data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
  49. data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
  50. data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
  51. data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
  52. data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
  53. data/vendor_lib/rspec/core/option_parser.rb +234 -0
  54. data/vendor_lib/rspec/core/ordering.rb +154 -0
  55. data/vendor_lib/rspec/core/pending.rb +110 -0
  56. data/vendor_lib/rspec/core/project_initializer.rb +88 -0
  57. data/vendor_lib/rspec/core/rake_task.rb +128 -0
  58. data/vendor_lib/rspec/core/reporter.rb +132 -0
  59. data/vendor_lib/rspec/core/ruby_project.rb +44 -0
  60. data/vendor_lib/rspec/core/runner.rb +97 -0
  61. data/vendor_lib/rspec/core/shared_context.rb +53 -0
  62. data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
  63. data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
  64. data/vendor_lib/rspec/core/version.rb +7 -0
  65. data/vendor_lib/rspec/core/warnings.rb +22 -0
  66. data/vendor_lib/rspec/core/world.rb +131 -0
  67. data/vendor_lib/rspec/core.rb +203 -0
  68. data/vendor_lib/rspec/expectations/differ.rb +154 -0
  69. data/vendor_lib/rspec/expectations/errors.rb +9 -0
  70. data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
  71. data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
  72. data/vendor_lib/rspec/expectations/extensions.rb +1 -0
  73. data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
  74. data/vendor_lib/rspec/expectations/handler.rb +68 -0
  75. data/vendor_lib/rspec/expectations/syntax.rb +182 -0
  76. data/vendor_lib/rspec/expectations/version.rb +8 -0
  77. data/vendor_lib/rspec/expectations.rb +75 -0
  78. data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
  79. data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
  80. data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
  81. data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
  82. data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
  83. data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
  84. data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
  85. data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
  86. data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
  87. data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
  88. data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
  89. data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
  90. data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
  91. data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
  92. data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
  93. data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
  94. data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
  95. data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
  96. data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
  97. data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
  98. data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
  99. data/vendor_lib/rspec/matchers/built_in.rb +39 -0
  100. data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
  101. data/vendor_lib/rspec/matchers/configuration.rb +113 -0
  102. data/vendor_lib/rspec/matchers/dsl.rb +23 -0
  103. data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
  104. data/vendor_lib/rspec/matchers/matcher.rb +301 -0
  105. data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
  106. data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
  107. data/vendor_lib/rspec/matchers/pretty.rb +70 -0
  108. data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
  109. data/vendor_lib/rspec/matchers.rb +633 -0
  110. data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
  111. data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
  112. data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
  113. data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
  114. data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
  115. data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  116. data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
  117. data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
  118. data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
  119. data/vendor_lib/rspec/mocks/configuration.rb +111 -0
  120. data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
  121. data/vendor_lib/rspec/mocks/errors.rb +12 -0
  122. data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
  123. data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
  124. data/vendor_lib/rspec/mocks/framework.rb +36 -0
  125. data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
  126. data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
  127. data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
  128. data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  129. data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
  130. data/vendor_lib/rspec/mocks/method_double.rb +209 -0
  131. data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
  132. data/vendor_lib/rspec/mocks/mock.rb +7 -0
  133. data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
  134. data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
  135. data/vendor_lib/rspec/mocks/order_group.rb +82 -0
  136. data/vendor_lib/rspec/mocks/proxy.rb +269 -0
  137. data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
  138. data/vendor_lib/rspec/mocks/space.rb +95 -0
  139. data/vendor_lib/rspec/mocks/standalone.rb +3 -0
  140. data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
  141. data/vendor_lib/rspec/mocks/syntax.rb +374 -0
  142. data/vendor_lib/rspec/mocks/targets.rb +90 -0
  143. data/vendor_lib/rspec/mocks/test_double.rb +109 -0
  144. data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
  145. data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  146. data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
  147. data/vendor_lib/rspec/mocks/version.rb +7 -0
  148. data/vendor_lib/rspec/mocks.rb +100 -0
  149. data/vendor_lib/rspec/support/caller_filter.rb +56 -0
  150. data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
  151. data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
  152. data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
  153. data/vendor_lib/rspec/support/spec.rb +14 -0
  154. data/vendor_lib/rspec/support/version.rb +7 -0
  155. data/vendor_lib/rspec/support/warnings.rb +41 -0
  156. data/vendor_lib/rspec/support.rb +6 -0
  157. data/vendor_lib/rspec/version.rb +5 -0
  158. data/vendor_lib/rspec-expectations.rb +1 -0
  159. data/vendor_lib/rspec.rb +3 -0
  160. metadata +163 -4
  161. data/opal/opal/rspec/rspec.js +0 -20384
@@ -0,0 +1,297 @@
1
+ module RSpec
2
+ module Matchers
3
+ module BuiltIn
4
+ class YieldProbe
5
+ def self.probe(block)
6
+ probe = new
7
+ assert_valid_expect_block!(block)
8
+ block.call(probe)
9
+ probe.assert_used!
10
+ probe
11
+ end
12
+
13
+ attr_accessor :num_yields, :yielded_args
14
+
15
+ def initialize
16
+ @used = false
17
+ self.num_yields, self.yielded_args = 0, []
18
+ end
19
+
20
+ def to_proc
21
+ @used = true
22
+
23
+ probe = self
24
+ Proc.new do |*args|
25
+ probe.num_yields += 1
26
+ probe.yielded_args << args
27
+ nil # to indicate the block does not return a meaningful value
28
+ end
29
+ end
30
+
31
+ def single_yield_args
32
+ yielded_args.first
33
+ end
34
+
35
+ def yielded_once?(matcher_name)
36
+ case num_yields
37
+ when 1 then true
38
+ when 0 then false
39
+ else
40
+ raise "The #{matcher_name} matcher is not designed to be used with a " +
41
+ "method that yields multiple times. Use the yield_successive_args " +
42
+ "matcher for that case."
43
+ end
44
+ end
45
+
46
+ def successive_yield_args
47
+ yielded_args.map do |arg_array|
48
+ arg_array.size == 1 ? arg_array.first : arg_array
49
+ end
50
+ end
51
+
52
+ def assert_used!
53
+ return if @used
54
+ raise "You must pass the argument yielded to your expect block on " +
55
+ "to the method-under-test as a block. It acts as a probe that " +
56
+ "allows the matcher to detect whether or not the method-under-test " +
57
+ "yields, and, if so, how many times, and what the yielded arguments " +
58
+ "are."
59
+ end
60
+
61
+ def self.assert_valid_expect_block!(block)
62
+ return if block.arity == 1
63
+ raise "Your expect block must accept an argument to be used with this " +
64
+ "matcher. Pass the argument as a block on to the method you are testing."
65
+ end
66
+ end
67
+
68
+ class YieldControl < BaseMatcher
69
+ def initialize
70
+ @expectation_type = nil
71
+ @expected_yields_count = nil
72
+ end
73
+
74
+ def matches?(block)
75
+ probe = YieldProbe.probe(block)
76
+
77
+ if @expectation_type
78
+ probe.num_yields.send(@expectation_type, @expected_yields_count)
79
+ else
80
+ probe.yielded_once?(:yield_control)
81
+ end
82
+ end
83
+
84
+ def once
85
+ exactly(1)
86
+ self
87
+ end
88
+
89
+ def twice
90
+ exactly(2)
91
+ self
92
+ end
93
+
94
+ def exactly(number)
95
+ set_expected_yields_count(:==, number)
96
+ self
97
+ end
98
+
99
+ def at_most(number)
100
+ set_expected_yields_count(:<=, number)
101
+ self
102
+ end
103
+
104
+ def at_least(number)
105
+ set_expected_yields_count(:>=, number)
106
+ self
107
+ end
108
+
109
+ def times
110
+ self
111
+ end
112
+
113
+ def failure_message_for_should
114
+ 'expected given block to yield control'.tap do |failure_message|
115
+ failure_message << relativity_failure_message
116
+ end
117
+ end
118
+
119
+ def failure_message_for_should_not
120
+ 'expected given block not to yield control'.tap do |failure_message|
121
+ failure_message << relativity_failure_message
122
+ end
123
+ end
124
+
125
+ private
126
+
127
+ def set_expected_yields_count(relativity, n)
128
+ @expectation_type = relativity
129
+ @expected_yields_count = case n
130
+ when Numeric then n
131
+ when :once then 1
132
+ when :twice then 2
133
+ end
134
+ end
135
+
136
+ def relativity_failure_message
137
+ return '' unless @expected_yields_count
138
+ " #{human_readable_expecation_type}#{human_readable_count}"
139
+ end
140
+
141
+ def human_readable_expecation_type
142
+ case @expectation_type
143
+ when :<= then 'at most '
144
+ when :>= then 'at least '
145
+ else ''
146
+ end
147
+ end
148
+
149
+ def human_readable_count
150
+ case @expected_yields_count
151
+ when 1 then "once"
152
+ when 2 then "twice"
153
+ else "#{@expected_yields_count} times"
154
+ end
155
+ end
156
+ end
157
+
158
+ class YieldWithNoArgs < BaseMatcher
159
+
160
+ def matches?(block)
161
+ @probe = YieldProbe.probe(block)
162
+ @probe.yielded_once?(:yield_with_no_args) && @probe.single_yield_args.empty?
163
+ end
164
+
165
+ def failure_message_for_should
166
+ "expected given block to yield with no arguments, but #{failure_reason}"
167
+ end
168
+
169
+ def failure_message_for_should_not
170
+ "expected given block not to yield with no arguments, but did"
171
+ end
172
+
173
+ private
174
+
175
+ def failure_reason
176
+ if @probe.num_yields.zero?
177
+ "did not yield"
178
+ else
179
+ "yielded with arguments: #{@probe.single_yield_args.inspect}"
180
+ end
181
+ end
182
+ end
183
+
184
+ class YieldWithArgs
185
+ def initialize(*args)
186
+ @expected = args
187
+ end
188
+
189
+ def matches?(block)
190
+ @probe = YieldProbe.probe(block)
191
+ @actual = @probe.single_yield_args
192
+ @probe.yielded_once?(:yield_with_args) && args_match?
193
+ end
194
+ alias == matches?
195
+
196
+ def failure_message_for_should
197
+ "expected given block to yield with arguments, but #{positive_failure_reason}"
198
+ end
199
+
200
+ def failure_message_for_should_not
201
+ "expected given block not to yield with arguments, but #{negative_failure_reason}"
202
+ end
203
+
204
+ def description
205
+ desc = "yield with args"
206
+ desc << "(" + @expected.map { |e| e.inspect }.join(", ") + ")" unless @expected.empty?
207
+ desc
208
+ end
209
+
210
+ private
211
+
212
+ def positive_failure_reason
213
+ if @probe.num_yields.zero?
214
+ "did not yield"
215
+ else
216
+ @positive_args_failure
217
+ end
218
+ end
219
+
220
+ def negative_failure_reason
221
+ if all_args_match?
222
+ "yielded with expected arguments" +
223
+ "\nexpected not: #{@expected.inspect}" +
224
+ "\n got: #{@actual.inspect} (compared using === and ==)"
225
+ else
226
+ "did"
227
+ end
228
+ end
229
+
230
+ def args_match?
231
+ if @expected.empty? # expect {...}.to yield_with_args
232
+ @positive_args_failure = "yielded with no arguments" if @actual.empty?
233
+ return !@actual.empty?
234
+ end
235
+
236
+ unless match = all_args_match?
237
+ @positive_args_failure = "yielded with unexpected arguments" +
238
+ "\nexpected: #{@expected.inspect}" +
239
+ "\n got: #{@actual.inspect} (compared using === and ==)"
240
+ end
241
+
242
+ match
243
+ end
244
+
245
+ def all_args_match?
246
+ return false if @expected.size != @actual.size
247
+
248
+ @expected.zip(@actual).all? do |expected, actual|
249
+ expected === actual || actual == expected
250
+ end
251
+ end
252
+ end
253
+
254
+ class YieldSuccessiveArgs
255
+ def initialize(*args)
256
+ @expected = args
257
+ end
258
+
259
+ def matches?(block)
260
+ @probe = YieldProbe.probe(block)
261
+ @actual = @probe.successive_yield_args
262
+ args_match?
263
+ end
264
+ alias == matches?
265
+
266
+ def failure_message_for_should
267
+ "expected given block to yield successively with arguments, but yielded with unexpected arguments" +
268
+ "\nexpected: #{@expected.inspect}" +
269
+ "\n got: #{@actual.inspect} (compared using === and ==)"
270
+ end
271
+
272
+ def failure_message_for_should_not
273
+ "expected given block not to yield successively with arguments, but yielded with expected arguments" +
274
+ "\nexpected not: #{@expected.inspect}" +
275
+ "\n got: #{@actual.inspect} (compared using === and ==)"
276
+ end
277
+
278
+ def description
279
+ desc = "yield successive args"
280
+ desc << "(" + @expected.map { |e| e.inspect }.join(", ") + ")"
281
+ desc
282
+ end
283
+
284
+ private
285
+
286
+ def args_match?
287
+ return false if @expected.size != @actual.size
288
+
289
+ @expected.zip(@actual).all? do |expected, actual|
290
+ expected === actual || actual == expected
291
+ end
292
+ end
293
+ end
294
+ end
295
+ end
296
+ end
297
+
@@ -0,0 +1,39 @@
1
+ module RSpec
2
+ module Matchers
3
+ module BuiltIn
4
+ require 'rspec/matchers/built_in/base_matcher'
5
+ autoload :BeAnInstanceOf, 'rspec/matchers/built_in/be_instance_of'
6
+ autoload :Be, 'rspec/matchers/built_in/be'
7
+ autoload :BeTruthy, 'rspec/matchers/built_in/be'
8
+ autoload :BeFalsey, 'rspec/matchers/built_in/be'
9
+ autoload :BeNil, 'rspec/matchers/built_in/be'
10
+ autoload :BeComparedTo, 'rspec/matchers/built_in/be'
11
+ autoload :BePredicate, 'rspec/matchers/built_in/be'
12
+ autoload :BeAKindOf, 'rspec/matchers/built_in/be_kind_of'
13
+ autoload :BeWithin, 'rspec/matchers/built_in/be_within'
14
+ autoload :Change, 'rspec/matchers/built_in/change'
15
+ autoload :Cover, 'rspec/matchers/built_in/cover' if (1..2).respond_to?(:cover?)
16
+ autoload :Eq, 'rspec/matchers/built_in/eq'
17
+ autoload :Eql, 'rspec/matchers/built_in/eql'
18
+ autoload :Equal, 'rspec/matchers/built_in/equal'
19
+ autoload :Exist, 'rspec/matchers/built_in/exist'
20
+ autoload :Has, 'rspec/matchers/built_in/has'
21
+ autoload :Have, 'rspec/matchers/built_in/have'
22
+ autoload :Include, 'rspec/matchers/built_in/include'
23
+ autoload :Match, 'rspec/matchers/built_in/match'
24
+ autoload :MatchArray, 'rspec/matchers/built_in/match_array'
25
+ autoload :RaiseError, 'rspec/matchers/built_in/raise_error'
26
+ autoload :RespondTo, 'rspec/matchers/built_in/respond_to'
27
+ autoload :StartWith, 'rspec/matchers/built_in/start_and_end_with'
28
+ autoload :EndWith, 'rspec/matchers/built_in/start_and_end_with'
29
+ autoload :Satisfy, 'rspec/matchers/built_in/satisfy'
30
+ autoload :ThrowSymbol, 'rspec/matchers/built_in/throw_symbol'
31
+ autoload :YieldControl, 'rspec/matchers/built_in/yield'
32
+ autoload :YieldWithArgs, 'rspec/matchers/built_in/yield'
33
+ autoload :YieldWithNoArgs, 'rspec/matchers/built_in/yield'
34
+ autoload :YieldSuccessiveArgs, 'rspec/matchers/built_in/yield'
35
+ end
36
+ end
37
+ end
38
+
39
+
@@ -0,0 +1,14 @@
1
+ RSpec::Matchers.constants.each do |c|
2
+ if Class === (klass = RSpec::Matchers.const_get(c))
3
+ if klass.public_instance_methods.any? {|m| ['failure_message_for_should',:failure_message_for_should].include?(m)}
4
+ klass.class_exec do
5
+ alias_method :failure_message, :failure_message_for_should
6
+ end
7
+ end
8
+ if klass.public_instance_methods.any? {|m| ['failure_message_for_should_not',:failure_message_for_should_not].include?(m)}
9
+ klass.class_exec do
10
+ alias_method :negative_failure_message, :failure_message_for_should_not
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,113 @@
1
+ require 'rspec/expectations/syntax'
2
+
3
+ module RSpec
4
+ module Matchers
5
+ # Provides configuration options for rspec-expectations.
6
+ class Configuration
7
+ # Configures the supported syntax.
8
+ # @param [Array<Symbol>, Symbol] values the syntaxes to enable
9
+ # @example
10
+ # RSpec.configure do |rspec|
11
+ # rspec.expect_with :rspec do |c|
12
+ # c.syntax = :should
13
+ # # or
14
+ # c.syntax = :expect
15
+ # # or
16
+ # c.syntax = [:should, :expect]
17
+ # end
18
+ # end
19
+ def syntax=(values)
20
+ if Array(values).include?(:expect)
21
+ Expectations::Syntax.enable_expect
22
+ else
23
+ Expectations::Syntax.disable_expect
24
+ end
25
+
26
+ if Array(values).include?(:should)
27
+ Expectations::Syntax.enable_should
28
+ else
29
+ Expectations::Syntax.disable_should
30
+ end
31
+ end
32
+
33
+ # The list of configured syntaxes.
34
+ # @return [Array<Symbol>] the list of configured syntaxes.
35
+ def syntax
36
+ syntaxes = []
37
+ syntaxes << :should if Expectations::Syntax.should_enabled?
38
+ syntaxes << :expect if Expectations::Syntax.expect_enabled?
39
+ syntaxes
40
+ end
41
+
42
+ # color config for expectations
43
+ # fallback if rspec core not available
44
+ if ::RSpec.respond_to?(:configuration)
45
+ def color?
46
+ ::RSpec.configuration.color_enabled?
47
+ end
48
+ else
49
+ attr_writer :color
50
+ def color?
51
+ @color
52
+ end
53
+ end
54
+
55
+ # Adds `should` and `should_not` to the given classes
56
+ # or modules. This can be used to ensure `should` works
57
+ # properly on things like proxy objects (particular
58
+ # `Delegator`-subclassed objects on 1.8).
59
+ #
60
+ # @param [Array<Module>] modules the list of classes or modules
61
+ # to add `should` and `should_not` to.
62
+ def add_should_and_should_not_to(*modules)
63
+ modules.each do |mod|
64
+ Expectations::Syntax.enable_should(mod)
65
+ end
66
+ end
67
+
68
+ # Sets or gets the backtrace formatter. The backtrace formatter should
69
+ # implement `#format_backtrace(Array<String>)`. This is used
70
+ # to format backtraces of errors handled by the `raise_error`
71
+ # matcher.
72
+ #
73
+ # If you are using rspec-core, rspec-core's backtrace formatting
74
+ # will be used (including respecting the presence or absence of
75
+ # the `--backtrace` option).
76
+ #
77
+ # @overload backtrace_formatter
78
+ # @return [#format_backtrace] the backtrace formatter
79
+ # @overload backtrace_formatter=
80
+ # @param value [#format_backtrace] sets the backtrace formatter
81
+ attr_writer :backtrace_formatter
82
+ def backtrace_formatter
83
+ @backtrace_formatter ||= if defined?(::RSpec::Core::BacktraceFormatter)
84
+ ::RSpec::Core::BacktraceFormatter
85
+ else
86
+ NullBacktraceFormatter
87
+ end
88
+ end
89
+
90
+ def reset_syntaxes_to_default
91
+ self.syntax = [:should, :expect]
92
+ RSpec::Expectations::Syntax.warn_about_should!
93
+ end
94
+
95
+ # @api private
96
+ NullBacktraceFormatter = Module.new do
97
+ def self.format_backtrace(backtrace)
98
+ backtrace
99
+ end
100
+ end
101
+ end
102
+
103
+ # The configuration object
104
+ # @return [RSpec::Matchers::Configuration] the configuration object
105
+ def self.configuration
106
+ @configuration ||= Configuration.new
107
+ end
108
+
109
+ # set default syntax
110
+ configuration.reset_syntaxes_to_default
111
+ end
112
+ end
113
+
@@ -0,0 +1,23 @@
1
+ module RSpec
2
+ module Matchers
3
+ module DSL
4
+ # Defines a custom matcher.
5
+ # @see RSpec::Matchers
6
+ def define(name, &declarations)
7
+ define_method name do |*expected|
8
+ matcher = RSpec::Matchers::DSL::Matcher.new(name, declarations, *expected)
9
+ matcher.matcher_execution_context = @matcher_execution_context ||= self
10
+ matcher
11
+ end
12
+ end
13
+
14
+ alias_method :matcher, :define
15
+
16
+ if RSpec.respond_to?(:configure)
17
+ RSpec.configure {|c| c.extend self}
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ RSpec::Matchers.extend RSpec::Matchers::DSL
@@ -0,0 +1,35 @@
1
+ module RSpec
2
+ module Matchers
3
+ class << self
4
+ attr_accessor :last_matcher, :last_should
5
+ end
6
+
7
+ def self.clear_generated_description
8
+ self.last_matcher = nil
9
+ self.last_should = nil
10
+ end
11
+
12
+ def self.generated_description
13
+ return nil if last_should.nil?
14
+ "#{last_should.to_s.gsub('_',' ')} #{last_description}"
15
+ end
16
+
17
+ private
18
+
19
+ def self.last_description
20
+ last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE
21
+ When you call a matcher in an example without a String, like this:
22
+
23
+ specify { object.should matcher }
24
+
25
+ or this:
26
+
27
+ it { should matcher }
28
+
29
+ RSpec expects the matcher to have a #description method. You should either
30
+ add a String to the example this matcher is being used in, or give it a
31
+ description method. Then you won't have to suffer this lengthy warning again.
32
+ MESSAGE
33
+ end
34
+ end
35
+ end