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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.gitmodules +15 -0
- data/.travis.yml +12 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +3 -1
- data/Gemfile +6 -7
- data/README.md +2 -0
- data/Rakefile +12 -50
- data/lib/opal/rspec/version.rb +1 -1
- data/lib/opal/rspec.rb +14 -0
- data/opal/opal/rspec/async.rb +146 -11
- data/opal/opal/rspec/fixes.rb +18 -8
- data/opal/opal/rspec/requires.rb +45 -0
- data/opal/opal/rspec.rb +1 -24
- data/opal-rspec.gemspec +1 -1
- data/spec/async_spec.rb +4 -5
- data/spec/matchers_spec.rb +20 -0
- data/spec/named_subject_spec.rb +11 -0
- data/spec/should_syntax_spec.rb +17 -0
- data/vendor_lib/rspec/autorun.rb +2 -0
- data/vendor_lib/rspec/core/backport_random.rb +302 -0
- data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
- data/vendor_lib/rspec/core/command_line.rb +36 -0
- data/vendor_lib/rspec/core/configuration.rb +1129 -0
- data/vendor_lib/rspec/core/configuration_options.rb +143 -0
- data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
- data/vendor_lib/rspec/core/drb_options.rb +87 -0
- data/vendor_lib/rspec/core/dsl.rb +26 -0
- data/vendor_lib/rspec/core/example.rb +312 -0
- data/vendor_lib/rspec/core/example_group.rb +540 -0
- data/vendor_lib/rspec/core/filter_manager.rb +224 -0
- data/vendor_lib/rspec/core/flat_map.rb +17 -0
- data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
- data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
- data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
- data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
- data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
- data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
- data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
- data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
- data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
- data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
- data/vendor_lib/rspec/core/formatters.rb +54 -0
- data/vendor_lib/rspec/core/hooks.rb +535 -0
- data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
- data/vendor_lib/rspec/core/metadata.rb +313 -0
- data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
- data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
- data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
- data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
- data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
- data/vendor_lib/rspec/core/option_parser.rb +234 -0
- data/vendor_lib/rspec/core/ordering.rb +154 -0
- data/vendor_lib/rspec/core/pending.rb +110 -0
- data/vendor_lib/rspec/core/project_initializer.rb +88 -0
- data/vendor_lib/rspec/core/rake_task.rb +128 -0
- data/vendor_lib/rspec/core/reporter.rb +132 -0
- data/vendor_lib/rspec/core/ruby_project.rb +44 -0
- data/vendor_lib/rspec/core/runner.rb +97 -0
- data/vendor_lib/rspec/core/shared_context.rb +53 -0
- data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
- data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
- data/vendor_lib/rspec/core/version.rb +7 -0
- data/vendor_lib/rspec/core/warnings.rb +22 -0
- data/vendor_lib/rspec/core/world.rb +131 -0
- data/vendor_lib/rspec/core.rb +203 -0
- data/vendor_lib/rspec/expectations/differ.rb +154 -0
- data/vendor_lib/rspec/expectations/errors.rb +9 -0
- data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
- data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
- data/vendor_lib/rspec/expectations/extensions.rb +1 -0
- data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
- data/vendor_lib/rspec/expectations/handler.rb +68 -0
- data/vendor_lib/rspec/expectations/syntax.rb +182 -0
- data/vendor_lib/rspec/expectations/version.rb +8 -0
- data/vendor_lib/rspec/expectations.rb +75 -0
- data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
- data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
- data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
- data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
- data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
- data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
- data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
- data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
- data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
- data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
- data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
- data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
- data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
- data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
- data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
- data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
- data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
- data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
- data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
- data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
- data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
- data/vendor_lib/rspec/matchers/built_in.rb +39 -0
- data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
- data/vendor_lib/rspec/matchers/configuration.rb +113 -0
- data/vendor_lib/rspec/matchers/dsl.rb +23 -0
- data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
- data/vendor_lib/rspec/matchers/matcher.rb +301 -0
- data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
- data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
- data/vendor_lib/rspec/matchers/pretty.rb +70 -0
- data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
- data/vendor_lib/rspec/matchers.rb +633 -0
- data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
- data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
- data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
- data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
- data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
- data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
- data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
- data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
- data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
- data/vendor_lib/rspec/mocks/configuration.rb +111 -0
- data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
- data/vendor_lib/rspec/mocks/errors.rb +12 -0
- data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
- data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
- data/vendor_lib/rspec/mocks/framework.rb +36 -0
- data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
- data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
- data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
- data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
- data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
- data/vendor_lib/rspec/mocks/method_double.rb +209 -0
- data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
- data/vendor_lib/rspec/mocks/mock.rb +7 -0
- data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
- data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
- data/vendor_lib/rspec/mocks/order_group.rb +82 -0
- data/vendor_lib/rspec/mocks/proxy.rb +269 -0
- data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
- data/vendor_lib/rspec/mocks/space.rb +95 -0
- data/vendor_lib/rspec/mocks/standalone.rb +3 -0
- data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
- data/vendor_lib/rspec/mocks/syntax.rb +374 -0
- data/vendor_lib/rspec/mocks/targets.rb +90 -0
- data/vendor_lib/rspec/mocks/test_double.rb +109 -0
- data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
- data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
- data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
- data/vendor_lib/rspec/mocks/version.rb +7 -0
- data/vendor_lib/rspec/mocks.rb +100 -0
- data/vendor_lib/rspec/support/caller_filter.rb +56 -0
- data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
- data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
- data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
- data/vendor_lib/rspec/support/spec.rb +14 -0
- data/vendor_lib/rspec/support/version.rb +7 -0
- data/vendor_lib/rspec/support/warnings.rb +41 -0
- data/vendor_lib/rspec/support.rb +6 -0
- data/vendor_lib/rspec/version.rb +5 -0
- data/vendor_lib/rspec-expectations.rb +1 -0
- data/vendor_lib/rspec.rb +3 -0
- metadata +163 -4
- data/opal/opal/rspec/rspec.js +0 -20384
@@ -0,0 +1,313 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
# Each ExampleGroup class and Example instance owns an instance of
|
4
|
+
# Metadata, which is Hash extended to support lazy evaluation of values
|
5
|
+
# associated with keys that may or may not be used by any example or group.
|
6
|
+
#
|
7
|
+
# In addition to metadata that is used internally, this also stores
|
8
|
+
# user-supplied metadata, e.g.
|
9
|
+
#
|
10
|
+
# describe Something, :type => :ui do
|
11
|
+
# it "does something", :slow => true do
|
12
|
+
# # ...
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# `:type => :ui` is stored in the Metadata owned by the example group, and
|
17
|
+
# `:slow => true` is stored in the Metadata owned by the example. These can
|
18
|
+
# then be used to select which examples are run using the `--tag` option on
|
19
|
+
# the command line, or several methods on `Configuration` used to filter a
|
20
|
+
# run (e.g. `filter_run_including`, `filter_run_excluding`, etc).
|
21
|
+
#
|
22
|
+
# @see Example#metadata
|
23
|
+
# @see ExampleGroup.metadata
|
24
|
+
# @see FilterManager
|
25
|
+
# @see Configuration#filter_run_including
|
26
|
+
# @see Configuration#filter_run_excluding
|
27
|
+
class Metadata < Hash
|
28
|
+
|
29
|
+
def self.relative_path(line)
|
30
|
+
line = line.sub(File.expand_path("."), ".")
|
31
|
+
line = line.sub(/\A([^:]+:\d+)$/, '\\1')
|
32
|
+
return nil if line == '-e:1'
|
33
|
+
line
|
34
|
+
rescue SecurityError
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# @private
|
39
|
+
# Used internally to build a hash from an args array.
|
40
|
+
# Symbols are converted into hash keys with a value of `true`.
|
41
|
+
# This is done to support simple tagging using a symbol, rather
|
42
|
+
# than needing to do `:symbol => true`.
|
43
|
+
def self.build_hash_from(args)
|
44
|
+
hash = args.last.is_a?(Hash) ? args.pop : {}
|
45
|
+
|
46
|
+
while args.last.is_a?(Symbol)
|
47
|
+
hash[args.pop] = true
|
48
|
+
end
|
49
|
+
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
53
|
+
module MetadataHash
|
54
|
+
|
55
|
+
# @private
|
56
|
+
# Supports lazy evaluation of some values. Extended by
|
57
|
+
# ExampleMetadataHash and GroupMetadataHash, which get mixed in to
|
58
|
+
# Metadata for ExampleGroups and Examples (respectively).
|
59
|
+
def [](key)
|
60
|
+
store_computed(key) unless has_key?(key)
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch(key, *args)
|
65
|
+
store_computed(key) unless has_key?(key)
|
66
|
+
super
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def store_computed(key)
|
72
|
+
case key
|
73
|
+
when :location
|
74
|
+
store(:location, location)
|
75
|
+
when :file_path, :line_number
|
76
|
+
file_path, line_number = file_and_line_number
|
77
|
+
store(:file_path, file_path)
|
78
|
+
store(:line_number, line_number)
|
79
|
+
when :execution_result
|
80
|
+
store(:execution_result, {})
|
81
|
+
when :describes, :described_class
|
82
|
+
klass = described_class
|
83
|
+
store(:described_class, klass)
|
84
|
+
# TODO (2011-11-07 DC) deprecate :describes as a key
|
85
|
+
store(:describes, klass)
|
86
|
+
when :full_description
|
87
|
+
store(:full_description, full_description)
|
88
|
+
when :description
|
89
|
+
store(:description, build_description_from(*self[:description_args]))
|
90
|
+
when :description_args
|
91
|
+
store(:description_args, [])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def location
|
96
|
+
"#{self[:file_path]}:#{self[:line_number]}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def file_and_line_number
|
100
|
+
first_caller_from_outside_rspec =~ /(.+?):(\d+)(|:\d+)/
|
101
|
+
return [Metadata::relative_path($1), $2.to_i]
|
102
|
+
end
|
103
|
+
|
104
|
+
def first_caller_from_outside_rspec
|
105
|
+
self[:caller].detect {|l| l !~ /\/lib\/rspec\/core/}
|
106
|
+
end
|
107
|
+
|
108
|
+
def method_description_after_module?(parent_part, child_part)
|
109
|
+
return false unless parent_part.is_a?(Module)
|
110
|
+
child_part =~ /^(#|::|\.)/
|
111
|
+
end
|
112
|
+
|
113
|
+
def build_description_from(first_part = '', *parts)
|
114
|
+
description, _ = parts.inject([first_part.to_s, first_part]) do |(desc, last_part), this_part|
|
115
|
+
this_part = this_part.to_s
|
116
|
+
this_part = (' ' + this_part) unless method_description_after_module?(last_part, this_part)
|
117
|
+
[(desc + this_part), this_part]
|
118
|
+
end
|
119
|
+
|
120
|
+
description
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Mixed in to Metadata for an Example (extends MetadataHash) to support
|
125
|
+
# lazy evaluation of some values.
|
126
|
+
module ExampleMetadataHash
|
127
|
+
include MetadataHash
|
128
|
+
|
129
|
+
def described_class
|
130
|
+
self[:example_group].described_class
|
131
|
+
end
|
132
|
+
|
133
|
+
def full_description
|
134
|
+
build_description_from(self[:example_group][:full_description], *self[:description_args])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Mixed in to Metadata for an ExampleGroup (extends MetadataHash) to
|
139
|
+
# support lazy evaluation of some values.
|
140
|
+
module GroupMetadataHash
|
141
|
+
include MetadataHash
|
142
|
+
|
143
|
+
def described_class
|
144
|
+
container_stack.each do |g|
|
145
|
+
[:described_class, :describes].each do |key|
|
146
|
+
if g.has_key?(key)
|
147
|
+
value = g[key]
|
148
|
+
return value unless value.nil?
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
container_stack.reverse.each do |g|
|
154
|
+
candidate = g[:description_args].first
|
155
|
+
return candidate unless String === candidate || Symbol === candidate
|
156
|
+
end
|
157
|
+
|
158
|
+
nil
|
159
|
+
end
|
160
|
+
|
161
|
+
def full_description
|
162
|
+
build_description_from(*FlatMap.flat_map(container_stack.reverse) {|a| a[:description_args]})
|
163
|
+
end
|
164
|
+
|
165
|
+
def container_stack
|
166
|
+
@container_stack ||= begin
|
167
|
+
groups = [group = self]
|
168
|
+
while group.has_key?(:example_group)
|
169
|
+
groups << group[:example_group]
|
170
|
+
group = group[:example_group]
|
171
|
+
end
|
172
|
+
groups
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def initialize(parent_group_metadata=nil)
|
178
|
+
if parent_group_metadata
|
179
|
+
update(parent_group_metadata)
|
180
|
+
store(:example_group, {:example_group => parent_group_metadata[:example_group].extend(GroupMetadataHash)}.extend(GroupMetadataHash))
|
181
|
+
else
|
182
|
+
store(:example_group, {}.extend(GroupMetadataHash))
|
183
|
+
end
|
184
|
+
|
185
|
+
yield self if block_given?
|
186
|
+
end
|
187
|
+
|
188
|
+
# @private
|
189
|
+
def process(*args)
|
190
|
+
user_metadata = args.last.is_a?(Hash) ? args.pop : {}
|
191
|
+
ensure_valid_keys(user_metadata)
|
192
|
+
|
193
|
+
self[:example_group].store(:description_args, args)
|
194
|
+
self[:example_group].store(:caller, user_metadata.delete(:caller) || caller)
|
195
|
+
|
196
|
+
update(user_metadata)
|
197
|
+
end
|
198
|
+
|
199
|
+
# @private
|
200
|
+
def for_example(description, user_metadata)
|
201
|
+
dup.extend(ExampleMetadataHash).configure_for_example(description, user_metadata)
|
202
|
+
end
|
203
|
+
|
204
|
+
# @private
|
205
|
+
def any_apply?(filters)
|
206
|
+
filters.any? {|k,v| filter_applies?(k,v)}
|
207
|
+
end
|
208
|
+
|
209
|
+
# @private
|
210
|
+
def all_apply?(filters)
|
211
|
+
filters.all? {|k,v| filter_applies?(k,v)}
|
212
|
+
end
|
213
|
+
|
214
|
+
# @private
|
215
|
+
def filter_applies?(key, value, metadata=self)
|
216
|
+
return metadata.filter_applies_to_any_value?(key, value) if Array === metadata[key] && !(Proc === value)
|
217
|
+
return metadata.line_number_filter_applies?(value) if key == :line_numbers
|
218
|
+
return metadata.location_filter_applies?(value) if key == :locations
|
219
|
+
return metadata.filters_apply?(key, value) if Hash === value
|
220
|
+
|
221
|
+
return false unless metadata.has_key?(key)
|
222
|
+
|
223
|
+
case value
|
224
|
+
when Regexp
|
225
|
+
metadata[key] =~ value
|
226
|
+
when Proc
|
227
|
+
case value.arity
|
228
|
+
when 0 then value.call
|
229
|
+
when 2 then value.call(metadata[key], metadata)
|
230
|
+
else value.call(metadata[key])
|
231
|
+
end
|
232
|
+
else
|
233
|
+
metadata[key].to_s == value.to_s
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# @private
|
238
|
+
def filters_apply?(key, value)
|
239
|
+
value.all? {|k, v| filter_applies?(k, v, self[key])}
|
240
|
+
end
|
241
|
+
|
242
|
+
# @private
|
243
|
+
def filter_applies_to_any_value?(key, value)
|
244
|
+
self[key].any? {|v| filter_applies?(key, v, {key => value})}
|
245
|
+
end
|
246
|
+
|
247
|
+
# @private
|
248
|
+
def location_filter_applies?(locations)
|
249
|
+
# it ignores location filters for other files
|
250
|
+
line_number = example_group_declaration_line(locations)
|
251
|
+
line_number ? line_number_filter_applies?(line_number) : true
|
252
|
+
end
|
253
|
+
|
254
|
+
# @private
|
255
|
+
def line_number_filter_applies?(line_numbers)
|
256
|
+
preceding_declaration_lines = line_numbers.map {|n| RSpec.world.preceding_declaration_line(n)}
|
257
|
+
!(relevant_line_numbers & preceding_declaration_lines).empty?
|
258
|
+
end
|
259
|
+
|
260
|
+
protected
|
261
|
+
|
262
|
+
def configure_for_example(description, user_metadata)
|
263
|
+
store(:description_args, [description]) if description
|
264
|
+
store(:caller, user_metadata.delete(:caller) || caller)
|
265
|
+
update(user_metadata)
|
266
|
+
end
|
267
|
+
|
268
|
+
private
|
269
|
+
|
270
|
+
RESERVED_KEYS = [
|
271
|
+
:description,
|
272
|
+
:example_group,
|
273
|
+
:execution_result,
|
274
|
+
:file_path,
|
275
|
+
:full_description,
|
276
|
+
:line_number,
|
277
|
+
:location
|
278
|
+
]
|
279
|
+
|
280
|
+
def ensure_valid_keys(user_metadata)
|
281
|
+
RESERVED_KEYS.each do |key|
|
282
|
+
if user_metadata.has_key?(key)
|
283
|
+
raise <<-EOM
|
284
|
+
#{"*"*50}
|
285
|
+
:#{key} is not allowed
|
286
|
+
|
287
|
+
RSpec reserves some hash keys for its own internal use,
|
288
|
+
including :#{key}, which is used on:
|
289
|
+
|
290
|
+
#{CallerFilter.first_non_rspec_line}.
|
291
|
+
|
292
|
+
Here are all of RSpec's reserved hash keys:
|
293
|
+
|
294
|
+
#{RESERVED_KEYS.join("\n ")}
|
295
|
+
#{"*"*50}
|
296
|
+
EOM
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def example_group_declaration_line(locations)
|
302
|
+
locations[File.expand_path(self[:example_group][:file_path])] if self[:example_group]
|
303
|
+
end
|
304
|
+
|
305
|
+
# TODO - make this a method on metadata - the problem is
|
306
|
+
# metadata[:example_group] is not always a kind of GroupMetadataHash.
|
307
|
+
def relevant_line_numbers(metadata=self)
|
308
|
+
[metadata[:line_number]] + (metadata[:example_group] ? relevant_line_numbers(metadata[:example_group]) : [])
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Jim Weirich on 2007-04-10.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
require 'flexmock/rspec'
|
7
|
+
|
8
|
+
module RSpec
|
9
|
+
module Core
|
10
|
+
module MockFrameworkAdapter
|
11
|
+
|
12
|
+
def self.framework_name; :flexmock end
|
13
|
+
|
14
|
+
include FlexMock::MockContainer
|
15
|
+
def setup_mocks_for_rspec
|
16
|
+
# No setup required
|
17
|
+
end
|
18
|
+
def verify_mocks_for_rspec
|
19
|
+
flexmock_verify
|
20
|
+
end
|
21
|
+
def teardown_mocks_for_rspec
|
22
|
+
flexmock_close
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# In order to support all versions of mocha, we have to jump through some
|
2
|
+
# hoops here.
|
3
|
+
#
|
4
|
+
# mocha >= '0.13.0':
|
5
|
+
# require 'mocha/api' is required
|
6
|
+
# require 'mocha/object' raises a LoadError b/c the file no longer exists
|
7
|
+
# mocha < '0.13.0', >= '0.9.7'
|
8
|
+
# require 'mocha/api' is required
|
9
|
+
# require 'mocha/object' is required
|
10
|
+
# mocha < '0.9.7':
|
11
|
+
# require 'mocha/api' raises a LoadError b/c the file does not yet exist
|
12
|
+
# require 'mocha/standalone' is required
|
13
|
+
# require 'mocha/object' is required
|
14
|
+
begin
|
15
|
+
require 'mocha/api'
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'mocha/object'
|
19
|
+
rescue LoadError
|
20
|
+
# Mocha >= 0.13.0 no longer contains this file nor needs it to be loaded
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
require 'mocha/standalone'
|
24
|
+
require 'mocha/object'
|
25
|
+
end
|
26
|
+
|
27
|
+
module RSpec
|
28
|
+
module Core
|
29
|
+
module MockFrameworkAdapter
|
30
|
+
def self.framework_name; :mocha end
|
31
|
+
|
32
|
+
# Mocha::Standalone was deprecated as of Mocha 0.9.7.
|
33
|
+
begin
|
34
|
+
include Mocha::API
|
35
|
+
rescue NameError
|
36
|
+
include Mocha::Standalone
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup_mocks_for_rspec
|
40
|
+
mocha_setup
|
41
|
+
end
|
42
|
+
|
43
|
+
def verify_mocks_for_rspec
|
44
|
+
mocha_verify
|
45
|
+
end
|
46
|
+
|
47
|
+
def teardown_mocks_for_rspec
|
48
|
+
mocha_teardown
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rr'
|
2
|
+
|
3
|
+
RSpec.configuration.backtrace_exclusion_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Core
|
7
|
+
module MockFrameworkAdapter
|
8
|
+
|
9
|
+
def self.framework_name; :rr end
|
10
|
+
|
11
|
+
include RR::Extensions::InstanceMethods
|
12
|
+
|
13
|
+
def setup_mocks_for_rspec
|
14
|
+
RR::Space.instance.reset
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_mocks_for_rspec
|
18
|
+
RR::Space.instance.verify_doubles
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown_mocks_for_rspec
|
22
|
+
RR::Space.instance.reset
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspec/mocks'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
module MockFrameworkAdapter
|
6
|
+
|
7
|
+
def self.framework_name; :rspec end
|
8
|
+
|
9
|
+
def self.configuration
|
10
|
+
RSpec::Mocks.configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup_mocks_for_rspec
|
14
|
+
RSpec::Mocks::setup(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_mocks_for_rspec
|
18
|
+
RSpec::Mocks::verify
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown_mocks_for_rspec
|
22
|
+
RSpec::Mocks::teardown
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module RSpec::Core
|
5
|
+
class Parser
|
6
|
+
def self.parse!(args)
|
7
|
+
new.parse!(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
alias_method :parse, :parse!
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse!(args)
|
15
|
+
return {} if args.empty?
|
16
|
+
|
17
|
+
convert_deprecated_args(args)
|
18
|
+
|
19
|
+
options = args.delete('--tty') ? {:tty => true} : {}
|
20
|
+
begin
|
21
|
+
parser(options).parse!(args)
|
22
|
+
rescue OptionParser::InvalidOption => e
|
23
|
+
abort "#{e.message}\n\nPlease use --help for a listing of valid options"
|
24
|
+
end
|
25
|
+
|
26
|
+
options
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_deprecated_args(args)
|
30
|
+
args.map! { |arg|
|
31
|
+
case arg
|
32
|
+
when "--formatter"
|
33
|
+
RSpec.deprecate("the --formatter option", :replacement => "-f or --format")
|
34
|
+
"--format"
|
35
|
+
when "--default_path"
|
36
|
+
"--default-path"
|
37
|
+
when "--line_number"
|
38
|
+
"--line-number"
|
39
|
+
else
|
40
|
+
arg
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :parse, :parse!
|
46
|
+
|
47
|
+
def parser(options)
|
48
|
+
OptionParser.new do |parser|
|
49
|
+
parser.banner = "Usage: rspec [options] [files or directories]\n\n"
|
50
|
+
|
51
|
+
parser.on('-I PATH', 'Specify PATH to add to $LOAD_PATH (may be used more than once).') do |dir|
|
52
|
+
options[:libs] ||= []
|
53
|
+
options[:libs] << dir
|
54
|
+
end
|
55
|
+
|
56
|
+
parser.on('-r', '--require PATH', 'Require a file.') do |path|
|
57
|
+
options[:requires] ||= []
|
58
|
+
options[:requires] << path
|
59
|
+
end
|
60
|
+
|
61
|
+
parser.on('-O', '--options PATH', 'Specify the path to a custom options file.') do |path|
|
62
|
+
options[:custom_options_file] = path
|
63
|
+
end
|
64
|
+
|
65
|
+
parser.on('--order TYPE[:SEED]', 'Run examples by the specified order type.',
|
66
|
+
' [defined] examples and groups are run in the order they are defined',
|
67
|
+
' [rand] randomize the order of groups and examples',
|
68
|
+
' [random] alias for rand',
|
69
|
+
' [random:SEED] e.g. --order random:123') do |o|
|
70
|
+
options[:order] = o
|
71
|
+
end
|
72
|
+
|
73
|
+
parser.on('--seed SEED', Integer, 'Equivalent of --order rand:SEED.') do |seed|
|
74
|
+
options[:order] = "rand:#{seed}"
|
75
|
+
end
|
76
|
+
|
77
|
+
parser.on('--fail-fast', 'Abort the run on first failure.') do |o|
|
78
|
+
options[:fail_fast] = true
|
79
|
+
end
|
80
|
+
|
81
|
+
parser.on('--no-fail-fast', 'Do not abort the run on first failure.') do |o|
|
82
|
+
options[:fail_fast] = false
|
83
|
+
end
|
84
|
+
|
85
|
+
parser.on('--failure-exit-code CODE', Integer, 'Override the exit code used when there are failing specs.') do |code|
|
86
|
+
options[:failure_exit_code] = code
|
87
|
+
end
|
88
|
+
|
89
|
+
parser.on('--dry-run', 'Print the formatter output of your suite without',
|
90
|
+
' running any examples or hooks') do |o|
|
91
|
+
options[:dry_run] = true
|
92
|
+
end
|
93
|
+
|
94
|
+
parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |o|
|
95
|
+
options[:drb] = o
|
96
|
+
end
|
97
|
+
|
98
|
+
parser.on('--drb-port PORT', 'Port to connect to the DRb server.') do |o|
|
99
|
+
options[:drb_port] = o.to_i
|
100
|
+
end
|
101
|
+
|
102
|
+
parser.on('--init', 'Initialize your project with RSpec.') do |cmd|
|
103
|
+
require 'rspec/core/project_initializer'
|
104
|
+
ProjectInitializer.new(cmd).run
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
|
108
|
+
parser.on('--configure', 'Deprecated. Use --init instead.') do |cmd|
|
109
|
+
RSpec.warning "--configure is deprecated with no effect. Use --init instead.", :call_site => nil
|
110
|
+
exit
|
111
|
+
end
|
112
|
+
|
113
|
+
parser.separator("\n **** Output ****\n\n")
|
114
|
+
|
115
|
+
parser.on('-f', '--format FORMATTER', 'Choose a formatter.',
|
116
|
+
' [p]rogress (default - dots)',
|
117
|
+
' [d]ocumentation (group and example names)',
|
118
|
+
' [h]tml',
|
119
|
+
' [j]son',
|
120
|
+
' custom formatter class name') do |o|
|
121
|
+
options[:formatters] ||= []
|
122
|
+
options[:formatters] << [o]
|
123
|
+
end
|
124
|
+
|
125
|
+
parser.on('-o', '--out FILE',
|
126
|
+
'Write output to a file instead of $stdout. This option applies',
|
127
|
+
' to the previously specified --format, or the default format',
|
128
|
+
' if no format is specified.'
|
129
|
+
) do |o|
|
130
|
+
options[:formatters] ||= [['progress']]
|
131
|
+
options[:formatters].last << o
|
132
|
+
end
|
133
|
+
|
134
|
+
parser.on('-b', '--backtrace', 'Enable full backtrace.') do |o|
|
135
|
+
options[:full_backtrace] = true
|
136
|
+
end
|
137
|
+
|
138
|
+
parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output.') do |o|
|
139
|
+
options[:color] = o
|
140
|
+
end
|
141
|
+
|
142
|
+
parser.on('-p', '--[no-]profile [COUNT]', 'Enable profiling of examples and list the slowest examples (default: 10).') do |argument|
|
143
|
+
options[:profile_examples] = if argument.nil?
|
144
|
+
true
|
145
|
+
elsif argument == false
|
146
|
+
false
|
147
|
+
else
|
148
|
+
begin
|
149
|
+
Integer(argument)
|
150
|
+
rescue ArgumentError
|
151
|
+
RSpec.warning "Non integer specified as profile count, seperate " +
|
152
|
+
"your path from options with -- e.g. " +
|
153
|
+
"`rspec --profile -- #{argument}`",
|
154
|
+
:call_site => nil
|
155
|
+
true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
parser.on('-w', '--warnings', 'Enable ruby warnings') do
|
161
|
+
options[:warnings] = true
|
162
|
+
end
|
163
|
+
|
164
|
+
parser.separator <<-FILTERING
|
165
|
+
|
166
|
+
**** Filtering/tags ****
|
167
|
+
|
168
|
+
In addition to the following options for selecting specific files, groups,
|
169
|
+
or examples, you can select a single example by appending the line number to
|
170
|
+
the filename:
|
171
|
+
|
172
|
+
rspec path/to/a_spec.rb:37
|
173
|
+
|
174
|
+
FILTERING
|
175
|
+
|
176
|
+
parser.on('-P', '--pattern PATTERN', 'Load files matching pattern (default: "spec/**/*_spec.rb").') do |o|
|
177
|
+
options[:pattern] = o
|
178
|
+
end
|
179
|
+
|
180
|
+
parser.on('-e', '--example STRING', "Run examples whose full nested names include STRING (may be",
|
181
|
+
" used more than once)") do |o|
|
182
|
+
(options[:full_description] ||= []) << Regexp.compile(Regexp.escape(o))
|
183
|
+
end
|
184
|
+
|
185
|
+
parser.on('-l', '--line-number LINE', 'Specify line number of an example or group (may be',
|
186
|
+
' used more than once).') do |o|
|
187
|
+
(options[:line_numbers] ||= []) << o
|
188
|
+
end
|
189
|
+
|
190
|
+
parser.on('-t', '--tag TAG[:VALUE]',
|
191
|
+
'Run examples with the specified tag, or exclude examples',
|
192
|
+
'by adding ~ before the tag.',
|
193
|
+
' - e.g. ~slow',
|
194
|
+
' - TAG is always converted to a symbol') do |tag|
|
195
|
+
filter_type = tag =~ /^~/ ? :exclusion_filter : :inclusion_filter
|
196
|
+
|
197
|
+
name,value = tag.gsub(/^(~@|~|@)/, '').split(':',2)
|
198
|
+
name = name.to_sym
|
199
|
+
|
200
|
+
options[filter_type] ||= {}
|
201
|
+
options[filter_type][name] = case value
|
202
|
+
when nil then true # The default value for tags is true
|
203
|
+
when 'true' then true
|
204
|
+
when 'false' then false
|
205
|
+
when 'nil' then nil
|
206
|
+
when /^:/ then value[1..-1].to_sym
|
207
|
+
when /^\d+$/ then Integer(value)
|
208
|
+
when /^\d+.\d+$/ then Float(value)
|
209
|
+
else
|
210
|
+
value
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
parser.on('--default-path PATH', 'Set the default path where RSpec looks for examples (can',
|
215
|
+
' be a path to a file or a directory).') do |path|
|
216
|
+
options[:default_path] = path
|
217
|
+
end
|
218
|
+
|
219
|
+
parser.separator("\n **** Utility ****\n\n")
|
220
|
+
|
221
|
+
parser.on('-v', '--version', 'Display the version.') do
|
222
|
+
puts RSpec::Core::Version::STRING
|
223
|
+
exit
|
224
|
+
end
|
225
|
+
|
226
|
+
parser.on_tail('-h', '--help', "You're looking at it.") do
|
227
|
+
puts parser
|
228
|
+
exit
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|