r_spec 1.0.0.beta5 → 1.0.0.beta6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -11
- data/lib/r_spec.rb +2 -2
- data/lib/r_spec/console.rb +38 -0
- data/lib/r_spec/dsl.rb +204 -28
- data/lib/r_spec/error.rb +4 -4
- data/lib/r_spec/error/pending_expectation.rb +2 -2
- data/lib/r_spec/expectation_helper.rb +3 -3
- data/lib/r_spec/expectation_helper/base.rb +1 -18
- data/lib/r_spec/expectation_helper/it.rb +1 -1
- data/lib/r_spec/expectation_helper/its.rb +1 -1
- data/lib/r_spec/expectation_target.rb +3 -3
- data/lib/r_spec/expectation_target/base.rb +12 -3
- data/lib/r_spec/expectation_target/block.rb +1 -10
- data/lib/r_spec/expectation_target/value.rb +0 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6facf7764beddac81425ab44d80ed3b306f6c63c3532401bb658240654b06845
|
4
|
+
data.tar.gz: 944d53b22a1ffeeca3afe990aa99a613493f9ff1b3aad3ceaa43ae0b9a8ec019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c28b4fbd53cf2a368022418c2ccbbf31cf4a35abce141f0999285bff90b4c84d7f36209894dafcf5362464d01fad3dcb724d942ae5db5c1095387997b087964f
|
7
|
+
data.tar.gz: 4c7a23212c2ce90a67b04e9fe25dda7812c37902eba8f6febdb9e4e2dcd33633fa43642d6905f9bfffa6215b467eb88cbb921d596f0276fb788cc876bc63e291
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A minimalist __[RSpec](https://github.com/rspec/rspec) clone__ with all the essentials.
|
4
4
|
|
5
|
-

|
6
6
|
|
7
7
|
## Status
|
8
8
|
|
@@ -46,7 +46,7 @@ Following [RubyGems naming conventions](https://guides.rubygems.org/name-your-ge
|
|
46
46
|
Add this line to your application's Gemfile:
|
47
47
|
|
48
48
|
```ruby
|
49
|
-
gem "r_spec", ">= 1.0.0.
|
49
|
+
gem "r_spec", ">= 1.0.0.beta6"
|
50
50
|
```
|
51
51
|
|
52
52
|
And then execute:
|
@@ -81,16 +81,15 @@ Many projects use a custom spec helper which organizes these includes.
|
|
81
81
|
Concrete test cases are defined in `it` blocks.
|
82
82
|
An optional descriptive string states it's purpose and a block contains the main logic performing the test.
|
83
83
|
|
84
|
+
Test cases that have been defined or outlined but are not yet expected to work can be defined using `pending` instead of `it`. They will not be run but show up in the spec report as pending.
|
85
|
+
|
84
86
|
An `it` block contains an example that should invoke the code to be tested and define what is expected of it.
|
85
87
|
Each example can contain multiple expectations, but it should test only one specific behaviour.
|
86
88
|
|
87
|
-
To express an expectation, wrap an object or block in `expect`, call `to` or `not_to` and pass it a matcher object.
|
88
|
-
|
89
|
+
To express an expectation, wrap an object or block in `expect`, call `to` (or `not_to`) and pass it a matcher object.
|
89
90
|
If the expectation is met, code execution continues.
|
90
91
|
Otherwise the example has _failed_ and other code will not be executed.
|
91
92
|
|
92
|
-
Test cases that have been defined or outlined but are not yet expected to work can be defined using `pending` instead of `expect`. They will not be run but show up in the spec report as pending.
|
93
|
-
|
94
93
|
In test files, specs are structured by example groups which are defined by `describe` and `context` sections.
|
95
94
|
Typically a top level `describe` defines the outer unit (such as a class) to be tested by the spec.
|
96
95
|
Further `describe` sections can be nested within the outer unit to specify smaller units under test (such as individual methods).
|
@@ -100,7 +99,7 @@ For unit tests, it is recommended to follow the conventions for method names:
|
|
100
99
|
* outer `describe` is the name of the class, inner `describe` targets methods;
|
101
100
|
* instance methods are prefixed with `#`, class methods with `.`.
|
102
101
|
|
103
|
-
To establish certain contexts
|
102
|
+
To establish certain contexts — think _empty array_ versus _array with elements_ — the `context` method may be used to communicate this to the reader.
|
104
103
|
It has a different name, but behaves exactly like `describe`.
|
105
104
|
|
106
105
|
`describe` and `context` take an optional description as argument and a block containing the individual specs or nested groupings.
|
@@ -214,6 +213,16 @@ task spec: :test
|
|
214
213
|
task default: :test
|
215
214
|
```
|
216
215
|
|
216
|
+
## Performance
|
217
|
+
|
218
|
+
Benchmark against an single expectation executed 100 times from the console.
|
219
|
+
|
220
|
+
| Framework | Seconds to complete |
|
221
|
+
|-------------|---------------------|
|
222
|
+
| RSpec clone | [13.2](https://github.com/cyril/r_spec.rb/blob/main/benchmark/r_spec.rb) |
|
223
|
+
| RSpec | [32.7](https://github.com/cyril/r_spec.rb/blob/main/benchmark/rspec.rb) |
|
224
|
+
| minitest | [17.6](https://github.com/cyril/r_spec.rb/blob/main/benchmark/minitest.rb) |
|
225
|
+
|
217
226
|
## Test suite
|
218
227
|
|
219
228
|
__RSpec clone__'s specifications are self-described here: [spec/](https://github.com/cyril/r_spec.rb/blob/main/spec/)
|
@@ -224,10 +233,6 @@ __RSpec clone__'s specifications are self-described here: [spec/](https://github
|
|
224
233
|
* Source code: https://github.com/cyril/r_spec.rb
|
225
234
|
* Twitter: [https://twitter.com/cyri\_](https://twitter.com/cyri\_)
|
226
235
|
|
227
|
-
## Versioning
|
228
|
-
|
229
|
-
__RSpec clone__ follows [Semantic Versioning 2.0](https://semver.org/).
|
230
|
-
|
231
236
|
## Special thanks ❤️
|
232
237
|
|
233
238
|
I would like to thank the whole [RSpec team](https://rspec.info/about/) for all their work.
|
@@ -241,6 +246,10 @@ If you like this project please consider making a small donation.
|
|
241
246
|
|
242
247
|
[](https://etherscan.io/address/0x834b5c1feaff5aebf9cd0f25dc38e741d65ab773)
|
243
248
|
|
249
|
+
## Versioning
|
250
|
+
|
251
|
+
__RSpec clone__ follows [Semantic Versioning 2.0](https://semver.org/).
|
252
|
+
|
244
253
|
## License
|
245
254
|
|
246
255
|
The [gem](https://rubygems.org/gems/r_spec) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/r_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative File.join("r_spec", "dsl")
|
4
|
+
|
3
5
|
# Top level namespace for the RSpec clone.
|
4
6
|
#
|
5
7
|
# @example The true from the false
|
@@ -73,5 +75,3 @@ module RSpec
|
|
73
75
|
Dsl.describe(const, &block)
|
74
76
|
end
|
75
77
|
end
|
76
|
-
|
77
|
-
require_relative File.join("r_spec", "dsl")
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
# Send log messages to the console.
|
5
|
+
#
|
6
|
+
# @api private
|
7
|
+
module Console
|
8
|
+
# @param report [::Expresenter::Pass] Passed expectation result presenter.
|
9
|
+
#
|
10
|
+
# @see https://github.com/fixrb/expresenter
|
11
|
+
#
|
12
|
+
# @return [nil] Add a colored message to `$stdout`.
|
13
|
+
def self.passed_spec(report)
|
14
|
+
puts report.colored_string
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param report [::Expresenter::Fail] Failed expectation result presenter.
|
18
|
+
#
|
19
|
+
# @see https://github.com/fixrb/expresenter
|
20
|
+
#
|
21
|
+
# @raise [SystemExit] Terminate execution immediately with colored message.
|
22
|
+
def self.failed_spec(report)
|
23
|
+
abort report.colored_string
|
24
|
+
end
|
25
|
+
|
26
|
+
# The Ruby source filename and line number containing this method or nil if
|
27
|
+
# this method was not defined in Ruby (i.e. native).
|
28
|
+
#
|
29
|
+
# @param filename [String, nil] The Ruby source filename.
|
30
|
+
# @param line [Integer, nil] The Ruby source line number.
|
31
|
+
#
|
32
|
+
# @return [String] The Ruby source filename and line number associated with
|
33
|
+
# the evaluated spec.
|
34
|
+
def self.source(filename, line)
|
35
|
+
puts [filename, line].compact.join(":")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/r_spec/dsl.rb
CHANGED
@@ -2,22 +2,100 @@
|
|
2
2
|
|
3
3
|
require "securerandom"
|
4
4
|
|
5
|
+
require_relative "console"
|
6
|
+
require_relative "error"
|
7
|
+
require_relative "expectation_helper"
|
8
|
+
require_relative "sandbox"
|
9
|
+
|
5
10
|
module RSpec
|
6
11
|
# Abstract class for handling the domain-specific language.
|
7
12
|
class Dsl
|
8
|
-
#
|
9
|
-
#
|
13
|
+
# Executes the given block before each spec in the current context runs.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# require "r_spec"
|
17
|
+
#
|
18
|
+
# RSpec.describe Integer do
|
19
|
+
# before do
|
20
|
+
# @value = 123
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# it { expect(@value).to be 123 }
|
24
|
+
#
|
25
|
+
# describe "nested" do
|
26
|
+
# before do
|
27
|
+
# @value -= 81
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# it { expect(@value).to be 42 }
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# it { expect(@value).to be 123 }
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # Output to the console
|
37
|
+
# # Success: expected to be 123.
|
38
|
+
# # Success: expected to be 42.
|
39
|
+
# # Success: expected to be 123.
|
10
40
|
#
|
11
41
|
# @param block [Proc] The content to execute at the class initialization.
|
12
42
|
def self.before(&block)
|
13
|
-
define_method(:initialize) do
|
43
|
+
define_method(:initialize) do
|
14
44
|
super()
|
15
|
-
|
45
|
+
instance_eval(&block)
|
16
46
|
end
|
47
|
+
|
48
|
+
private :initialize
|
49
|
+
end
|
50
|
+
|
51
|
+
# Executes the given block after each spec in the current context runs.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# require "r_spec"
|
55
|
+
#
|
56
|
+
# RSpec.describe Integer do
|
57
|
+
# after do
|
58
|
+
# puts "That is the answer to everything."
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# it { expect(42).to be 42 }
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# # Output to the console
|
65
|
+
# # Success: expected to be 42.
|
66
|
+
# # That is the answer to everything.
|
67
|
+
#
|
68
|
+
# @param block [Proc] The content to execute at the class initialization.
|
69
|
+
def self.after(&block)
|
70
|
+
define_method(:terminate) do
|
71
|
+
instance_exec(&block)
|
72
|
+
super()
|
73
|
+
end
|
74
|
+
|
75
|
+
private :terminate
|
17
76
|
end
|
18
77
|
|
19
78
|
# Sets a user-defined property.
|
20
79
|
#
|
80
|
+
# @example
|
81
|
+
# require "r_spec"
|
82
|
+
#
|
83
|
+
# RSpec.describe do
|
84
|
+
# let(:name) { "Bob" }
|
85
|
+
#
|
86
|
+
# it { expect(name).to eq "Bob" }
|
87
|
+
#
|
88
|
+
# context "with last name" do
|
89
|
+
# let(:name) { "#{super()} Smith" }
|
90
|
+
#
|
91
|
+
# it { expect(name).to eq "Bob Smith" }
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# # Output to the console
|
96
|
+
# # Success: expected to eq "Bob".
|
97
|
+
# # Success: expected to eq "Bob Smith".
|
98
|
+
#
|
21
99
|
# @param name [String, Symbol] The name of the property.
|
22
100
|
# @param block [Proc] The content of the method to define.
|
23
101
|
#
|
@@ -26,20 +104,46 @@ module RSpec
|
|
26
104
|
protected define_method(name.to_sym, *args, **kwargs, &block)
|
27
105
|
end
|
28
106
|
|
29
|
-
# Sets a user-defined property named
|
107
|
+
# Sets a user-defined property named {#subject}.
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# require "r_spec"
|
111
|
+
#
|
112
|
+
# RSpec.describe Array do
|
113
|
+
# subject { [1, 2, 3] }
|
114
|
+
#
|
115
|
+
# it "has the prescribed elements" do
|
116
|
+
# expect(subject).to eq([1, 2, 3])
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# # Output to the console
|
121
|
+
# # Success: expected to eq [1, 2, 3].
|
30
122
|
#
|
31
123
|
# @param block [Proc] The subject to set.
|
32
|
-
# @return [Symbol] A
|
124
|
+
# @return [Symbol] A {#subject} method that define the block content.
|
33
125
|
def self.subject(&block)
|
34
126
|
let(__method__, &block)
|
35
127
|
end
|
36
128
|
|
37
|
-
#
|
129
|
+
# Defines an example group that describes a unit to be tested.
|
130
|
+
#
|
131
|
+
# @example
|
132
|
+
# require "r_spec"
|
133
|
+
#
|
134
|
+
# RSpec.describe String do
|
135
|
+
# describe "+" do
|
136
|
+
# it("concats") { expect("foo" + "bar").to eq "foobar" }
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# # Output to the console
|
141
|
+
# # Success: expected to eq "foobar".
|
38
142
|
#
|
39
143
|
# @param const [Module, #object_id] A module to include in block context.
|
40
144
|
# @param block [Proc] The block to define the specs.
|
41
145
|
def self.describe(const = nil, &block)
|
42
|
-
desc = Sandbox.const_set(
|
146
|
+
desc = Sandbox.const_set(random_context_const_name, ::Class.new(self))
|
43
147
|
|
44
148
|
if const.is_a?(::Module)
|
45
149
|
desc.define_method(:described_class) { const }
|
@@ -47,14 +151,41 @@ module RSpec
|
|
47
151
|
end
|
48
152
|
|
49
153
|
desc.instance_eval(&block)
|
50
|
-
desc
|
51
154
|
end
|
52
155
|
|
53
|
-
#
|
54
|
-
|
156
|
+
# Defines an example group that establishes a specific context, like _empty
|
157
|
+
# array_ versus _array with elements_.
|
158
|
+
#
|
159
|
+
# It is functionally equivalent to {.describe}.
|
160
|
+
#
|
161
|
+
# @example
|
162
|
+
# require "r_spec"
|
163
|
+
#
|
164
|
+
# RSpec.describe do
|
165
|
+
# context "when resource is not found" do
|
166
|
+
# pending "responds with 404"
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
# context "when resource is found" do
|
170
|
+
# pending "responds with 200"
|
171
|
+
# end
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# # Output to the console
|
175
|
+
# # Warning: responds with 404.
|
176
|
+
# # Warning: responds with 200.
|
177
|
+
#
|
178
|
+
# @param _description [String] A description that usually begins with
|
179
|
+
# "when", "with" or "without".
|
180
|
+
# @param block [Proc] The block to define the specs.
|
181
|
+
def self.context(_description = nil, &block)
|
182
|
+
desc = Sandbox.const_set(random_context_const_name, ::Class.new(self))
|
183
|
+
desc.instance_eval(&block)
|
184
|
+
end
|
55
185
|
|
56
|
-
#
|
57
|
-
#
|
186
|
+
# Defines a concrete test case.
|
187
|
+
#
|
188
|
+
# The test is performed by the block supplied to `&block`.
|
58
189
|
#
|
59
190
|
# @example The integer after 41
|
60
191
|
# require "r_spec"
|
@@ -83,22 +214,29 @@ module RSpec
|
|
83
214
|
# # Success: expected 41 to be an instance of Integer.
|
84
215
|
# # Success: divided by 0.
|
85
216
|
#
|
217
|
+
# It can be used inside a {.describe} or {.context} section.
|
218
|
+
#
|
86
219
|
# @param _name [String, nil] The name of the spec.
|
87
220
|
# @param block [Proc] An expectation to evaluate.
|
88
221
|
#
|
89
222
|
# @raise (see ExpectationTarget::Base#result)
|
90
223
|
# @return (see ExpectationTarget::Base#result)
|
91
224
|
def self.it(_name = nil, &block)
|
92
|
-
raise ::ArgumentError, "Missing block" unless block
|
93
|
-
|
94
|
-
puts "\e[37m#{block.source_location.join(':')}\e[0m"
|
225
|
+
raise ::ArgumentError, "Missing example block" unless block
|
95
226
|
|
96
227
|
i = it_example.new
|
97
228
|
i.instance_eval(&block)
|
229
|
+
rescue ::SystemExit
|
230
|
+
Console.source(*block.source_location)
|
231
|
+
|
232
|
+
exit false
|
233
|
+
ensure
|
234
|
+
i.send(:terminate)
|
98
235
|
end
|
99
236
|
|
100
|
-
# Use the
|
101
|
-
# value of an attribute of the subject using
|
237
|
+
# Use the {.its} method to define a single spec that specifies the actual
|
238
|
+
# value of an attribute of the subject using
|
239
|
+
# {ExpectationHelper::Its#is_expected}.
|
102
240
|
#
|
103
241
|
# @example The integer after 41
|
104
242
|
# require "r_spec"
|
@@ -142,9 +280,7 @@ module RSpec
|
|
142
280
|
# @raise (see ExpectationTarget::Base#result)
|
143
281
|
# @return (see ExpectationTarget::Base#result)
|
144
282
|
def self.its(attribute, *args, **kwargs, &block)
|
145
|
-
raise ::ArgumentError, "Missing block" unless block
|
146
|
-
|
147
|
-
puts "\e[37m#{block.source_location.join(':')}\e[0m"
|
283
|
+
raise ::ArgumentError, "Missing example block" unless block
|
148
284
|
|
149
285
|
i = its_example.new
|
150
286
|
|
@@ -153,6 +289,48 @@ module RSpec
|
|
153
289
|
end
|
154
290
|
|
155
291
|
i.instance_eval(&block)
|
292
|
+
rescue ::SystemExit
|
293
|
+
Console.source(*block.source_location)
|
294
|
+
|
295
|
+
exit false
|
296
|
+
ensure
|
297
|
+
i.send(:terminate)
|
298
|
+
end
|
299
|
+
|
300
|
+
# Defines a pending test case.
|
301
|
+
#
|
302
|
+
# `&block` is never evaluated. It can be used to describe behaviour that is
|
303
|
+
# not yet implemented.
|
304
|
+
#
|
305
|
+
# @example
|
306
|
+
# require "r_spec"
|
307
|
+
#
|
308
|
+
# RSpec.describe do
|
309
|
+
# pending "is implemented but waiting" do
|
310
|
+
# expect("something").to eq("getting finished")
|
311
|
+
# end
|
312
|
+
# end
|
313
|
+
#
|
314
|
+
# # Output to the console
|
315
|
+
# # Warning: is implemented but waiting.
|
316
|
+
#
|
317
|
+
# @example
|
318
|
+
# require "r_spec"
|
319
|
+
#
|
320
|
+
# RSpec.describe do
|
321
|
+
# pending "is not yet implemented and waiting"
|
322
|
+
# end
|
323
|
+
#
|
324
|
+
# # Output to the console
|
325
|
+
# # Warning: is not yet implemented and waiting.
|
326
|
+
#
|
327
|
+
# @param message [String] The reason why the example is pending.
|
328
|
+
#
|
329
|
+
# @return [nil] Write a message to STDOUT.
|
330
|
+
#
|
331
|
+
# @api public
|
332
|
+
def self.pending(message)
|
333
|
+
Console.passed_spec Error::PendingExpectation.result(message)
|
156
334
|
end
|
157
335
|
|
158
336
|
# @private
|
@@ -172,11 +350,11 @@ module RSpec
|
|
172
350
|
# @private
|
173
351
|
#
|
174
352
|
# @return [String] A random constant name for a test class.
|
175
|
-
def self.
|
176
|
-
"
|
353
|
+
def self.random_context_const_name
|
354
|
+
"Context#{::SecureRandom.hex(4).to_i(16)}"
|
177
355
|
end
|
178
356
|
|
179
|
-
private_class_method :it_example, :its_example, :
|
357
|
+
private_class_method :it_example, :its_example, :random_context_const_name
|
180
358
|
|
181
359
|
protected
|
182
360
|
|
@@ -188,9 +366,7 @@ module RSpec
|
|
188
366
|
def subject
|
189
367
|
raise Error::UndefinedSubject, "subject not explicitly defined"
|
190
368
|
end
|
369
|
+
|
370
|
+
def terminate; end
|
191
371
|
end
|
192
372
|
end
|
193
|
-
|
194
|
-
require_relative "error"
|
195
|
-
require_relative "expectation_helper"
|
196
|
-
require_relative "sandbox"
|
data/lib/r_spec/error.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative File.join("error", "pending_expectation")
|
4
|
+
require_relative File.join("error", "undefined_described_class")
|
5
|
+
require_relative File.join("error", "undefined_subject")
|
6
|
+
|
3
7
|
module RSpec
|
4
8
|
# Namespace for exceptions.
|
5
9
|
#
|
@@ -7,7 +11,3 @@ module RSpec
|
|
7
11
|
module Error
|
8
12
|
end
|
9
13
|
end
|
10
|
-
|
11
|
-
require_relative File.join("error", "pending_expectation")
|
12
|
-
require_relative File.join("error", "undefined_described_class")
|
13
|
-
require_relative File.join("error", "undefined_subject")
|
@@ -12,7 +12,7 @@ module RSpec
|
|
12
12
|
#
|
13
13
|
# @return [nil] Write a pending expectation to STDOUT.
|
14
14
|
def self.result(message)
|
15
|
-
|
15
|
+
::Expresenter.call(true).with(
|
16
16
|
actual: new(message),
|
17
17
|
error: nil,
|
18
18
|
expected: self,
|
@@ -21,7 +21,7 @@ module RSpec
|
|
21
21
|
negate: true,
|
22
22
|
level: :SHOULD,
|
23
23
|
valid: false
|
24
|
-
)
|
24
|
+
)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative File.join("expectation_helper", "it")
|
4
|
+
require_relative File.join("expectation_helper", "its")
|
5
|
+
|
3
6
|
module RSpec
|
4
7
|
# Namespace for `it` and `its` helper modules.
|
5
8
|
module ExpectationHelper
|
6
9
|
end
|
7
10
|
end
|
8
|
-
|
9
|
-
require_relative File.join("expectation_helper", "it")
|
10
|
-
require_relative File.join("expectation_helper", "its")
|
@@ -9,7 +9,7 @@ module RSpec
|
|
9
9
|
# Abstract expectation helper base module.
|
10
10
|
#
|
11
11
|
# This module defines a number of methods to create expectations, which are
|
12
|
-
# automatically included into
|
12
|
+
# automatically included into examples.
|
13
13
|
#
|
14
14
|
# It also includes a collection of expectation matchers 🤹
|
15
15
|
#
|
@@ -77,23 +77,6 @@ module RSpec
|
|
77
77
|
# @see https://github.com/fixrb/matchi-rspec
|
78
78
|
module Base
|
79
79
|
include ::Matchi::Helper
|
80
|
-
|
81
|
-
# Mark a spec as pending, expectation results will be ignored.
|
82
|
-
#
|
83
|
-
# @param description [String] The reason why the example is pending.
|
84
|
-
#
|
85
|
-
# @return [nil] Write a message to STDOUT.
|
86
|
-
#
|
87
|
-
# @example Output a message to the console and return nil
|
88
|
-
# pending("something else getting finished") # => nil
|
89
|
-
#
|
90
|
-
# # Output to the console
|
91
|
-
# # Warning: something else getting finished.
|
92
|
-
#
|
93
|
-
# @api public
|
94
|
-
def pending(description)
|
95
|
-
Error::PendingExpectation.result(description)
|
96
|
-
end
|
97
80
|
end
|
98
81
|
end
|
99
82
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative File.join("expectation_target", "block")
|
4
|
+
require_relative File.join("expectation_target", "value")
|
5
|
+
|
3
6
|
module RSpec
|
4
7
|
# Wraps the target of an expectation.
|
5
8
|
#
|
@@ -25,6 +28,3 @@ module RSpec
|
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
28
|
-
|
29
|
-
require_relative File.join("expectation_target", "block")
|
30
|
-
require_relative File.join("expectation_target", "value")
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "expresenter"
|
4
4
|
|
5
|
+
require_relative File.join("..", "console")
|
6
|
+
|
5
7
|
module RSpec
|
6
8
|
module ExpectationTarget
|
7
9
|
# Abstract expectation target base class.
|
@@ -9,6 +11,13 @@ module RSpec
|
|
9
11
|
# @note `RSpec::ExpectationTarget::Base` is not intended to be instantiated
|
10
12
|
# directly by users. Use `expect` instead.
|
11
13
|
class Base
|
14
|
+
# Instantiate a new expectation target.
|
15
|
+
#
|
16
|
+
# @param actual [#object_id] The actual value of the code to evaluate.
|
17
|
+
def initialize(actual)
|
18
|
+
@actual = actual
|
19
|
+
end
|
20
|
+
|
12
21
|
# Runs the given expectation, passing if `matcher` returns true.
|
13
22
|
#
|
14
23
|
# @example _Absolute requirement_ definition
|
@@ -55,7 +64,7 @@ module RSpec
|
|
55
64
|
#
|
56
65
|
# @api private
|
57
66
|
def result(actual:, error:, got:, matcher:, negate:, valid:)
|
58
|
-
|
67
|
+
Console.passed_spec ::Expresenter.call(valid).with(
|
59
68
|
actual: actual,
|
60
69
|
error: error,
|
61
70
|
expected: matcher.expected,
|
@@ -64,9 +73,9 @@ module RSpec
|
|
64
73
|
valid: valid,
|
65
74
|
matcher: matcher.class.to_sym,
|
66
75
|
level: :MUST
|
67
|
-
)
|
76
|
+
)
|
68
77
|
rescue ::Expresenter::Fail => e
|
69
|
-
|
78
|
+
Console.failed_spec(e)
|
70
79
|
end
|
71
80
|
end
|
72
81
|
end
|
@@ -20,15 +20,6 @@ module RSpec
|
|
20
20
|
# @note `RSpec::ExpectationTarget::Block` is not intended to be instantiated
|
21
21
|
# directly by users. Use `expect` instead.
|
22
22
|
class Block < Base
|
23
|
-
# Instantiate a new expectation target.
|
24
|
-
#
|
25
|
-
# @param block [#call] The code to evaluate.
|
26
|
-
def initialize(block)
|
27
|
-
super()
|
28
|
-
|
29
|
-
@callable = block
|
30
|
-
end
|
31
|
-
|
32
23
|
protected
|
33
24
|
|
34
25
|
# @param matcher [#matches?] The matcher.
|
@@ -40,7 +31,7 @@ module RSpec
|
|
40
31
|
# `Kernel.exit(false)` with a failure message written to STDERR.
|
41
32
|
def absolute_requirement(matcher:, negate:)
|
42
33
|
exam = ::Spectus::Exam.new(
|
43
|
-
callable: @
|
34
|
+
callable: @actual,
|
44
35
|
isolation: false,
|
45
36
|
negate: negate,
|
46
37
|
matcher: matcher
|
@@ -18,15 +18,6 @@ module RSpec
|
|
18
18
|
# @note `RSpec::ExpectationTarget::Value` is not intended to be instantiated
|
19
19
|
# directly by users. Use `expect` instead.
|
20
20
|
class Value < Base
|
21
|
-
# Instantiate a new expectation target.
|
22
|
-
#
|
23
|
-
# @param actual [#object_id] The actual value.
|
24
|
-
def initialize(actual)
|
25
|
-
super()
|
26
|
-
|
27
|
-
@actual = actual
|
28
|
-
end
|
29
|
-
|
30
21
|
protected
|
31
22
|
|
32
23
|
# @param matcher [#matches?] The matcher.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: expresenter
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- LICENSE.md
|
188
188
|
- README.md
|
189
189
|
- lib/r_spec.rb
|
190
|
+
- lib/r_spec/console.rb
|
190
191
|
- lib/r_spec/dsl.rb
|
191
192
|
- lib/r_spec/error.rb
|
192
193
|
- lib/r_spec/error/pending_expectation.rb
|