expresenter 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b293c0c6ffd15b336c00fcc841647e6d244623346dd86ab6cf319c05cfc7d909
4
- data.tar.gz: 3901ec01f1277302150665002b97c157ba26846bf08e344bd364fbb7fdec874d
3
+ metadata.gz: 7681f55eec320e3a594a0dd3bf83bed059059c4fe0786c21702d100cdcff4686
4
+ data.tar.gz: 120bfa0781682b31af511528a1271118329745a0348e11a9508eb20daf55c082
5
5
  SHA512:
6
- metadata.gz: db88b4f5c706ae1aaf48fdf6b2b45aa0ab4d0fe1f5a557331e51b8b9c9333f07305ec1f6d5f3287a34ed39e20396fd2d4879f5b186e94e9653420604a1d2ca3d
7
- data.tar.gz: 04c1db7b8ea904a67397305f111bde2e4dadac40c6cdd392cb855b3b4db24a8ae904c92cfe07332cdc137cceea57481d9d920803941722b3e8749db16d0b346b
6
+ metadata.gz: 9b9618acf9d062eacc9ac69ac3bca457fa6bbf7172baca826ee77f21365ef994e356fbf03b983fc39403a23fdecc7abdaa32ea4e5837a1260e5bf1696f8fb60c
7
+ data.tar.gz: 02a640a1f52ea92dce4e1fc8c88128142fb3ca9f2e14b811ba654008ce769f92c0d2137b88dd734a9bf91d8b68be758c0b6d862c3cf11d8b9aef4fc87bb02646
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Expresenter
2
2
 
3
- [![Build Status](https://api.travis-ci.org/fixrb/expresenter.svg?branch=main)][travis]
4
- [![Gem Version](https://badge.fury.io/rb/expresenter.svg)][gem]
5
- [![Inline docs](https://inch-ci.org/github/fixrb/expresenter.svg?branch=main)][inchpages]
6
- [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
3
+ [![Version](https://img.shields.io/github/v/tag/fixrb/expresenter?label=Version&logo=github)](https://github.com/fixrb/expresenter/releases)
4
+ [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/expresenter/main)
5
+ [![CI](https://github.com/fixrb/expresenter/workflows/CI/badge.svg?branch=main)](https://github.com/fixrb/expresenter/actions?query=workflow%3Aci+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
 
@@ -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, matcher: :eql, level: :MUST)
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, matcher: :eql, negate: true, level: :MUST)"
91
- result.definition # => "eql \"foo\""
92
- result.summary # => "expected \"FOO\" not to eql \"foo\""
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 eql \"foo\".\e[0m"
95
- result.message # => "Success: expected \"FOO\" not to eql \"foo\"."
96
- result.to_s # => "Success: expected \"FOO\" not to eql \"foo\"."
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, matcher: :eql, level: :MUST)
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, matcher: :eql, negate: true, level: :MUST)"
117
- result.definition # => "eql 42"
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, matcher: :eql, level: :MUST) # => Expresenter::Pass(actual: "FOO", error: nil, expected: "foo", got: true, matcher: :eql, negate: true, level: :MUST)
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, matcher: :eql, level: :MUST)
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
- > 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'
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
@@ -171,8 +173,3 @@ The [gem](https://rubygems.org/gems/expresenter) is available as open source und
171
173
  src="https://github.com/fixrb/expresenter/raw/main/img/sashite.png"
172
174
  alt="Sashite" /></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.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, matcher: :eql, level: :MUST) # => Expresenter::Pass(actual: "FOO", error: nil, expected: "foo", got: true, matcher: :eql, negate: true, level: :MUST)
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
  #
@@ -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
- "error: #{error.inspect}, " \
62
- "expected: #{expected.inspect}, " \
63
- "got: #{got.inspect}, " \
64
- "matcher: #{matcher.inspect}, " \
65
- "negate: #{negate?.inspect}, " \
66
- "level: #{level.inspect}" \
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.
@@ -27,22 +27,23 @@ module Expresenter
27
27
 
28
28
  # Initialize method.
29
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
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 [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
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
@@ -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:, matcher:, level:)
47
- @actual = actual
48
- @error = error
49
- @expected = expected
50
- @got = got
51
- @negate = negate
52
- @matcher = matcher
53
- @level = 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?
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.3.0
4
+ version: 1.4.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-06-19 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal