expresenter 1.0.0 → 1.3.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 +124 -33
- data/lib/expresenter.rb +9 -2
- data/lib/expresenter/{base.rb → common.rb} +23 -62
- data/lib/expresenter/fail.rb +58 -9
- data/lib/expresenter/pass.rb +68 -14
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b293c0c6ffd15b336c00fcc841647e6d244623346dd86ab6cf319c05cfc7d909
|
4
|
+
data.tar.gz: 3901ec01f1277302150665002b97c157ba26846bf08e344bd364fbb7fdec874d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db88b4f5c706ae1aaf48fdf6b2b45aa0ab4d0fe1f5a557331e51b8b9c9333f07305ec1f6d5f3287a34ed39e20396fd2d4879f5b186e94e9653420604a1d2ca3d
|
7
|
+
data.tar.gz: 04c1db7b8ea904a67397305f111bde2e4dadac40c6cdd392cb855b3b4db24a8ae904c92cfe07332cdc137cceea57481d9d920803941722b3e8749db16d0b346b
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Expresenter
|
2
2
|
|
3
3
|
[][travis]
|
4
|
-
[][codeclimate]
|
5
4
|
[][gem]
|
6
5
|
[][inchpages]
|
7
6
|
[][rubydoc]
|
@@ -18,58 +17,151 @@ gem "expresenter"
|
|
18
17
|
|
19
18
|
And then execute:
|
20
19
|
|
21
|
-
|
20
|
+
```sh
|
21
|
+
bundle
|
22
|
+
```
|
22
23
|
|
23
24
|
Or install it yourself as:
|
24
25
|
|
25
|
-
|
26
|
+
```sh
|
27
|
+
gem install expresenter
|
28
|
+
```
|
26
29
|
|
27
30
|
## Usage
|
28
31
|
|
32
|
+
Assuming that an expectation is an assertion that is either `true` or `false`,
|
33
|
+
qualifying it with `MUST`, `SHOULD` and `MAY`, we can draw up several scenarios:
|
34
|
+
|
35
|
+
| Requirement levels | **MUST** | **SHOULD** | **MAY** |
|
36
|
+
| ------------------------- | -------- | ---------- | ------- |
|
37
|
+
| Implemented & Matched | `true` | `true` | `true` |
|
38
|
+
| Implemented & Not matched | `false` | `true` | `false` |
|
39
|
+
| Implemented & Exception | `false` | `false` | `false` |
|
40
|
+
| Not implemented | `false` | `false` | `true` |
|
41
|
+
|
42
|
+
Then,
|
43
|
+
|
44
|
+
* for a `true` assertion, a `Expresenter::Pass` instance can be returned;
|
45
|
+
* for a `false` assertion, a `Expresenter::Fail` exception can be raised.
|
46
|
+
|
47
|
+
Both class share a same `Common` interface.
|
48
|
+
|
49
|
+
Passed expectations can be classified as:
|
50
|
+
|
51
|
+
* ✅ success
|
52
|
+
* ⚠️ warning
|
53
|
+
* 💡 info
|
54
|
+
|
55
|
+
Failed expectations can be classified as:
|
56
|
+
|
57
|
+
* ❌ failure
|
58
|
+
* 💥 error
|
59
|
+
|
60
|
+
### Instantiation
|
61
|
+
|
62
|
+
The following parameters are required to instantiate the result:
|
63
|
+
|
64
|
+
* `actual`: Returned value by the challenged subject.
|
65
|
+
* `error`: Any possible raised exception.
|
66
|
+
* `expected`: The expected value.
|
67
|
+
* `got`: The result of the boolean comparison between the actual value and the expected value through the matcher.
|
68
|
+
* `negate`: Evaluated to a negative assertion?
|
69
|
+
* `matcher`: The symbol representing a matcher.
|
70
|
+
* `level`: The requirement level (`:MUST`, `:SHOULD` or `:MAY`).
|
71
|
+
|
72
|
+
#### Examples
|
73
|
+
|
74
|
+
A passed expectation:
|
75
|
+
|
29
76
|
```ruby
|
30
|
-
result = Expresenter.call(true
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
actual.colored_char # => "\e[32m.\e[0m"
|
49
|
-
actual.colored_string # => "\e[32mSuccess: expected \"FOO\" not to eql \"foo\".\e[0m"
|
77
|
+
result = Expresenter.call(true).new(actual: "FOO", error: nil, expected: "foo", got: true, negate: true, matcher: :eql, level: :MUST)
|
78
|
+
|
79
|
+
result.failed? # => false
|
80
|
+
result.failure? # => false
|
81
|
+
result.info? # => false
|
82
|
+
result.warning? # => false
|
83
|
+
result.to_sym # => :success
|
84
|
+
result.char # => "."
|
85
|
+
result.emoji # => "✅"
|
86
|
+
result.passed? # => true
|
87
|
+
result.negate? # => true
|
88
|
+
result.error? # => false
|
89
|
+
result.success? # => true
|
90
|
+
result.inspect # => "Expresenter::Pass(actual: \"FOO\", error: nil, expected: \"foo\", got: true, matcher: :eql, negate: true, level: :MUST)"
|
91
|
+
result.definition # => "eql \"foo\""
|
92
|
+
result.summary # => "expected \"FOO\" not to eql \"foo\""
|
93
|
+
result.colored_char # => "\e[32m.\e[0m"
|
94
|
+
result.colored_string # => "\e[32m\e[1mSuccess\e[22m: expected \"FOO\" not to eql \"foo\".\e[0m"
|
50
95
|
result.message # => "Success: expected \"FOO\" not to eql \"foo\"."
|
51
|
-
|
52
|
-
|
96
|
+
result.to_s # => "Success: expected \"FOO\" not to eql \"foo\"."
|
97
|
+
result.titre # => "Success"
|
53
98
|
```
|
54
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, matcher: :eql, level: :MUST)
|
104
|
+
|
105
|
+
result.failed? # => true
|
106
|
+
result.failure? # => false
|
107
|
+
result.info? # => false
|
108
|
+
result.warning? # => false
|
109
|
+
result.to_sym # => :error
|
110
|
+
result.char # => "E"
|
111
|
+
result.emoji # => "💥"
|
112
|
+
result.passed? # => false
|
113
|
+
result.negate? # => true
|
114
|
+
result.error? # => true
|
115
|
+
result.success? # => true
|
116
|
+
result.inspect # => "Expresenter::Fail(actual: \"foo\", error: #<Exception: BOOM>, expected: 42, got: true, matcher: :eql, negate: true, level: :MUST)"
|
117
|
+
result.definition # => "eql 42"
|
118
|
+
result.summary # => "BOOM"
|
119
|
+
result.colored_char # => "\e[31mE\e[0m"
|
120
|
+
result.colored_string # => "\e[31m\e[1mException\e[22m: BOOM.\e[0m"
|
121
|
+
result.message # => "Exception: BOOM."
|
122
|
+
result.to_s # => "Exception: BOOM."
|
123
|
+
result.titre # => "Exception"
|
124
|
+
```
|
125
|
+
|
126
|
+
### Return or Raise
|
127
|
+
|
128
|
+
To return the results which pass, and to raise the results which fail, the `with` method is available.
|
129
|
+
|
130
|
+
In this example, the result passes, the instance is therefore returned:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
Expresenter.call(true).with(actual: "FOO", error: nil, expected: "foo", got: true, negate: true, matcher: :eql, level: :MUST) # => Expresenter::Pass(actual: "FOO", error: nil, expected: "foo", got: true, matcher: :eql, negate: true, level: :MUST)
|
134
|
+
```
|
135
|
+
|
136
|
+
In this example, the result fails, so the exception is raised:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
Expresenter.call(false).with(actual: "foo", error: Exception.new("BOOM"), expected: 42, got: true, negate: true, matcher: :eql, level: :MUST)
|
140
|
+
```
|
141
|
+
|
142
|
+
> Traceback (most recent call last):
|
143
|
+
> 3: from ./bin/console:7:in `<main>'
|
144
|
+
> 2: from (irb):1
|
145
|
+
> 1: from /Users/cyril/github/fixrb/expresenter/lib/expresenter/fail.rb:19:in `with'
|
146
|
+
> Expresenter::Fail (Exception: BOOM.)
|
147
|
+
|
148
|
+
### More Examples
|
149
|
+
|
150
|
+
A full list of unit tests can be viewed (and executed) here:
|
151
|
+
[./test.rb](https://github.com/fixrb/expresenter/blob/main/test.rb)
|
152
|
+
|
55
153
|
## Contact
|
56
154
|
|
57
155
|
* Home page: https://github.com/fixrb/expresenter
|
58
156
|
* Bugs/issues: https://github.com/fixrb/expresenter/issues
|
59
157
|
|
60
|
-
## Rubies
|
61
|
-
|
62
|
-
* [MRI](https://www.ruby-lang.org/)
|
63
|
-
* [Rubinius](https://rubinius.com/)
|
64
|
-
* [JRuby](https://www.jruby.org/)
|
65
|
-
|
66
158
|
## Versioning
|
67
159
|
|
68
160
|
__Expresenter__ follows [Semantic Versioning 2.0](https://semver.org/).
|
69
161
|
|
70
162
|
## License
|
71
163
|
|
72
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
164
|
+
The [gem](https://rubygems.org/gems/expresenter) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
73
165
|
|
74
166
|
***
|
75
167
|
|
@@ -82,6 +174,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
82
174
|
|
83
175
|
[gem]: https://rubygems.org/gems/expresenter
|
84
176
|
[travis]: https://travis-ci.org/fixrb/expresenter
|
85
|
-
[codeclimate]: https://codeclimate.com/github/fixrb/expresenter
|
86
177
|
[inchpages]: https://inch-ci.org/github/fixrb/expresenter
|
87
178
|
[rubydoc]: https://rubydoc.info/gems/expresenter/frames
|
data/lib/expresenter.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
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, matcher: :eql, level: :MUST) # => Expresenter::Pass(actual: "FOO", error: nil, expected: "foo", got: true, matcher: :eql, negate: true, level: :MUST)
|
4
7
|
module Expresenter
|
5
|
-
# @
|
6
|
-
#
|
8
|
+
# @param is_passed [Boolean] The value of an assertion.
|
9
|
+
#
|
10
|
+
# @return [Class<Pass>, Class<Fail>] The class of the result.
|
11
|
+
#
|
12
|
+
# @example Get the pass class result.
|
13
|
+
# call(true) # => Pass
|
7
14
|
def self.call(is_passed)
|
8
15
|
is_passed ? Pass : Fail
|
9
16
|
end
|
@@ -1,8 +1,11 @@
|
|
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
|
+
# White space.
|
7
|
+
SPACE = " "
|
8
|
+
|
6
9
|
# @return [#object_id] Returned value by the challenged subject.
|
7
10
|
attr_reader :actual
|
8
11
|
|
@@ -16,38 +19,12 @@ module Expresenter
|
|
16
19
|
# actual value and the expected value through the matcher.
|
17
20
|
attr_reader :got
|
18
21
|
|
19
|
-
# @return [
|
22
|
+
# @return [Symbol] The matcher.
|
20
23
|
attr_reader :matcher
|
21
24
|
|
22
25
|
# @return [:MUST, :SHOULD, :MAY] The requirement level of the expectation.
|
23
26
|
attr_reader :level
|
24
27
|
|
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
28
|
# Did the test pass?
|
52
29
|
#
|
53
30
|
# @return [Boolean] The spec passed or failed?
|
@@ -76,14 +53,6 @@ module Expresenter
|
|
76
53
|
got.equal?(true)
|
77
54
|
end
|
78
55
|
|
79
|
-
# The value of the boolean comparison between the actual value and the
|
80
|
-
# expected value.
|
81
|
-
#
|
82
|
-
# @return [Boolean] The test was true or false?
|
83
|
-
def valid?
|
84
|
-
@valid
|
85
|
-
end
|
86
|
-
|
87
56
|
# A string containing a human-readable representation of the result.
|
88
57
|
#
|
89
58
|
# @return [String] The human-readable representation of the result.
|
@@ -94,22 +63,14 @@ module Expresenter
|
|
94
63
|
"got: #{got.inspect}, " \
|
95
64
|
"matcher: #{matcher.inspect}, " \
|
96
65
|
"negate: #{negate?.inspect}, " \
|
97
|
-
"level: #{level.inspect}
|
98
|
-
"valid: #{valid?.inspect})" \
|
66
|
+
"level: #{level.inspect}" \
|
99
67
|
end
|
100
68
|
|
101
69
|
# The readable definition.
|
102
70
|
#
|
103
71
|
# @return [String] A readable string of the definition.
|
104
72
|
def definition
|
105
|
-
[matcher, expected&.inspect].compact.join(
|
106
|
-
end
|
107
|
-
|
108
|
-
# The negation, if any.
|
109
|
-
#
|
110
|
-
# @return [String] The negation, or an empty string.
|
111
|
-
def maybe_negate
|
112
|
-
negate? ? " not" : ""
|
73
|
+
[matcher.to_s.tr("_", " "), expected&.inspect].compact.join(SPACE)
|
113
74
|
end
|
114
75
|
|
115
76
|
# The summary of the result.
|
@@ -121,9 +82,9 @@ module Expresenter
|
|
121
82
|
elsif actual.is_a?(::Exception)
|
122
83
|
actual.message
|
123
84
|
elsif actual == expected
|
124
|
-
"expected
|
85
|
+
["expected", negation, "to", definition].compact.join(SPACE)
|
125
86
|
else
|
126
|
-
"expected
|
87
|
+
["expected", actual.inspect, negation, "to", definition].compact.join(SPACE)
|
127
88
|
end
|
128
89
|
end
|
129
90
|
|
@@ -138,7 +99,7 @@ module Expresenter
|
|
138
99
|
#
|
139
100
|
# @return [String] A string representing the result.
|
140
101
|
def colored_string
|
141
|
-
color(
|
102
|
+
color(to_bold_s)
|
142
103
|
end
|
143
104
|
|
144
105
|
# The representation of the result.
|
@@ -161,18 +122,18 @@ module Expresenter
|
|
161
122
|
|
162
123
|
protected
|
163
124
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
125
|
+
# The negation, if any.
|
126
|
+
#
|
127
|
+
# @return [String, nil] The negation, or an empty string.
|
128
|
+
def negation
|
129
|
+
"not" if negate?
|
130
|
+
end
|
131
|
+
|
132
|
+
# The representation of the result with the title in bold.
|
133
|
+
#
|
134
|
+
# @return [String] A string representing the result with the title in bold.
|
135
|
+
def to_bold_s
|
136
|
+
"\e[1m#{titre}\e[22m: #{summary}."
|
176
137
|
end
|
177
138
|
end
|
178
139
|
end
|
data/lib/expresenter/fail.rb
CHANGED
@@ -1,17 +1,52 @@
|
|
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
|
-
|
8
|
+
# Char representing a failure.
|
9
|
+
FAILURE_CHAR = "F"
|
9
10
|
|
10
|
-
#
|
11
|
+
# Emoji representing a failure.
|
12
|
+
FAILURE_EMOJI = "❌"
|
13
|
+
|
14
|
+
# Char representing an error.
|
15
|
+
ERROR_CHAR = "E"
|
16
|
+
|
17
|
+
# Emoji representing an error.
|
18
|
+
ERROR_EMOJI = "💥"
|
19
|
+
|
20
|
+
include Common
|
21
|
+
|
22
|
+
# @param (see Fail#initialize)
|
23
|
+
# @raise [Fail] A failed spec exception.
|
11
24
|
def self.with(**details)
|
12
25
|
raise new(**details)
|
13
26
|
end
|
14
27
|
|
28
|
+
# Initialize method.
|
29
|
+
#
|
30
|
+
# @param actual [#object_id] Returned value by the challenged subject.
|
31
|
+
# @param error [Exception, nil] Any possible raised exception.
|
32
|
+
# @param expected [#object_id] The expected value.
|
33
|
+
# @param got [Boolean, nil] The result of the boolean comparison
|
34
|
+
# between the actual value and the expected value through the matcher.
|
35
|
+
# @param negate [Boolean] Evaluated to a negative assertion?
|
36
|
+
# @param matcher [Symbol] The matcher.
|
37
|
+
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
38
|
+
def initialize(actual:, error:, expected:, got:, negate:, matcher:, level:)
|
39
|
+
@actual = actual
|
40
|
+
@error = error
|
41
|
+
@expected = expected
|
42
|
+
@got = got
|
43
|
+
@negate = negate
|
44
|
+
@matcher = matcher
|
45
|
+
@level = level
|
46
|
+
|
47
|
+
super(to_s)
|
48
|
+
end
|
49
|
+
|
15
50
|
# Did the test fail?
|
16
51
|
#
|
17
52
|
# @return [Boolean] The spec passed or failed?
|
@@ -44,7 +79,11 @@ module Expresenter
|
|
44
79
|
#
|
45
80
|
# @return [Symbol] The identifier of the state.
|
46
81
|
def to_sym
|
47
|
-
failure?
|
82
|
+
if failure?
|
83
|
+
:failure
|
84
|
+
else
|
85
|
+
:error
|
86
|
+
end
|
48
87
|
end
|
49
88
|
|
50
89
|
# Express the result with one char.
|
@@ -52,9 +91,9 @@ module Expresenter
|
|
52
91
|
# @return [String] The char that identify the result.
|
53
92
|
def char
|
54
93
|
if failure?
|
55
|
-
|
94
|
+
FAILURE_CHAR
|
56
95
|
else
|
57
|
-
|
96
|
+
ERROR_CHAR
|
58
97
|
end
|
59
98
|
end
|
60
99
|
|
@@ -63,9 +102,19 @@ module Expresenter
|
|
63
102
|
# @return [String] The emoji that identify the result.
|
64
103
|
def emoji
|
65
104
|
if failure?
|
66
|
-
|
105
|
+
FAILURE_EMOJI
|
106
|
+
else
|
107
|
+
ERROR_EMOJI
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
protected
|
112
|
+
|
113
|
+
def color(str)
|
114
|
+
if failure?
|
115
|
+
"\e[35m#{str}\e[0m" # purple
|
67
116
|
else
|
68
|
-
"
|
117
|
+
"\e[31m#{str}\e[0m" # red
|
69
118
|
end
|
70
119
|
end
|
71
120
|
end
|
data/lib/expresenter/pass.rb
CHANGED
@@ -1,19 +1,58 @@
|
|
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
|
-
|
8
|
+
# Char representing an info.
|
9
|
+
INFO_CHAR = "I"
|
9
10
|
|
10
|
-
#
|
11
|
+
# Emoji representing an info.
|
12
|
+
INFO_EMOJI = "💡"
|
13
|
+
|
14
|
+
# Char representing a success.
|
15
|
+
SUCCESS_CHAR = "."
|
16
|
+
|
17
|
+
# Emoji representing a success.
|
18
|
+
SUCCESS_EMOJI = "✅"
|
19
|
+
|
20
|
+
# Char representing a warning.
|
21
|
+
WARNING_CHAR = "W"
|
22
|
+
|
23
|
+
# Emoji representing a warning.
|
24
|
+
WARNING_EMOJI = "⚠️"
|
25
|
+
|
26
|
+
include Common
|
27
|
+
|
28
|
+
# @param (see Pass#initialize)
|
29
|
+
# @return [Pass] A passed spec instance.
|
11
30
|
def self.with(**details)
|
12
31
|
new(**details)
|
13
32
|
end
|
14
33
|
|
15
34
|
alias message to_s
|
16
35
|
|
36
|
+
# Initialize method.
|
37
|
+
#
|
38
|
+
# @param actual [#object_id] Returned value by the challenged subject.
|
39
|
+
# @param error [Exception, nil] Any possible raised exception.
|
40
|
+
# @param expected [#object_id] The expected value.
|
41
|
+
# @param got [Boolean, nil] The result of the boolean comparison
|
42
|
+
# between the actual value and the expected value through the matcher.
|
43
|
+
# @param negate [Boolean] Evaluated to a negative assertion?
|
44
|
+
# @param matcher [Symbol] The matcher.
|
45
|
+
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
46
|
+
def initialize(actual:, error:, expected:, got:, negate:, matcher:, level:)
|
47
|
+
@actual = actual
|
48
|
+
@error = error
|
49
|
+
@expected = expected
|
50
|
+
@got = got
|
51
|
+
@negate = negate
|
52
|
+
@matcher = matcher
|
53
|
+
@level = level
|
54
|
+
end
|
55
|
+
|
17
56
|
# Did the test fail?
|
18
57
|
#
|
19
58
|
# @return [Boolean] The spec passed or failed?
|
@@ -46,10 +85,13 @@ module Expresenter
|
|
46
85
|
#
|
47
86
|
# @return [Symbol] The identifier of the state.
|
48
87
|
def to_sym
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
88
|
+
if success?
|
89
|
+
:success
|
90
|
+
elsif warning?
|
91
|
+
:warning
|
92
|
+
else
|
93
|
+
:info
|
94
|
+
end
|
53
95
|
end
|
54
96
|
|
55
97
|
# Express the result with one char.
|
@@ -57,11 +99,11 @@ module Expresenter
|
|
57
99
|
# @return [String] The char that identify the result.
|
58
100
|
def char
|
59
101
|
if success?
|
60
|
-
|
102
|
+
SUCCESS_CHAR
|
61
103
|
elsif warning?
|
62
|
-
|
104
|
+
WARNING_CHAR
|
63
105
|
else
|
64
|
-
|
106
|
+
INFO_CHAR
|
65
107
|
end
|
66
108
|
end
|
67
109
|
|
@@ -70,11 +112,23 @@ module Expresenter
|
|
70
112
|
# @return [String] The emoji that identify the result.
|
71
113
|
def emoji
|
72
114
|
if success?
|
73
|
-
|
115
|
+
SUCCESS_EMOJI
|
116
|
+
elsif warning?
|
117
|
+
WARNING_EMOJI
|
118
|
+
else
|
119
|
+
INFO_EMOJI
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
protected
|
124
|
+
|
125
|
+
def color(str)
|
126
|
+
if success?
|
127
|
+
"\e[32m#{str}\e[0m" # green
|
74
128
|
elsif warning?
|
75
|
-
"
|
129
|
+
"\e[33m#{str}\e[0m" # yellow
|
76
130
|
else
|
77
|
-
"
|
131
|
+
"\e[36m#{str}\e[0m" # blue
|
78
132
|
end
|
79
133
|
end
|
80
134
|
end
|
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.
|
4
|
+
version: 1.3.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-
|
11
|
+
date: 2021-06-19 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
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
rubygems_version: 3.1.
|
170
|
+
rubygems_version: 3.1.6
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: Expectation result presenter.
|