spectus 3.1.3 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -10
- data/lib/spectus/requirement_level/base.rb +12 -28
- data/lib/spectus/result.rb +15 -0
- data/lib/spectus/result/common.rb +7 -1
- data/lib/spectus/result/fail.rb +5 -7
- data/lib/spectus/result/pass.rb +5 -7
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73306cc997a51543203fcfbec28fedae74de8ca9f382040db66d1c6aebbfc4bd
|
4
|
+
data.tar.gz: c9d9365b33cc4cca9cb54630306f9320c254a42ad64161d8a609107eeb8f95e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cdfb58c6e5e3b748f8c5071f354793618a6e6e00053e3139175c5afde4cbc2fd39a419fbe516970354a6eaaee585637077d6dcc65b1d3ba7ae5412f26dcce60
|
7
|
+
data.tar.gz: 8211f7d6955d70067071a691bfa80b1f640930c01db4cec6433534141c3f7c7a4e386ee82c80f00941b3c6a04426d2266be7cdb416960e04c5e8a36b0f35bc95
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Spectus
|
2
2
|
|
3
|
-
[![Build Status](https://api.travis-ci.org/fixrb/spectus.svg?branch=
|
3
|
+
[![Build Status](https://api.travis-ci.org/fixrb/spectus.svg?branch=main)][travis]
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fixrb/spectus/badges/gpa.svg)][codeclimate]
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/spectus.svg)][gem]
|
6
|
-
[![Inline docs](https://inch-ci.org/github/fixrb/spectus.svg?branch=
|
6
|
+
[![Inline docs](https://inch-ci.org/github/fixrb/spectus.svg?branch=main)][inchpages]
|
7
7
|
[![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
|
8
8
|
|
9
9
|
> Expectation library with [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt)'s requirement levels 🚥
|
@@ -39,13 +39,21 @@ There are several scenarios:
|
|
39
39
|
|
40
40
|
Thus,
|
41
41
|
|
42
|
-
* when an
|
43
|
-
* when an
|
42
|
+
* when an assertion is `true`, a `Spectus::Result::Pass` instance is returned;
|
43
|
+
* when an assertion is `false`, a `Spectus::Result::Fail` exception is raised.
|
44
44
|
|
45
|
-
Both results share a common interface
|
45
|
+
Both results share a common interface.
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
Passed expectations can be classified as:
|
48
|
+
|
49
|
+
* ✅ success
|
50
|
+
* ⚠️ warning
|
51
|
+
* 💡 info
|
52
|
+
|
53
|
+
Failed expectations can be classified as:
|
54
|
+
|
55
|
+
* ❌ failure
|
56
|
+
* 💥 error
|
49
57
|
|
50
58
|
## Code Isolation
|
51
59
|
|
@@ -141,8 +149,8 @@ The optional `blank?` method is not implemented (unlike in [Ruby on Rails](https
|
|
141
149
|
|
142
150
|
### More Examples
|
143
151
|
|
144
|
-
A full list of unit tests can be viewed here:
|
145
|
-
[test.rb](https://github.com/fixrb/spectus/blob/
|
152
|
+
A full list of unit tests can be viewed (and executed) here:
|
153
|
+
[./test.rb](https://github.com/fixrb/spectus/blob/main/test.rb)
|
146
154
|
|
147
155
|
## Contact
|
148
156
|
|
@@ -162,7 +170,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
162
170
|
<p>
|
163
171
|
This project is sponsored by:<br />
|
164
172
|
<a href="https://sashite.com/"><img
|
165
|
-
src="https://github.com/fixrb/spectus/raw/
|
173
|
+
src="https://github.com/fixrb/spectus/raw/main/img/sashite.png"
|
166
174
|
alt="Sashite" /></a>
|
167
175
|
</p>
|
168
176
|
|
@@ -32,37 +32,22 @@ module Spectus
|
|
32
32
|
|
33
33
|
# The result of the expectation.
|
34
34
|
#
|
35
|
-
# @
|
35
|
+
# @raise [Result::Fail] The expectation is `false`.
|
36
|
+
# @return [Result::Pass] The expectation is `true`.
|
36
37
|
def call
|
37
|
-
pass
|
38
|
+
Result.call(pass?,
|
39
|
+
actual: exam.actual,
|
40
|
+
error: exam.exception,
|
41
|
+
expected: matcher.expected,
|
42
|
+
got: exam.got,
|
43
|
+
negate: negate?,
|
44
|
+
valid: exam.valid?,
|
45
|
+
matcher: matcher.class.to_sym,
|
46
|
+
level: level)
|
38
47
|
end
|
39
48
|
|
40
49
|
protected
|
41
50
|
|
42
|
-
# @return [Result::Pass] A passed spec result.
|
43
|
-
def pass!
|
44
|
-
Result::Pass.new(**details)
|
45
|
-
end
|
46
|
-
|
47
|
-
# @raise [Result::Fail] A failed spec result.
|
48
|
-
def fail!
|
49
|
-
raise Result::Fail.new(**details)
|
50
|
-
end
|
51
|
-
|
52
|
-
# @return [Hash] List of parameters.
|
53
|
-
def details
|
54
|
-
{
|
55
|
-
actual: exam.actual,
|
56
|
-
error: exam.exception,
|
57
|
-
expected: matcher.expected,
|
58
|
-
got: exam.got,
|
59
|
-
negate: negate?,
|
60
|
-
valid: exam.valid?,
|
61
|
-
matcher: matcher.class.to_sym,
|
62
|
-
level: level
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
51
|
# @return [Symbol] The requirement level.
|
67
52
|
def level
|
68
53
|
self.class.name.split("::").fetch(-1).upcase.to_sym
|
@@ -79,6 +64,5 @@ module Spectus
|
|
79
64
|
end
|
80
65
|
end
|
81
66
|
|
67
|
+
require_relative File.join("..", "result")
|
82
68
|
require_relative File.join("..", "exam")
|
83
|
-
require_relative File.join("..", "result", "fail")
|
84
|
-
require_relative File.join("..", "result", "pass")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spectus
|
4
|
+
# Namespace for the results.
|
5
|
+
module Result
|
6
|
+
# @raise [Fail] A failed spec result.
|
7
|
+
# @return [Pass] A passed spec result.
|
8
|
+
def self.call(is_passed, **details)
|
9
|
+
(is_passed ? Pass : Fail).call(**details)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative File.join("result", "fail")
|
15
|
+
require_relative File.join("result", "pass")
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Spectus
|
4
|
-
# Namespace for the results.
|
5
4
|
module Result
|
6
5
|
# Common collection of methods for Result's classes.
|
7
6
|
module Common
|
@@ -50,6 +49,13 @@ module Spectus
|
|
50
49
|
super(to_s) if failed?
|
51
50
|
end
|
52
51
|
|
52
|
+
# Did the test pass?
|
53
|
+
#
|
54
|
+
# @return [Boolean] The spec passed or failed?
|
55
|
+
def passed?
|
56
|
+
!failed?
|
57
|
+
end
|
58
|
+
|
53
59
|
# The value of the negate instance variable.
|
54
60
|
#
|
55
61
|
# @return [Boolean] Evaluated to a negative assertion?
|
data/lib/spectus/result/fail.rb
CHANGED
@@ -8,6 +8,11 @@ module Spectus
|
|
8
8
|
class Fail < ::StandardError
|
9
9
|
include Common
|
10
10
|
|
11
|
+
# @raise [Fail] A failed spec result.
|
12
|
+
def self.call(**details)
|
13
|
+
raise new(**details)
|
14
|
+
end
|
15
|
+
|
11
16
|
# Did the test fail?
|
12
17
|
#
|
13
18
|
# @return [Boolean] The spec passed or failed?
|
@@ -15,13 +20,6 @@ module Spectus
|
|
15
20
|
true
|
16
21
|
end
|
17
22
|
|
18
|
-
# Did the test pass?
|
19
|
-
#
|
20
|
-
# @return [Boolean] The spec passed or failed?
|
21
|
-
def passed?
|
22
|
-
!failed?
|
23
|
-
end
|
24
|
-
|
25
23
|
# The state of failure.
|
26
24
|
#
|
27
25
|
# @return [Boolean] The test was a failure?
|
data/lib/spectus/result/pass.rb
CHANGED
@@ -8,6 +8,11 @@ module Spectus
|
|
8
8
|
class Pass
|
9
9
|
include Common
|
10
10
|
|
11
|
+
# @return [Pass] A passed spec result.
|
12
|
+
def self.call(**details)
|
13
|
+
new(**details)
|
14
|
+
end
|
15
|
+
|
11
16
|
alias message to_s
|
12
17
|
|
13
18
|
# Did the test fail?
|
@@ -17,13 +22,6 @@ module Spectus
|
|
17
22
|
false
|
18
23
|
end
|
19
24
|
|
20
|
-
# Did the test pass?
|
21
|
-
#
|
22
|
-
# @return [Boolean] The spec passed or failed?
|
23
|
-
def passed?
|
24
|
-
!failed?
|
25
|
-
end
|
26
|
-
|
27
25
|
# The state of failure.
|
28
26
|
#
|
29
27
|
# @return [Boolean] The test was a failure?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/spectus/requirement_level/may.rb
|
180
180
|
- lib/spectus/requirement_level/must.rb
|
181
181
|
- lib/spectus/requirement_level/should.rb
|
182
|
+
- lib/spectus/result.rb
|
182
183
|
- lib/spectus/result/common.rb
|
183
184
|
- lib/spectus/result/fail.rb
|
184
185
|
- lib/spectus/result/pass.rb
|