expresenter 1.0.1 → 1.1.0
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 +68 -3
- data/lib/expresenter.rb +7 -2
- data/lib/expresenter/{base.rb → common.rb} +2 -28
- data/lib/expresenter/fail.rb +36 -5
- data/lib/expresenter/pass.rb +29 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fa35d343813c6913d049086af460babf8a5a84b18c7058853fe956c50a3f143
|
4
|
+
data.tar.gz: cbcd35e730fd41b653b7ea944a3b2d0861229e204919747e60940074964aa97d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4e83fd46dc38ac64bae7ebf4577a0d964d11aa49e4ff88c573e294d943a3c450dc2212678b97d6976f7bc3850936db0df3f946b80da22e0d00615c76d48f97
|
7
|
+
data.tar.gz: 4ad82f7aa266fc139e166821a3b18766c24c50ef5ee92fad16f013d8b4240cfd6ea135e105606dab014ea9afffccb8036b669950d0b8254cf576913aa363dba1
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ Then,
|
|
41
41
|
* for a `true` assertion, a `Expresenter::Pass` instance can be returned;
|
42
42
|
* for a `false` assertion, a `Expresenter::Fail` exception can be raised.
|
43
43
|
|
44
|
-
Both class share a
|
44
|
+
Both class share a same `Common` interface.
|
45
45
|
|
46
46
|
Passed expectations can be classified as:
|
47
47
|
|
@@ -54,10 +54,25 @@ Failed expectations can be classified as:
|
|
54
54
|
* ❌ failure
|
55
55
|
* 💥 error
|
56
56
|
|
57
|
-
|
57
|
+
### Instantiation
|
58
|
+
|
59
|
+
The following parameters are required to instantiate the result:
|
60
|
+
|
61
|
+
* `actual`: Returned value by the challenged subject.
|
62
|
+
* `error`: Any possible raised exception.
|
63
|
+
* `expected`: The expected value.
|
64
|
+
* `got`: The result of the boolean comparison between the actual value and the expected value through the matcher.
|
65
|
+
* `negate`: Evaluated to a negative assertion?
|
66
|
+
* `valid`: Report if the test was `true` or `false`.
|
67
|
+
* `matcher`: The symbol representing a matcher.
|
68
|
+
* `level`: The requirement level (`:MUST`, `:SHOULD` or `:MAY`).
|
69
|
+
|
70
|
+
#### Examples
|
71
|
+
|
72
|
+
A passed expectation:
|
58
73
|
|
59
74
|
```ruby
|
60
|
-
result = Expresenter.call(true).
|
75
|
+
result = Expresenter.call(true).new(actual: "FOO", error: nil, expected: "foo", got: true, negate: true, valid: true, matcher: :eql, level: :MUST)
|
61
76
|
|
62
77
|
result.failed? # => false
|
63
78
|
result.failure? # => false
|
@@ -82,6 +97,56 @@ result.to_s # => "Success: expected \"FOO\" not to eql \"foo\"."
|
|
82
97
|
result.titre # => "Success"
|
83
98
|
```
|
84
99
|
|
100
|
+
A failed expectation:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
result = Expresenter.call(false).new(actual: "foo", error: Exception.new("BOOM"), expected: 42, got: true, negate: true, valid: true, matcher: :eql, level: :MUST)
|
104
|
+
|
105
|
+
actual.failed? # => true
|
106
|
+
actual.failure? # => false
|
107
|
+
actual.info? # => false
|
108
|
+
actual.warning? # => false
|
109
|
+
actual.to_sym # => :error
|
110
|
+
actual.char # => "E"
|
111
|
+
actual.emoji # => "💥"
|
112
|
+
actual.passed? # => false
|
113
|
+
actual.negate? # => true
|
114
|
+
actual.error? # => true
|
115
|
+
actual.success? # => true
|
116
|
+
actual.valid? # => true
|
117
|
+
actual.inspect # => "Expresenter::Fail(actual: \"foo\", error: #<Exception: BOOM>, expected: 42, got: true, matcher: :eql, negate: true, level: :MUST, valid: true)"
|
118
|
+
actual.definition # => "eql 42"
|
119
|
+
actual.maybe_negate # => " not"
|
120
|
+
actual.summary # => "BOOM"
|
121
|
+
actual.colored_char # => "\e[32mE\e[0m"
|
122
|
+
actual.colored_string # => "\e[32mException: BOOM.\e[0m"
|
123
|
+
actual.message # => "Exception: BOOM."
|
124
|
+
actual.to_s # => "Exception: BOOM."
|
125
|
+
actual.titre # => "Exception"
|
126
|
+
```
|
127
|
+
|
128
|
+
### Return or Raise
|
129
|
+
|
130
|
+
To return the results which pass, and to raise the results which fail, the `with` method is available.
|
131
|
+
|
132
|
+
In this example, the result passes, the instance is therefore returned:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
Expresenter.call(true).with(actual: "FOO", error: nil, expected: "foo", got: true, negate: true, valid: true, matcher: :eql, level: :MUST) # => Expresenter::Pass(actual: "FOO", error: nil, expected: "foo", got: true, matcher: :eql, negate: true, level: :MUST, valid: true)
|
136
|
+
```
|
137
|
+
|
138
|
+
In this example, the result fails, so the exception is raised:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
Expresenter.call(false).with(actual: "foo", error: Exception.new("BOOM"), expected: 42, got: true, negate: true, valid: true, matcher: :eql, level: :MUST)
|
142
|
+
```
|
143
|
+
|
144
|
+
> Traceback (most recent call last):
|
145
|
+
> 3: from ./bin/console:7:in `<main>'
|
146
|
+
> 2: from (irb):1
|
147
|
+
> 1: from /Users/cyril/github/fixrb/expresenter/lib/expresenter/fail.rb:12:in `with'
|
148
|
+
> Expresenter::Fail (Exception: BOOM.)
|
149
|
+
|
85
150
|
### More Examples
|
86
151
|
|
87
152
|
A full list of unit tests can be viewed (and executed) here:
|
data/lib/expresenter.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Namespace for the Expresenter library.
|
4
|
+
#
|
5
|
+
# @example A passed expectation result presenter.
|
6
|
+
# Expresenter.call(true).with(actual: "FOO", error: nil, expected: "foo", got: true, negate: true, valid: true, matcher: :eql, level: :MUST)
|
4
7
|
module Expresenter
|
5
|
-
# @
|
6
|
-
# @return [Pass]
|
8
|
+
# @param is_passed [Boolean] The value of an assertion.
|
9
|
+
# @return [Class<Pass>, Class<Fail>] The class of the result.
|
10
|
+
# @example Get the pass class result.
|
11
|
+
# call(true) # => Pass
|
7
12
|
def self.call(is_passed)
|
8
13
|
is_passed ? Pass : Fail
|
9
14
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Expresenter
|
4
|
-
# Common collection of methods
|
5
|
-
module
|
4
|
+
# Common collection of methods.
|
5
|
+
module Common
|
6
6
|
# @return [#object_id] Returned value by the challenged subject.
|
7
7
|
attr_reader :actual
|
8
8
|
|
@@ -22,32 +22,6 @@ module Expresenter
|
|
22
22
|
# @return [:MUST, :SHOULD, :MAY] The requirement level of the expectation.
|
23
23
|
attr_reader :level
|
24
24
|
|
25
|
-
# Common initialize method.
|
26
|
-
#
|
27
|
-
# @param actual [#object_id] Returned value by the challenged subject.
|
28
|
-
# @param error [Exception, nil] Any possible raised exception.
|
29
|
-
# @param expected [#object_id] The expected value.
|
30
|
-
# @param got [Boolean, nil] The result of the boolean comparison
|
31
|
-
# between the actual value and the expected value through the matcher.
|
32
|
-
# @param negate [Boolean] Evaluated to a negative assertion?
|
33
|
-
# @param valid [Boolean] Report if the test was true or false?
|
34
|
-
# @param matcher [Symbol] The matcher.
|
35
|
-
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
36
|
-
def initialize(actual:, error:, expected:, got:, negate:, valid:,
|
37
|
-
matcher:, level:)
|
38
|
-
|
39
|
-
@actual = actual
|
40
|
-
@error = error
|
41
|
-
@expected = expected
|
42
|
-
@got = got
|
43
|
-
@negate = negate
|
44
|
-
@valid = valid
|
45
|
-
@matcher = matcher
|
46
|
-
@level = level
|
47
|
-
|
48
|
-
super(to_s) if failed?
|
49
|
-
end
|
50
|
-
|
51
25
|
# Did the test pass?
|
52
26
|
#
|
53
27
|
# @return [Boolean] The spec passed or failed?
|
data/lib/expresenter/fail.rb
CHANGED
@@ -1,17 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "common"
|
4
4
|
|
5
5
|
module Expresenter
|
6
|
-
# The class that is responsible for reporting that
|
6
|
+
# The class that is responsible for reporting that an expectation is false.
|
7
7
|
class Fail < ::StandardError
|
8
|
-
include
|
8
|
+
include Common
|
9
9
|
|
10
|
-
# @
|
10
|
+
# @param (see Fail#initialize)
|
11
|
+
# @raise [Fail] A failed spec exception.
|
11
12
|
def self.with(**details)
|
12
13
|
raise new(**details)
|
13
14
|
end
|
14
15
|
|
16
|
+
# Initialize method.
|
17
|
+
#
|
18
|
+
# @param actual [#object_id] Returned value by the challenged subject.
|
19
|
+
# @param error [Exception, nil] Any possible raised exception.
|
20
|
+
# @param expected [#object_id] The expected value.
|
21
|
+
# @param got [Boolean, nil] The result of the boolean comparison
|
22
|
+
# between the actual value and the expected value through the matcher.
|
23
|
+
# @param negate [Boolean] Evaluated to a negative assertion?
|
24
|
+
# @param valid [Boolean] Report if the test was true or false?
|
25
|
+
# @param matcher [Symbol] The matcher.
|
26
|
+
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
27
|
+
def initialize(actual:, error:, expected:, got:, negate:, valid:,
|
28
|
+
matcher:, level:)
|
29
|
+
|
30
|
+
@actual = actual
|
31
|
+
@error = error
|
32
|
+
@expected = expected
|
33
|
+
@got = got
|
34
|
+
@negate = negate
|
35
|
+
@valid = valid
|
36
|
+
@matcher = matcher
|
37
|
+
@level = level
|
38
|
+
|
39
|
+
super(to_s)
|
40
|
+
end
|
41
|
+
|
15
42
|
# Did the test fail?
|
16
43
|
#
|
17
44
|
# @return [Boolean] The spec passed or failed?
|
@@ -44,7 +71,11 @@ module Expresenter
|
|
44
71
|
#
|
45
72
|
# @return [Symbol] The identifier of the state.
|
46
73
|
def to_sym
|
47
|
-
failure?
|
74
|
+
if failure?
|
75
|
+
:failure
|
76
|
+
else
|
77
|
+
:error
|
78
|
+
end
|
48
79
|
end
|
49
80
|
|
50
81
|
# Express the result with one char.
|
data/lib/expresenter/pass.rb
CHANGED
@@ -1,19 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "common"
|
4
4
|
|
5
5
|
module Expresenter
|
6
|
-
# The class that is responsible for reporting that
|
6
|
+
# The class that is responsible for reporting that an expectation is true.
|
7
7
|
class Pass
|
8
|
-
include
|
8
|
+
include Common
|
9
9
|
|
10
|
-
# @
|
10
|
+
# @param (see Pass#initialize)
|
11
|
+
# @return [Pass] A passed spec instance.
|
11
12
|
def self.with(**details)
|
12
13
|
new(**details)
|
13
14
|
end
|
14
15
|
|
15
16
|
alias message to_s
|
16
17
|
|
18
|
+
# Initialize method.
|
19
|
+
#
|
20
|
+
# @param actual [#object_id] Returned value by the challenged subject.
|
21
|
+
# @param error [Exception, nil] Any possible raised exception.
|
22
|
+
# @param expected [#object_id] The expected value.
|
23
|
+
# @param got [Boolean, nil] The result of the boolean comparison
|
24
|
+
# between the actual value and the expected value through the matcher.
|
25
|
+
# @param negate [Boolean] Evaluated to a negative assertion?
|
26
|
+
# @param valid [Boolean] Report if the test was true or false?
|
27
|
+
# @param matcher [Symbol] The matcher.
|
28
|
+
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
29
|
+
def initialize(actual:, error:, expected:, got:, negate:, valid:,
|
30
|
+
matcher:, level:)
|
31
|
+
|
32
|
+
@actual = actual
|
33
|
+
@error = error
|
34
|
+
@expected = expected
|
35
|
+
@got = got
|
36
|
+
@negate = negate
|
37
|
+
@valid = valid
|
38
|
+
@matcher = matcher
|
39
|
+
@level = level
|
40
|
+
end
|
41
|
+
|
17
42
|
# Did the test fail?
|
18
43
|
#
|
19
44
|
# @return [Boolean] The spec passed or failed?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expresenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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-05-
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brutal
|
@@ -145,7 +145,7 @@ files:
|
|
145
145
|
- LICENSE.md
|
146
146
|
- README.md
|
147
147
|
- lib/expresenter.rb
|
148
|
-
- lib/expresenter/
|
148
|
+
- lib/expresenter/common.rb
|
149
149
|
- lib/expresenter/fail.rb
|
150
150
|
- lib/expresenter/pass.rb
|
151
151
|
homepage: https://github.com/fixrb/expresenter
|