rspec-core 3.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.document +5 -0
- data/.yardopts +8 -0
- data/Changelog.md +2243 -0
- data/LICENSE.md +26 -0
- data/README.md +384 -0
- data/exe/rspec +4 -0
- data/lib/rspec/autorun.rb +3 -0
- data/lib/rspec/core.rb +185 -0
- data/lib/rspec/core/backtrace_formatter.rb +65 -0
- data/lib/rspec/core/bisect/coordinator.rb +62 -0
- data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
- data/lib/rspec/core/bisect/fork_runner.rb +134 -0
- data/lib/rspec/core/bisect/server.rb +61 -0
- data/lib/rspec/core/bisect/shell_command.rb +126 -0
- data/lib/rspec/core/bisect/shell_runner.rb +73 -0
- data/lib/rspec/core/bisect/utilities.rb +58 -0
- data/lib/rspec/core/configuration.rb +2308 -0
- data/lib/rspec/core/configuration_options.rb +233 -0
- data/lib/rspec/core/drb.rb +113 -0
- data/lib/rspec/core/dsl.rb +98 -0
- data/lib/rspec/core/example.rb +656 -0
- data/lib/rspec/core/example_group.rb +889 -0
- data/lib/rspec/core/example_status_persister.rb +235 -0
- data/lib/rspec/core/filter_manager.rb +231 -0
- data/lib/rspec/core/flat_map.rb +20 -0
- data/lib/rspec/core/formatters.rb +269 -0
- data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
- data/lib/rspec/core/formatters/base_formatter.rb +70 -0
- data/lib/rspec/core/formatters/base_text_formatter.rb +75 -0
- data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
- data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
- data/lib/rspec/core/formatters/console_codes.rb +68 -0
- data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
- data/lib/rspec/core/formatters/documentation_formatter.rb +70 -0
- data/lib/rspec/core/formatters/exception_presenter.rb +508 -0
- data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
- data/lib/rspec/core/formatters/helpers.rb +110 -0
- data/lib/rspec/core/formatters/html_formatter.rb +153 -0
- data/lib/rspec/core/formatters/html_printer.rb +414 -0
- data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
- data/lib/rspec/core/formatters/json_formatter.rb +102 -0
- data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
- data/lib/rspec/core/formatters/progress_formatter.rb +29 -0
- data/lib/rspec/core/formatters/protocol.rb +182 -0
- data/lib/rspec/core/formatters/snippet_extractor.rb +134 -0
- data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
- data/lib/rspec/core/hooks.rb +624 -0
- data/lib/rspec/core/invocations.rb +87 -0
- data/lib/rspec/core/memoized_helpers.rb +554 -0
- data/lib/rspec/core/metadata.rb +498 -0
- data/lib/rspec/core/metadata_filter.rb +255 -0
- data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
- data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
- data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
- data/lib/rspec/core/mocking_adapters/null.rb +14 -0
- data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
- data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
- data/lib/rspec/core/notifications.rb +521 -0
- data/lib/rspec/core/option_parser.rb +309 -0
- data/lib/rspec/core/ordering.rb +158 -0
- data/lib/rspec/core/output_wrapper.rb +29 -0
- data/lib/rspec/core/pending.rb +165 -0
- data/lib/rspec/core/profiler.rb +34 -0
- data/lib/rspec/core/project_initializer.rb +48 -0
- data/lib/rspec/core/project_initializer/.rspec +1 -0
- data/lib/rspec/core/project_initializer/spec/spec_helper.rb +100 -0
- data/lib/rspec/core/rake_task.rb +168 -0
- data/lib/rspec/core/reporter.rb +257 -0
- data/lib/rspec/core/ruby_project.rb +53 -0
- data/lib/rspec/core/runner.rb +199 -0
- data/lib/rspec/core/sandbox.rb +37 -0
- data/lib/rspec/core/set.rb +54 -0
- data/lib/rspec/core/shared_context.rb +55 -0
- data/lib/rspec/core/shared_example_group.rb +269 -0
- data/lib/rspec/core/shell_escape.rb +49 -0
- data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
- data/lib/rspec/core/version.rb +9 -0
- data/lib/rspec/core/warnings.rb +40 -0
- data/lib/rspec/core/world.rb +275 -0
- metadata +292 -0
- metadata.gz.sig +0 -0
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
=====================
|
3
|
+
|
4
|
+
* Copyright © 2012 Chad Humphries, David Chelimsky, Myron Marston
|
5
|
+
* Copyright © 2009 Chad Humphries, David Chelimsky
|
6
|
+
* Copyright © 2006 David Chelimsky, The RSpec Development Team
|
7
|
+
* Copyright © 2005 Steven Baker
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
a copy of this software and associated documentation files (the
|
11
|
+
"Software"), to deal in the Software without restriction, including
|
12
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
+
permit persons to whom the Software is furnished to do so, subject to
|
15
|
+
the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be
|
18
|
+
included in all copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
23
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
24
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
25
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
26
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,384 @@
|
|
1
|
+
# rspec-core [![Build Status](https://secure.travis-ci.org/rspec/rspec-core.svg?branch=master)](http://travis-ci.org/rspec/rspec-core) [![Code Climate](https://codeclimate.com/github/rspec/rspec-core.svg)](https://codeclimate.com/github/rspec/rspec-core)
|
2
|
+
|
3
|
+
rspec-core provides the structure for writing executable examples of how your
|
4
|
+
code should behave, and an `rspec` command with tools to constrain which
|
5
|
+
examples get run and tailor the output.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
|
10
|
+
gem install rspec-core # for rspec-core only
|
11
|
+
rspec --help
|
12
|
+
|
13
|
+
Want to run against the `master` branch? You'll need to include the dependent
|
14
|
+
RSpec repos as well. Add the following to your `Gemfile`:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
18
|
+
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'master'
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
## Basic Structure
|
23
|
+
|
24
|
+
RSpec uses the words "describe" and "it" so we can express concepts like a conversation:
|
25
|
+
|
26
|
+
"Describe an order."
|
27
|
+
"It sums the prices of its line items."
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
RSpec.describe Order do
|
31
|
+
it "sums the prices of its line items" do
|
32
|
+
order = Order.new
|
33
|
+
|
34
|
+
order.add_entry(LineItem.new(:item => Item.new(
|
35
|
+
:price => Money.new(1.11, :USD)
|
36
|
+
)))
|
37
|
+
order.add_entry(LineItem.new(:item => Item.new(
|
38
|
+
:price => Money.new(2.22, :USD),
|
39
|
+
:quantity => 2
|
40
|
+
)))
|
41
|
+
|
42
|
+
expect(order.total).to eq(Money.new(5.55, :USD))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
The `describe` method creates an [ExampleGroup](http://rubydoc.info/gems/rspec-core/RSpec/Core/ExampleGroup). Within the
|
48
|
+
block passed to `describe` you can declare examples using the `it` method.
|
49
|
+
|
50
|
+
Under the hood, an example group is a class in which the block passed to
|
51
|
+
`describe` is evaluated. The blocks passed to `it` are evaluated in the
|
52
|
+
context of an _instance_ of that class.
|
53
|
+
|
54
|
+
## Nested Groups
|
55
|
+
|
56
|
+
You can also declare nested nested groups using the `describe` or `context`
|
57
|
+
methods:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
RSpec.describe Order do
|
61
|
+
context "with no items" do
|
62
|
+
it "behaves one way" do
|
63
|
+
# ...
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with one item" do
|
68
|
+
it "behaves another way" do
|
69
|
+
# ...
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Nested groups are subclasses of the outer example group class, providing
|
76
|
+
the inheritance semantics you'd want for free.
|
77
|
+
|
78
|
+
## Aliases
|
79
|
+
|
80
|
+
You can declare example groups using either `describe` or `context`.
|
81
|
+
For a top level example group, `describe` and `context` are available
|
82
|
+
off of `RSpec`. For backwards compatibility, they are also available
|
83
|
+
off of the `main` object and `Module` unless you disable monkey
|
84
|
+
patching.
|
85
|
+
|
86
|
+
You can declare examples within a group using any of `it`, `specify`, or
|
87
|
+
`example`.
|
88
|
+
|
89
|
+
## Shared Examples and Contexts
|
90
|
+
|
91
|
+
Declare a shared example group using `shared_examples`, and then include it
|
92
|
+
in any group using `include_examples`.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
RSpec.shared_examples "collections" do |collection_class|
|
96
|
+
it "is empty when first created" do
|
97
|
+
expect(collection_class.new).to be_empty
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
RSpec.describe Array do
|
102
|
+
include_examples "collections", Array
|
103
|
+
end
|
104
|
+
|
105
|
+
RSpec.describe Hash do
|
106
|
+
include_examples "collections", Hash
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
Nearly anything that can be declared within an example group can be declared
|
111
|
+
within a shared example group. This includes `before`, `after`, and `around`
|
112
|
+
hooks, `let` declarations, and nested groups/contexts.
|
113
|
+
|
114
|
+
You can also use the names `shared_context` and `include_context`. These are
|
115
|
+
pretty much the same as `shared_examples` and `include_examples`, providing
|
116
|
+
more accurate naming when you share hooks, `let` declarations, helper methods,
|
117
|
+
etc, but no examples.
|
118
|
+
|
119
|
+
## Metadata
|
120
|
+
|
121
|
+
rspec-core stores a metadata hash with every example and group, which
|
122
|
+
contains their descriptions, the locations at which they were
|
123
|
+
declared, etc, etc. This hash powers many of rspec-core's features,
|
124
|
+
including output formatters (which access descriptions and locations),
|
125
|
+
and filtering before and after hooks.
|
126
|
+
|
127
|
+
Although you probably won't ever need this unless you are writing an
|
128
|
+
extension, you can access it from an example like this:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
it "does something" do |example|
|
132
|
+
expect(example.metadata[:description]).to eq("does something")
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
### `described_class`
|
137
|
+
|
138
|
+
When a class is passed to `describe`, you can access it from an example
|
139
|
+
using the `described_class` method, which is a wrapper for
|
140
|
+
`example.metadata[:described_class]`.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
RSpec.describe Widget do
|
144
|
+
example do
|
145
|
+
expect(described_class).to equal(Widget)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
This is useful in extensions or shared example groups in which the specific
|
151
|
+
class is unknown. Taking the collections shared example group from above, we can
|
152
|
+
clean it up a bit using `described_class`:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
RSpec.shared_examples "collections" do
|
156
|
+
it "is empty when first created" do
|
157
|
+
expect(described_class.new).to be_empty
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
RSpec.describe Array do
|
162
|
+
include_examples "collections"
|
163
|
+
end
|
164
|
+
|
165
|
+
RSpec.describe Hash do
|
166
|
+
include_examples "collections"
|
167
|
+
end
|
168
|
+
```
|
169
|
+
|
170
|
+
## A Word on Scope
|
171
|
+
|
172
|
+
RSpec has two scopes:
|
173
|
+
|
174
|
+
* **Example Group**: Example groups are defined by a `describe` or
|
175
|
+
`context` block, which is eagerly evaluated when the spec file is
|
176
|
+
loaded. The block is evaluated in the context of a subclass of
|
177
|
+
`RSpec::Core::ExampleGroup`, or a subclass of the parent example group
|
178
|
+
when you're nesting them.
|
179
|
+
* **Example**: Examples -- typically defined by an `it` block -- and any other
|
180
|
+
blocks with per-example semantics -- such as a `before(:example)` hook -- are
|
181
|
+
evaluated in the context of
|
182
|
+
an _instance_ of the example group class to which the example belongs.
|
183
|
+
Examples are _not_ executed when the spec file is loaded; instead,
|
184
|
+
RSpec waits to run any examples until all spec files have been loaded,
|
185
|
+
at which point it can apply filtering, randomization, etc.
|
186
|
+
|
187
|
+
To make this more concrete, consider this code snippet:
|
188
|
+
|
189
|
+
``` ruby
|
190
|
+
RSpec.describe "Using an array as a stack" do
|
191
|
+
def build_stack
|
192
|
+
[]
|
193
|
+
end
|
194
|
+
|
195
|
+
before(:example) do
|
196
|
+
@stack = build_stack
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'is initially empty' do
|
200
|
+
expect(@stack).to be_empty
|
201
|
+
end
|
202
|
+
|
203
|
+
context "after an item has been pushed" do
|
204
|
+
before(:example) do
|
205
|
+
@stack.push :item
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'allows the pushed item to be popped' do
|
209
|
+
expect(@stack.pop).to eq(:item)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
Under the covers, this is (roughly) equivalent to:
|
216
|
+
|
217
|
+
``` ruby
|
218
|
+
class UsingAnArrayAsAStack < RSpec::Core::ExampleGroup
|
219
|
+
def build_stack
|
220
|
+
[]
|
221
|
+
end
|
222
|
+
|
223
|
+
def before_example_1
|
224
|
+
@stack = build_stack
|
225
|
+
end
|
226
|
+
|
227
|
+
def it_is_initially_empty
|
228
|
+
expect(@stack).to be_empty
|
229
|
+
end
|
230
|
+
|
231
|
+
class AfterAnItemHasBeenPushed < self
|
232
|
+
def before_example_2
|
233
|
+
@stack.push :item
|
234
|
+
end
|
235
|
+
|
236
|
+
def it_allows_the_pushed_item_to_be_popped
|
237
|
+
expect(@stack.pop).to eq(:item)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
```
|
242
|
+
|
243
|
+
To run these examples, RSpec would (roughly) do the following:
|
244
|
+
|
245
|
+
``` ruby
|
246
|
+
example_1 = UsingAnArrayAsAStack.new
|
247
|
+
example_1.before_example_1
|
248
|
+
example_1.it_is_initially_empty
|
249
|
+
|
250
|
+
example_2 = UsingAnArrayAsAStack::AfterAnItemHasBeenPushed.new
|
251
|
+
example_2.before_example_1
|
252
|
+
example_2.before_example_2
|
253
|
+
example_2.it_allows_the_pushed_item_to_be_popped
|
254
|
+
```
|
255
|
+
|
256
|
+
## The `rspec` Command
|
257
|
+
|
258
|
+
When you install the rspec-core gem, it installs the `rspec` executable,
|
259
|
+
which you'll use to run rspec. The `rspec` command comes with many useful
|
260
|
+
options.
|
261
|
+
Run `rspec --help` to see the complete list.
|
262
|
+
|
263
|
+
## Store Command Line Options `.rspec`
|
264
|
+
|
265
|
+
You can store command line options in a `.rspec` file in the project's root
|
266
|
+
directory, and the `rspec` command will read them as though you typed them on
|
267
|
+
the command line.
|
268
|
+
|
269
|
+
## Get Started
|
270
|
+
|
271
|
+
Start with a simple example of behavior you expect from your system. Do
|
272
|
+
this before you write any implementation code:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
# in spec/calculator_spec.rb
|
276
|
+
RSpec.describe Calculator do
|
277
|
+
describe '#add' do
|
278
|
+
it 'returns the sum of its arguments' do
|
279
|
+
expect(Calculator.new.add(1, 2)).to eq(3)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
```
|
284
|
+
|
285
|
+
Run this with the rspec command, and watch it fail:
|
286
|
+
|
287
|
+
```
|
288
|
+
$ rspec spec/calculator_spec.rb
|
289
|
+
./spec/calculator_spec.rb:1: uninitialized constant Calculator
|
290
|
+
```
|
291
|
+
|
292
|
+
Address the failure by defining a skeleton of the `Calculator` class:
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
# in lib/calculator.rb
|
296
|
+
class Calculator
|
297
|
+
def add(a, b)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
```
|
301
|
+
|
302
|
+
Be sure to require the implementation file in the spec:
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
# in spec/calculator_spec.rb
|
306
|
+
# - RSpec adds ./lib to the $LOAD_PATH
|
307
|
+
require "calculator"
|
308
|
+
```
|
309
|
+
|
310
|
+
Now run the spec again, and watch the expectation fail:
|
311
|
+
|
312
|
+
```
|
313
|
+
$ rspec spec/calculator_spec.rb
|
314
|
+
F
|
315
|
+
|
316
|
+
Failures:
|
317
|
+
|
318
|
+
1) Calculator#add returns the sum of its arguments
|
319
|
+
Failure/Error: expect(Calculator.new.add(1, 2)).to eq(3)
|
320
|
+
|
321
|
+
expected: 3
|
322
|
+
got: nil
|
323
|
+
|
324
|
+
(compared using ==)
|
325
|
+
# ./spec/calcalator_spec.rb:6:in `block (3 levels) in <top (required)>'
|
326
|
+
|
327
|
+
Finished in 0.00131 seconds (files took 0.10968 seconds to load)
|
328
|
+
1 example, 1 failure
|
329
|
+
|
330
|
+
Failed examples:
|
331
|
+
|
332
|
+
rspec ./spec/calcalator_spec.rb:5 # Calculator#add returns the sum of its arguments
|
333
|
+
```
|
334
|
+
|
335
|
+
Implement the simplest solution, by changing the definition of `Calculator#add` to:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
def add(a, b)
|
339
|
+
a + b
|
340
|
+
end
|
341
|
+
```
|
342
|
+
|
343
|
+
Now run the spec again, and watch it pass:
|
344
|
+
|
345
|
+
```
|
346
|
+
$ rspec spec/calculator_spec.rb
|
347
|
+
.
|
348
|
+
|
349
|
+
Finished in 0.000315 seconds
|
350
|
+
1 example, 0 failures
|
351
|
+
```
|
352
|
+
|
353
|
+
Use the `documentation` formatter to see the resulting spec:
|
354
|
+
|
355
|
+
```
|
356
|
+
$ rspec spec/calculator_spec.rb --format doc
|
357
|
+
Calculator
|
358
|
+
#add
|
359
|
+
returns the sum of its arguments
|
360
|
+
|
361
|
+
Finished in 0.000379 seconds
|
362
|
+
1 example, 0 failures
|
363
|
+
```
|
364
|
+
|
365
|
+
## Contributing
|
366
|
+
|
367
|
+
Once you've set up the environment, you'll need to cd into the working
|
368
|
+
directory of whichever repo you want to work in. From there you can run the
|
369
|
+
specs and cucumber features, and make patches.
|
370
|
+
|
371
|
+
NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. You
|
372
|
+
can treat each RSpec repo as an independent project.
|
373
|
+
|
374
|
+
* [Build details](BUILD_DETAIL.md)
|
375
|
+
* [Code of Conduct](CODE_OF_CONDUCT.md)
|
376
|
+
* [Detailed contributing guide](CONTRIBUTING.md)
|
377
|
+
* [Development setup guide](DEVELOPMENT.md)
|
378
|
+
|
379
|
+
## Also see
|
380
|
+
|
381
|
+
* [https://github.com/rspec/rspec](https://github.com/rspec/rspec)
|
382
|
+
* [https://github.com/rspec/rspec-expectations](https://github.com/rspec/rspec-expectations)
|
383
|
+
* [https://github.com/rspec/rspec-mocks](https://github.com/rspec/rspec-mocks)
|
384
|
+
* [https://github.com/rspec/rspec-rails](https://github.com/rspec/rspec-rails)
|
data/exe/rspec
ADDED
data/lib/rspec/core.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
# rubocop:disable Style/GlobalVars
|
2
|
+
$_rspec_core_load_started_at = Time.now
|
3
|
+
# rubocop:enable Style/GlobalVars
|
4
|
+
|
5
|
+
require "rspec/support"
|
6
|
+
RSpec::Support.require_rspec_support "caller_filter"
|
7
|
+
|
8
|
+
RSpec::Support.define_optimized_require_for_rspec(:core) { |f| require_relative f }
|
9
|
+
|
10
|
+
%w[
|
11
|
+
version
|
12
|
+
warnings
|
13
|
+
|
14
|
+
set
|
15
|
+
flat_map
|
16
|
+
filter_manager
|
17
|
+
dsl
|
18
|
+
notifications
|
19
|
+
reporter
|
20
|
+
|
21
|
+
hooks
|
22
|
+
memoized_helpers
|
23
|
+
metadata
|
24
|
+
metadata_filter
|
25
|
+
pending
|
26
|
+
formatters
|
27
|
+
ordering
|
28
|
+
|
29
|
+
world
|
30
|
+
configuration
|
31
|
+
option_parser
|
32
|
+
configuration_options
|
33
|
+
runner
|
34
|
+
invocations
|
35
|
+
example
|
36
|
+
shared_example_group
|
37
|
+
example_group
|
38
|
+
].each { |name| RSpec::Support.require_rspec_core name }
|
39
|
+
|
40
|
+
# Namespace for all core RSpec code.
|
41
|
+
module RSpec
|
42
|
+
autoload :SharedContext, 'rspec/core/shared_context'
|
43
|
+
|
44
|
+
extend RSpec::Core::Warnings
|
45
|
+
|
46
|
+
class << self
|
47
|
+
# Setters for shared global objects
|
48
|
+
# @api private
|
49
|
+
attr_writer :configuration, :world
|
50
|
+
end
|
51
|
+
|
52
|
+
# Used to ensure examples get reloaded and user configuration gets reset to
|
53
|
+
# defaults between multiple runs in the same process.
|
54
|
+
#
|
55
|
+
# Users must invoke this if they want to have the configuration reset when
|
56
|
+
# they use the runner multiple times within the same process. Users must deal
|
57
|
+
# themselves with re-configuration of RSpec before run.
|
58
|
+
def self.reset
|
59
|
+
RSpec::ExampleGroups.remove_all_constants
|
60
|
+
@world = nil
|
61
|
+
@configuration = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# Used to ensure examples get reloaded between multiple runs in the same
|
65
|
+
# process and ensures user configuration is persisted.
|
66
|
+
#
|
67
|
+
# Users must invoke this if they want to clear all examples but preserve
|
68
|
+
# current configuration when they use the runner multiple times within the
|
69
|
+
# same process.
|
70
|
+
def self.clear_examples
|
71
|
+
world.reset
|
72
|
+
configuration.reset_reporter
|
73
|
+
configuration.start_time = ::RSpec::Core::Time.now
|
74
|
+
configuration.reset_filters
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns the global [Configuration](RSpec/Core/Configuration) object. While
|
78
|
+
# you _can_ use this method to access the configuration, the more common
|
79
|
+
# convention is to use [RSpec.configure](RSpec#configure-class_method).
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# RSpec.configuration.drb_port = 1234
|
83
|
+
# @see RSpec.configure
|
84
|
+
# @see Core::Configuration
|
85
|
+
def self.configuration
|
86
|
+
@configuration ||= RSpec::Core::Configuration.new
|
87
|
+
end
|
88
|
+
|
89
|
+
# Yields the global configuration to a block.
|
90
|
+
# @yield [Configuration] global configuration
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# RSpec.configure do |config|
|
94
|
+
# config.add_formatter 'documentation'
|
95
|
+
# end
|
96
|
+
# @see Core::Configuration
|
97
|
+
def self.configure
|
98
|
+
yield configuration if block_given?
|
99
|
+
end
|
100
|
+
|
101
|
+
# The example being executed.
|
102
|
+
#
|
103
|
+
# The primary audience for this method is library authors who need access
|
104
|
+
# to the example currently being executed and also want to support all
|
105
|
+
# versions of RSpec 2 and 3.
|
106
|
+
#
|
107
|
+
# @example
|
108
|
+
#
|
109
|
+
# RSpec.configure do |c|
|
110
|
+
# # context.example is deprecated, but RSpec.current_example is not
|
111
|
+
# # available until RSpec 3.0.
|
112
|
+
# fetch_current_example = RSpec.respond_to?(:current_example) ?
|
113
|
+
# proc { RSpec.current_example } : proc { |context| context.example }
|
114
|
+
#
|
115
|
+
# c.before(:example) do
|
116
|
+
# example = fetch_current_example.call(self)
|
117
|
+
#
|
118
|
+
# # ...
|
119
|
+
# end
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
def self.current_example
|
123
|
+
RSpec::Support.thread_local_data[:current_example]
|
124
|
+
end
|
125
|
+
|
126
|
+
# Set the current example being executed.
|
127
|
+
# @api private
|
128
|
+
def self.current_example=(example)
|
129
|
+
RSpec::Support.thread_local_data[:current_example] = example
|
130
|
+
end
|
131
|
+
|
132
|
+
# @private
|
133
|
+
# Internal container for global non-configuration data.
|
134
|
+
def self.world
|
135
|
+
@world ||= RSpec::Core::World.new
|
136
|
+
end
|
137
|
+
|
138
|
+
# Namespace for the rspec-core code.
|
139
|
+
module Core
|
140
|
+
autoload :ExampleStatusPersister, "rspec/core/example_status_persister"
|
141
|
+
autoload :Profiler, "rspec/core/profiler"
|
142
|
+
|
143
|
+
# @private
|
144
|
+
# This avoids issues with reporting time caused by examples that
|
145
|
+
# change the value/meaning of Time.now without properly restoring
|
146
|
+
# it.
|
147
|
+
class Time
|
148
|
+
class << self
|
149
|
+
define_method(:now, &::Time.method(:now))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# @private path to executable file.
|
154
|
+
def self.path_to_executable
|
155
|
+
@path_to_executable ||= File.expand_path('../../../exe/rspec', __FILE__)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# @private
|
160
|
+
MODULES_TO_AUTOLOAD = {
|
161
|
+
:Matchers => "rspec/expectations",
|
162
|
+
:Expectations => "rspec/expectations",
|
163
|
+
:Mocks => "rspec/mocks"
|
164
|
+
}
|
165
|
+
|
166
|
+
# @private
|
167
|
+
def self.const_missing(name)
|
168
|
+
# Load rspec-expectations when RSpec::Matchers is referenced. This allows
|
169
|
+
# people to define custom matchers (using `RSpec::Matchers.define`) before
|
170
|
+
# rspec-core has loaded rspec-expectations (since it delays the loading of
|
171
|
+
# it to allow users to configure a different assertion/expectation
|
172
|
+
# framework). `autoload` can't be used since it works with ruby's built-in
|
173
|
+
# require (e.g. for files that are available relative to a load path dir),
|
174
|
+
# but not with rubygems' extended require.
|
175
|
+
#
|
176
|
+
# As of rspec 2.14.1, we no longer require `rspec/mocks` and
|
177
|
+
# `rspec/expectations` when `rspec` is required, so we want
|
178
|
+
# to make them available as an autoload.
|
179
|
+
require MODULES_TO_AUTOLOAD.fetch(name) { return super }
|
180
|
+
::RSpec.const_get(name)
|
181
|
+
end
|
182
|
+
|
183
|
+
Core::DSL.expose_globally!
|
184
|
+
Core::SharedExampleGroup::TopLevelDSL.expose_globally!
|
185
|
+
end
|