expresenter 1.3.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +25 -28
- data/lib/expresenter/common.rb +10 -17
- data/lib/expresenter/fail.rb +16 -15
- data/lib/expresenter/pass.rb +10 -9
- data/lib/expresenter.rb +1 -1
- metadata +7 -132
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eb634d0a1d539bbedb8a223d115a4b7ce567d376e67483c98a7a63816799730
|
4
|
+
data.tar.gz: 6251c7601028185b98b6748c2daca4666b8bcd350c62aa1066534e82d8282f8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8c26a86adfdee7cbc76b9308e541a0d5b97c7b6ed1b6eb5836065d587df7f820715f0fadf6c865c36176f4cf6c3ed29d557aa4b2cd30e2367a7d839395a80e1
|
7
|
+
data.tar.gz: 23d22691711a01ff958fa85276929f5a4c4132859eb44a28fc72577973d40a3535646492760494c6c9562a184599bbff0e36219fdceedae84ff3e315a767e3f0
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# Expresenter
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
3
|
+
[![Version](https://img.shields.io/github/v/tag/fixrb/expresenter?label=Version&logo=github)](https://github.com/fixrb/expresenter/tags)
|
4
|
+
[![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/expresenter/main)
|
5
|
+
[![Ruby](https://github.com/fixrb/expresenter/workflows/Ruby/badge.svg?branch=main)](https://github.com/fixrb/expresenter/actions?query=workflow%3Aruby+branch%3Amain)
|
6
|
+
[![RuboCop](https://github.com/fixrb/expresenter/workflows/RuboCop/badge.svg?branch=main)](https://github.com/fixrb/expresenter/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
|
+
[![License](https://img.shields.io/github/license/fixrb/expresenter?label=License&logo=github)](https://github.com/fixrb/expresenter/raw/main/LICENSE.md)
|
7
8
|
|
8
9
|
> Expectation result presenter.
|
9
10
|
|
@@ -18,7 +19,7 @@ gem "expresenter"
|
|
18
19
|
And then execute:
|
19
20
|
|
20
21
|
```sh
|
21
|
-
bundle
|
22
|
+
bundle install
|
22
23
|
```
|
23
24
|
|
24
25
|
Or install it yourself as:
|
@@ -62,11 +63,11 @@ Failed expectations can be classified as:
|
|
62
63
|
The following parameters are required to instantiate the result:
|
63
64
|
|
64
65
|
* `actual`: Returned value by the challenged subject.
|
66
|
+
* `definition`: A readable string of the matcher and any expected values.
|
65
67
|
* `error`: Any possible raised exception.
|
66
68
|
* `expected`: The expected value.
|
67
69
|
* `got`: The result of the boolean comparison between the actual value and the expected value through the matcher.
|
68
70
|
* `negate`: Evaluated to a negative assertion?
|
69
|
-
* `matcher`: The symbol representing a matcher.
|
70
71
|
* `level`: The requirement level (`:MUST`, `:SHOULD` or `:MAY`).
|
71
72
|
|
72
73
|
#### Examples
|
@@ -74,7 +75,7 @@ The following parameters are required to instantiate the result:
|
|
74
75
|
A passed expectation:
|
75
76
|
|
76
77
|
```ruby
|
77
|
-
result = Expresenter.call(true).new(actual: "FOO", error: nil, expected: "foo", got: true, negate: true,
|
78
|
+
result = Expresenter.call(true).new(actual: "FOO", definition: 'eq "foo"', error: nil, expected: "foo", got: true, negate: true, level: :MUST)
|
78
79
|
|
79
80
|
result.failed? # => false
|
80
81
|
result.failure? # => false
|
@@ -87,20 +88,20 @@ result.passed? # => true
|
|
87
88
|
result.negate? # => true
|
88
89
|
result.error? # => false
|
89
90
|
result.success? # => true
|
90
|
-
result.inspect # => "Expresenter::Pass(actual: \"FOO\", error: nil, expected: \"foo\", got: true,
|
91
|
-
result.definition # => "
|
92
|
-
result.summary # => "expected \"FOO\" not to
|
91
|
+
result.inspect # => "Expresenter::Pass(actual: \"FOO\", definition: \"eq \\\"foo\\\"\", error: nil, expected: \"foo\", got: true, negate: true, level: :MUST)"
|
92
|
+
result.definition # => "eq \"foo\""
|
93
|
+
result.summary # => "expected \"FOO\" not to eq \"foo\""
|
93
94
|
result.colored_char # => "\e[32m.\e[0m"
|
94
|
-
result.colored_string # => "\e[32m\e[1mSuccess\e[22m: expected \"FOO\" not to
|
95
|
-
result.message # => "Success: expected \"FOO\" not to
|
96
|
-
result.to_s # => "Success: expected \"FOO\" not to
|
95
|
+
result.colored_string # => "\e[32m\e[1mSuccess\e[22m: expected \"FOO\" not to eq \"foo\".\e[0m"
|
96
|
+
result.message # => "Success: expected \"FOO\" not to eq \"foo\"."
|
97
|
+
result.to_s # => "Success: expected \"FOO\" not to eq \"foo\"."
|
97
98
|
result.titre # => "Success"
|
98
99
|
```
|
99
100
|
|
100
101
|
A failed expectation:
|
101
102
|
|
102
103
|
```ruby
|
103
|
-
result = Expresenter.call(false).new(actual: "foo", error: Exception.new("BOOM"), expected: 42, got: true, negate: true,
|
104
|
+
result = Expresenter.call(false).new(actual: "foo", definition: "eq 42", error: Exception.new("BOOM"), expected: 42, got: true, negate: true, level: :MUST)
|
104
105
|
|
105
106
|
result.failed? # => true
|
106
107
|
result.failure? # => false
|
@@ -113,8 +114,8 @@ result.passed? # => false
|
|
113
114
|
result.negate? # => true
|
114
115
|
result.error? # => true
|
115
116
|
result.success? # => true
|
116
|
-
result.inspect # => "Expresenter::Fail(actual: \"foo\", error: #<Exception: BOOM>, expected: 42, got: true,
|
117
|
-
result.definition # => "
|
117
|
+
result.inspect # => "Expresenter::Fail(actual: \"foo\", definition: \"eq 42\", error: #<Exception: BOOM>, expected: 42, got: true, negate: true, level: :MUST)"
|
118
|
+
result.definition # => "eq 42"
|
118
119
|
result.summary # => "BOOM"
|
119
120
|
result.colored_char # => "\e[31mE\e[0m"
|
120
121
|
result.colored_string # => "\e[31m\e[1mException\e[22m: BOOM.\e[0m"
|
@@ -130,19 +131,20 @@ To return the results which pass, and to raise the results which fail, the `with
|
|
130
131
|
In this example, the result passes, the instance is therefore returned:
|
131
132
|
|
132
133
|
```ruby
|
133
|
-
Expresenter.call(true).with(actual: "FOO", error: nil, expected: "foo", got: true, negate: true,
|
134
|
+
Expresenter.call(true).with(actual: "FOO", definition: 'eq "foo"', error: nil, expected: "foo", got: true, negate: true, level: :MUST) # => Expresenter::Pass(actual: "FOO", definition: "eq \"foo\"", error: nil, expected: "foo", got: true, negate: true, level: :MUST)
|
134
135
|
```
|
135
136
|
|
136
137
|
In this example, the result fails, so the exception is raised:
|
137
138
|
|
138
139
|
```ruby
|
139
|
-
Expresenter.call(false).with(actual: "foo", error: Exception.new("BOOM"), expected: 42, got: true, negate: true,
|
140
|
+
Expresenter.call(false).with(actual: "foo", definition: "eq 40", error: Exception.new("BOOM"), expected: 42, got: true, negate: true, level: :MUST)
|
140
141
|
```
|
141
142
|
|
142
143
|
> Traceback (most recent call last):
|
143
|
-
>
|
144
|
-
>
|
145
|
-
>
|
144
|
+
> 4: from ./bin/console:7:in `<main>'
|
145
|
+
> 3: from (irb):42
|
146
|
+
> 2: from (irb):43:in `rescue in irb_binding'
|
147
|
+
> 1: from /Users/cyril/github/fixrb/expresenter/lib/expresenter/fail.rb:25:in `with'
|
146
148
|
> Expresenter::Fail (Exception: BOOM.)
|
147
149
|
|
148
150
|
### More Examples
|
@@ -161,7 +163,7 @@ __Expresenter__ follows [Semantic Versioning 2.0](https://semver.org/).
|
|
161
163
|
|
162
164
|
## License
|
163
165
|
|
164
|
-
The [gem](https://rubygems.org/gems/expresenter) is available as open source under the terms of the [MIT License](https://
|
166
|
+
The [gem](https://rubygems.org/gems/expresenter) is available as open source under the terms of the [MIT License](https://github.com/fixrb/expresenter/raw/main/LICENSE.md).
|
165
167
|
|
166
168
|
***
|
167
169
|
|
@@ -169,10 +171,5 @@ The [gem](https://rubygems.org/gems/expresenter) is available as open source und
|
|
169
171
|
This project is sponsored by:<br />
|
170
172
|
<a href="https://sashite.com/"><img
|
171
173
|
src="https://github.com/fixrb/expresenter/raw/main/img/sashite.png"
|
172
|
-
alt="
|
174
|
+
alt="Sashité" /></a>
|
173
175
|
</p>
|
174
|
-
|
175
|
-
[gem]: https://rubygems.org/gems/expresenter
|
176
|
-
[travis]: https://travis-ci.org/fixrb/expresenter
|
177
|
-
[inchpages]: https://inch-ci.org/github/fixrb/expresenter
|
178
|
-
[rubydoc]: https://rubydoc.info/gems/expresenter/frames
|
data/lib/expresenter/common.rb
CHANGED
@@ -9,6 +9,9 @@ module Expresenter
|
|
9
9
|
# @return [#object_id] Returned value by the challenged subject.
|
10
10
|
attr_reader :actual
|
11
11
|
|
12
|
+
# @return [String] A readable string of the matcher and any expected values.
|
13
|
+
attr_reader :definition
|
14
|
+
|
12
15
|
# @return [Exception, nil] Any possible raised exception.
|
13
16
|
attr_reader :error
|
14
17
|
|
@@ -19,9 +22,6 @@ module Expresenter
|
|
19
22
|
# actual value and the expected value through the matcher.
|
20
23
|
attr_reader :got
|
21
24
|
|
22
|
-
# @return [Symbol] The matcher.
|
23
|
-
attr_reader :matcher
|
24
|
-
|
25
25
|
# @return [:MUST, :SHOULD, :MAY] The requirement level of the expectation.
|
26
26
|
attr_reader :level
|
27
27
|
|
@@ -57,20 +57,13 @@ module Expresenter
|
|
57
57
|
#
|
58
58
|
# @return [String] The human-readable representation of the result.
|
59
59
|
def inspect
|
60
|
-
"#{self.class}(actual: #{actual.inspect}, "
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
# The readable definition.
|
70
|
-
#
|
71
|
-
# @return [String] A readable string of the definition.
|
72
|
-
def definition
|
73
|
-
[matcher.to_s.tr("_", " "), expected&.inspect].compact.join(SPACE)
|
60
|
+
"#{self.class}(actual: #{actual.inspect}, " \
|
61
|
+
"definition: #{definition.inspect}, " \
|
62
|
+
"error: #{error.inspect}, " \
|
63
|
+
"expected: #{expected.inspect}, " \
|
64
|
+
"got: #{got.inspect}, " \
|
65
|
+
"negate: #{negate?.inspect}, " \
|
66
|
+
"level: #{level.inspect})"
|
74
67
|
end
|
75
68
|
|
76
69
|
# The summary of the result.
|
data/lib/expresenter/fail.rb
CHANGED
@@ -27,22 +27,23 @@ module Expresenter
|
|
27
27
|
|
28
28
|
# Initialize method.
|
29
29
|
#
|
30
|
-
# @param actual
|
31
|
-
# @param
|
32
|
-
#
|
33
|
-
# @param
|
30
|
+
# @param actual [#object_id] Returned value by the challenged subject.
|
31
|
+
# @param definition [String] A readable string of the matcher and any
|
32
|
+
# expected values.
|
33
|
+
# @param error [Exception, nil] Any possible raised exception.
|
34
|
+
# @param expected [#object_id] The expected value.
|
35
|
+
# @param got [Boolean, nil] The result of the boolean comparison
|
34
36
|
# between the actual value and the expected value through the matcher.
|
35
|
-
# @param negate
|
36
|
-
# @param
|
37
|
-
|
38
|
-
|
39
|
-
@
|
40
|
-
@error
|
41
|
-
@expected
|
42
|
-
@got
|
43
|
-
@negate
|
44
|
-
@
|
45
|
-
@level = level
|
37
|
+
# @param negate [Boolean] Evaluated to a negative assertion?
|
38
|
+
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
39
|
+
def initialize(actual:, definition:, error:, expected:, got:, negate:, level:)
|
40
|
+
@actual = actual
|
41
|
+
@definition = definition
|
42
|
+
@error = error
|
43
|
+
@expected = expected
|
44
|
+
@got = got
|
45
|
+
@negate = negate
|
46
|
+
@level = level
|
46
47
|
|
47
48
|
super(to_s)
|
48
49
|
end
|
data/lib/expresenter/pass.rb
CHANGED
@@ -36,21 +36,22 @@ module Expresenter
|
|
36
36
|
# Initialize method.
|
37
37
|
#
|
38
38
|
# @param actual [#object_id] Returned value by the challenged subject.
|
39
|
+
# @param definition [String] A readable string of the matcher and any
|
40
|
+
# expected values.
|
39
41
|
# @param error [Exception, nil] Any possible raised exception.
|
40
42
|
# @param expected [#object_id] The expected value.
|
41
43
|
# @param got [Boolean, nil] The result of the boolean comparison
|
42
44
|
# between the actual value and the expected value through the matcher.
|
43
45
|
# @param negate [Boolean] Evaluated to a negative assertion?
|
44
|
-
# @param matcher [Symbol] The matcher.
|
45
46
|
# @param level [:MUST, :SHOULD, :MAY] The requirement level.
|
46
|
-
def initialize(actual:, error:, expected:, got:, negate:,
|
47
|
-
@actual
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@
|
51
|
-
@
|
52
|
-
@
|
53
|
-
@level
|
47
|
+
def initialize(actual:, definition:, error:, expected:, got:, negate:, level:)
|
48
|
+
@actual = actual
|
49
|
+
@definition = definition
|
50
|
+
@error = error
|
51
|
+
@expected = expected
|
52
|
+
@got = got
|
53
|
+
@negate = negate
|
54
|
+
@level = level
|
54
55
|
end
|
55
56
|
|
56
57
|
# Did the test fail?
|
data/lib/expresenter.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Namespace for the Expresenter library.
|
4
4
|
#
|
5
5
|
# @example A passed expectation result presenter.
|
6
|
-
# Expresenter.call(true).with(actual: "FOO", error: nil, expected: "foo", got: true, negate: true,
|
6
|
+
# Expresenter.call(true).with(actual: "FOO", definition: 'eql "foo"', error: nil, expected: "foo", got: true, negate: true, level: :MUST) # => Expresenter::Pass(actual: "FOO", definition: "eql \"foo\"", error: nil, expected: "foo", got: true, negate: true, level: :MUST)
|
7
7
|
module Expresenter
|
8
8
|
# @param is_passed [Boolean] The value of an assertion.
|
9
9
|
#
|
metadata
CHANGED
@@ -1,141 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expresenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: brutal
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop-md
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-performance
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rake
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-thread_safety
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: yard
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
139
13
|
description: Expectation result presenter.
|
140
14
|
email: contact@cyril.email
|
141
15
|
executables: []
|
@@ -151,7 +25,8 @@ files:
|
|
151
25
|
homepage: https://github.com/fixrb/expresenter
|
152
26
|
licenses:
|
153
27
|
- MIT
|
154
|
-
metadata:
|
28
|
+
metadata:
|
29
|
+
rubygems_mfa_required: 'true'
|
155
30
|
post_install_message:
|
156
31
|
rdoc_options: []
|
157
32
|
require_paths:
|
@@ -160,14 +35,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
35
|
requirements:
|
161
36
|
- - ">="
|
162
37
|
- !ruby/object:Gem::Version
|
163
|
-
version: 2.
|
38
|
+
version: 3.2.0
|
164
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
40
|
requirements:
|
166
41
|
- - ">="
|
167
42
|
- !ruby/object:Gem::Version
|
168
43
|
version: '0'
|
169
44
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
45
|
+
rubygems_version: 3.4.19
|
171
46
|
signing_key:
|
172
47
|
specification_version: 4
|
173
48
|
summary: Expectation result presenter.
|