spectus 3.1.4 → 3.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73306cc997a51543203fcfbec28fedae74de8ca9f382040db66d1c6aebbfc4bd
4
- data.tar.gz: c9d9365b33cc4cca9cb54630306f9320c254a42ad64161d8a609107eeb8f95e3
3
+ metadata.gz: 99e857c2dbe2b02d961770b40bd9119fa115665105c99f0a6eb813266e9b72be
4
+ data.tar.gz: 6f54bf36215f3f662257cffd68e420051f83f6de13d15d9dca60ffb7e89b9c0f
5
5
  SHA512:
6
- metadata.gz: 5cdfb58c6e5e3b748f8c5071f354793618a6e6e00053e3139175c5afde4cbc2fd39a419fbe516970354a6eaaee585637077d6dcc65b1d3ba7ae5412f26dcce60
7
- data.tar.gz: 8211f7d6955d70067071a691bfa80b1f640930c01db4cec6433534141c3f7c7a4e386ee82c80f00941b3c6a04426d2266be7cdb416960e04c5e8a36b0f35bc95
6
+ metadata.gz: 5d6b1e7a99bc5d6b52760a8f5fa37f58d485bda7fbf08d9790f78944375d46807366cc9c0232f5f0bb25940b668f89b8a153b78940204ee8e0c54cdc371dacd4
7
+ data.tar.gz: 658aaa685fe75ea3fd06c92b0ddca3066efb841cf3c0aa4b252f7d2a9f797ea9f44791ff441bc72bfc76f95fd3f3c532a8b4a1b74e40ea832f6c72ffcbff9b3d
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Spectus
2
2
 
3
3
  [![Build Status](https://api.travis-ci.org/fixrb/spectus.svg?branch=main)][travis]
4
- [![Code Climate](https://codeclimate.com/github/fixrb/spectus/badges/gpa.svg)][codeclimate]
5
4
  [![Gem Version](https://badge.fury.io/rb/spectus.svg)][gem]
6
5
  [![Inline docs](https://inch-ci.org/github/fixrb/spectus.svg?branch=main)][inchpages]
7
6
  [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
@@ -18,69 +17,14 @@ gem "spectus"
18
17
 
19
18
  And then execute:
20
19
 
21
- $ bundle
20
+ ```sh
21
+ bundle
22
+ ```
22
23
 
23
24
  Or install it yourself as:
24
25
 
25
- $ gem install spectus
26
-
27
- ## Expectation
28
-
29
- An expectation is an assertion that is either `true` or `false`.
30
-
31
- There are several scenarios:
32
-
33
- | Requirement levels | **MUST** | **SHOULD** | **MAY** |
34
- | ------------------------- | -------- | ---------- | ------- |
35
- | Implemented & Matched | `true` | `true` | `true` |
36
- | Implemented & Not matched | `false` | `true` | `false` |
37
- | Implemented & Exception | `false` | `false` | `false` |
38
- | Not implemented | `false` | `false` | `true` |
39
-
40
- Thus,
41
-
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
-
45
- Both results share a common interface.
46
-
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
57
-
58
- ## Code Isolation
59
-
60
- When executing expectations, side-effects may occur.
61
- Because they may or may not be desired, each requirement level has 2 versions:
62
-
63
- * if it does not end with `!`, its test is performed without isolation;
64
- * if it ends with `!`, its test is performed in isolation.
65
-
66
- Example of test without isolation:
67
-
68
- ```ruby
69
- include Spectus
70
- greeting = "Hello, world!"
71
- it { greeting.gsub!("world", "Alice") }.MUST eql "Hello, Alice!"
72
- # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
73
- greeting # => "Hello, Alice!"
74
- ```
75
-
76
- Example of test in isolation:
77
-
78
- ```ruby
79
- include Spectus
80
- greeting = "Hello, world!"
81
- it { greeting.gsub!("world", "Alice") }.MUST! eql "Hello, Alice!"
82
- # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
83
- greeting # => "Hello, world!"
26
+ ```sh
27
+ gem install spectus
84
28
  ```
85
29
 
86
30
  ## Usage
@@ -152,6 +96,34 @@ The optional `blank?` method is not implemented (unlike in [Ruby on Rails](https
152
96
  A full list of unit tests can be viewed (and executed) here:
153
97
  [./test.rb](https://github.com/fixrb/spectus/blob/main/test.rb)
154
98
 
99
+ ## Code Isolation
100
+
101
+ When executing expectations, side-effects may occur.
102
+ Because they may or may not be desired, each requirement level has 2 versions:
103
+
104
+ * if it does not end with `!`, its test is performed without isolation;
105
+ * if it ends with `!`, its test is performed in isolation.
106
+
107
+ Example of test without isolation:
108
+
109
+ ```ruby
110
+ include Spectus
111
+ greeting = "Hello, world!"
112
+ it { greeting.gsub!("world", "Alice") }.MUST eql "Hello, Alice!"
113
+ # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
114
+ greeting # => "Hello, Alice!"
115
+ ```
116
+
117
+ Example of test in isolation:
118
+
119
+ ```ruby
120
+ include Spectus
121
+ greeting = "Hello, world!"
122
+ it { greeting.gsub!("world", "Alice") }.MUST! eql "Hello, Alice!"
123
+ # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
124
+ greeting # => "Hello, world!"
125
+ ```
126
+
155
127
  ## Contact
156
128
 
157
129
  * Home page: https://github.com/fixrb/spectus
@@ -163,7 +135,7 @@ __Spectus__ follows [Semantic Versioning 2.0](https://semver.org/).
163
135
 
164
136
  ## License
165
137
 
166
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
138
+ The [gem](https://rubygems.org/gems/spectus) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
167
139
 
168
140
  ***
169
141
 
@@ -176,6 +148,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
176
148
 
177
149
  [gem]: https://rubygems.org/gems/spectus
178
150
  [travis]: https://travis-ci.org/fixrb/spectus
179
- [codeclimate]: https://codeclimate.com/github/fixrb/spectus
180
151
  [inchpages]: https://inch-ci.org/github/fixrb/spectus
181
152
  [rubydoc]: https://rubydoc.info/gems/spectus/frames
@@ -19,11 +19,12 @@ module Spectus
19
19
  # definition is an absolute requirement of the specification.
20
20
  #
21
21
  # @example _Absolute requirement_ definition
22
- # it { 'foo'.upcase }.MUST eql 'FOO'
22
+ # it { "foo".upcase }.MUST eql 'FOO'
23
23
  #
24
24
  # @param matcher [#matches?] The matcher.
25
25
  #
26
- # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
26
+ # @return [Spectus::Result::Fail, Spectus::Result::Pass] Report if the spec
27
+ # pass or fail.
27
28
  def MUST(matcher)
28
29
  RequirementLevel::Must.new(
29
30
  callable: callable,
@@ -34,7 +35,7 @@ module Spectus
34
35
  end
35
36
 
36
37
  # @example _Absolute requirement_ definition with isolation
37
- # it { 'foo'.upcase }.MUST! eql 'FOO'
38
+ # it { "foo".upcase }.MUST! eql 'FOO'
38
39
  #
39
40
  # @see MUST
40
41
  def MUST!(matcher)
@@ -50,11 +51,12 @@ module Spectus
50
51
  # definition is an absolute prohibition of the specification.
51
52
  #
52
53
  # @example _Absolute prohibition_ definition
53
- # it { 'foo'.size }.MUST_NOT equal 42
54
+ # it { "foo".size }.MUST_NOT equal 42
54
55
  #
55
56
  # @param matcher [#matches?] The matcher.
56
57
  #
57
- # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
58
+ # @return [Spectus::Result::Fail, Spectus::Result::Pass] Report if the spec
59
+ # pass or fail.
58
60
  def MUST_NOT(matcher)
59
61
  RequirementLevel::Must.new(
60
62
  callable: callable,
@@ -65,7 +67,7 @@ module Spectus
65
67
  end
66
68
 
67
69
  # @example _Absolute prohibition_ definition with isolation
68
- # it { 'foo'.size }.MUST_NOT! equal 42
70
+ # it { "foo".size }.MUST_NOT! equal 42
69
71
  #
70
72
  # @see MUST_NOT
71
73
  def MUST_NOT!(matcher)
@@ -83,11 +85,12 @@ module Spectus
83
85
  # carefully weighed before choosing a different course.
84
86
  #
85
87
  # @example _Recommended_ definition
86
- # it { 'foo'.valid_encoding? }.SHOULD equal true
88
+ # it { "foo".valid_encoding? }.SHOULD equal true
87
89
  #
88
90
  # @param matcher [#matches?] The matcher.
89
91
  #
90
- # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
92
+ # @return [Spectus::Result::Fail, Spectus::Result::Pass] Report if the spec
93
+ # pass or fail.
91
94
  def SHOULD(matcher)
92
95
  RequirementLevel::Should.new(
93
96
  callable: callable,
@@ -98,7 +101,7 @@ module Spectus
98
101
  end
99
102
 
100
103
  # @example _Recommended_ definition with isolation
101
- # it { 'foo'.valid_encoding? }.SHOULD! equal true
104
+ # it { "foo".valid_encoding? }.SHOULD! equal true
102
105
  #
103
106
  # @see SHOULD
104
107
  def SHOULD!(matcher)
@@ -117,11 +120,12 @@ module Spectus
117
120
  # before implementing any behavior described with this label.
118
121
  #
119
122
  # @example _Not recommended_ definition
120
- # it { ''.blank? }.SHOULD_NOT raise_exception NoMethodError
123
+ # it { "".blank? }.SHOULD_NOT raise_exception NoMethodError
121
124
  #
122
125
  # @param matcher [#matches?] The matcher.
123
126
  #
124
- # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
127
+ # @return [Spectus::Result::Fail, Spectus::Result::Pass] Report if the spec
128
+ # pass or fail.
125
129
  def SHOULD_NOT(matcher)
126
130
  RequirementLevel::Should.new(
127
131
  callable: callable,
@@ -132,7 +136,7 @@ module Spectus
132
136
  end
133
137
 
134
138
  # @example _Not recommended_ definition with isolation
135
- # it { ''.blank? }.SHOULD_NOT! raise_exception NoMethodError
139
+ # it { "".blank? }.SHOULD_NOT! raise_exception NoMethodError
136
140
  #
137
141
  # @see SHOULD_NOT
138
142
  def SHOULD_NOT!(matcher)
@@ -157,11 +161,11 @@ module Spectus
157
161
  # option provides.)
158
162
  #
159
163
  # @example _Optional_ definition
160
- # it { 'foo'.bar }.MAY match /^foo$/
164
+ # it { "foo".bar }.MAY match /^foo$/
161
165
  #
162
166
  # @param matcher [#matches?] The matcher.
163
167
  #
164
- # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
168
+ # @return [Spectus::Result::Fail, Spectus::Result::Pass] Report if the spec pass or fail.
165
169
  def MAY(matcher)
166
170
  RequirementLevel::May.new(
167
171
  callable: callable,
@@ -172,7 +176,7 @@ module Spectus
172
176
  end
173
177
 
174
178
  # @example _Optional_ definition with isolation
175
- # it { 'foo'.bar }.MAY! match /^foo$/
179
+ # it { "foo".bar }.MAY! match /^foo$/
176
180
  #
177
181
  # @see MAY
178
182
  def MAY!(matcher)
@@ -32,18 +32,19 @@ module Spectus
32
32
 
33
33
  # The result of the expectation.
34
34
  #
35
- # @raise [Result::Fail] The expectation is `false`.
36
- # @return [Result::Pass] The expectation is `true`.
35
+ # @raise [Spectus::Result::Fail] The expectation is `false`.
36
+ # @return [Spectus::Result::Pass] The expectation is `true`.
37
37
  def call
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
+ Result.call(pass?).with(
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
47
+ )
47
48
  end
48
49
 
49
50
  protected
@@ -64,5 +65,5 @@ module Spectus
64
65
  end
65
66
  end
66
67
 
67
- require_relative File.join("..", "result")
68
68
  require_relative File.join("..", "exam")
69
+ require_relative File.join("..", "result")
@@ -3,10 +3,13 @@
3
3
  module Spectus
4
4
  # Namespace for the results.
5
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)
6
+ # @param is_passed [Boolean] The value of an assertion.
7
+ # @return [Class<Spectus::Result::Pass>, Class<Spectus::Result::Fail>] The
8
+ # class of the result.
9
+ # @example Get the pass class result.
10
+ # call(true) # => Pass
11
+ def self.call(is_passed)
12
+ is_passed ? Pass : Fail
10
13
  end
11
14
  end
12
15
  end
@@ -1,74 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "common"
3
+ require "expresenter/fail"
4
4
 
5
5
  module Spectus
6
6
  module Result
7
7
  # The class that is responsible for reporting that the expectation is false.
8
- class Fail < ::StandardError
9
- include Common
10
-
11
- # @raise [Fail] A failed spec result.
12
- def self.call(**details)
13
- raise new(**details)
14
- end
15
-
16
- # Did the test fail?
17
- #
18
- # @return [Boolean] The spec passed or failed?
19
- def failed?
20
- true
21
- end
22
-
23
- # The state of failure.
24
- #
25
- # @return [Boolean] The test was a failure?
26
- def failure?
27
- !error?
28
- end
29
-
30
- # The state of info.
31
- #
32
- # @return [Boolean] The test was an info?
33
- def info?
34
- false
35
- end
36
-
37
- # The state of warning.
38
- #
39
- # @return [Boolean] The test was a warning?
40
- def warning?
41
- false
42
- end
43
-
44
- # Identify the state of the result.
45
- #
46
- # @return [Symbol] The identifier of the state.
47
- def to_sym
48
- failure? ? :failure : :error
49
- end
50
-
51
- # Express the result with one char.
52
- #
53
- # @return [String] The char that identify the result.
54
- def char
55
- if failure?
56
- "F"
57
- else
58
- "E"
59
- end
60
- end
61
-
62
- # Express the result with one emoji.
63
- #
64
- # @return [String] The emoji that identify the result.
65
- def emoji
66
- if failure?
67
- "❌"
68
- else
69
- "💥"
70
- end
71
- end
8
+ class Fail < ::Expresenter::Fail
72
9
  end
73
10
  end
74
11
  end
@@ -1,83 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "common"
3
+ require "expresenter/pass"
4
4
 
5
5
  module Spectus
6
6
  module Result
7
7
  # The class that is responsible for reporting that the expectation is true.
8
- class Pass
9
- include Common
10
-
11
- # @return [Pass] A passed spec result.
12
- def self.call(**details)
13
- new(**details)
14
- end
15
-
16
- alias message to_s
17
-
18
- # Did the test fail?
19
- #
20
- # @return [Boolean] The spec passed or failed?
21
- def failed?
22
- false
23
- end
24
-
25
- # The state of failure.
26
- #
27
- # @return [Boolean] The test was a failure?
28
- def failure?
29
- false
30
- end
31
-
32
- # The state of info.
33
- #
34
- # @return [Boolean] The test was an info?
35
- def info?
36
- !error.nil?
37
- end
38
-
39
- # The state of warning.
40
- #
41
- # @return [Boolean] The test was a warning?
42
- def warning?
43
- got.equal?(false)
44
- end
45
-
46
- # Identify the state of the result.
47
- #
48
- # @return [Symbol] The identifier of the state.
49
- def to_sym
50
- return :success if success?
51
- return :warning if warning?
52
-
53
- :info
54
- end
55
-
56
- # Express the result with one char.
57
- #
58
- # @return [String] The char that identify the result.
59
- def char
60
- if success?
61
- "."
62
- elsif warning?
63
- "W"
64
- else
65
- "I"
66
- end
67
- end
68
-
69
- # Express the result with one emoji.
70
- #
71
- # @return [String] The emoji that identify the result.
72
- def emoji
73
- if success?
74
- "✅"
75
- elsif warning?
76
- "⚠️"
77
- else
78
- "💡"
79
- end
80
- end
8
+ class Pass < ::Expresenter::Pass
81
9
  end
82
10
  end
83
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.3.3
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 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: defi
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.4
19
+ version: 2.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.4
26
+ version: 2.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: expresenter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: matchi
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 2.0.0
47
+ version: 2.0.2
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 2.0.0
54
+ version: 2.0.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: brutal
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -180,7 +194,6 @@ files:
180
194
  - lib/spectus/requirement_level/must.rb
181
195
  - lib/spectus/requirement_level/should.rb
182
196
  - lib/spectus/result.rb
183
- - lib/spectus/result/common.rb
184
197
  - lib/spectus/result/fail.rb
185
198
  - lib/spectus/result/pass.rb
186
199
  homepage: https://github.com/fixrb/spectus
@@ -202,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
215
  - !ruby/object:Gem::Version
203
216
  version: '0'
204
217
  requirements: []
205
- rubygems_version: 3.1.4
218
+ rubygems_version: 3.1.6
206
219
  signing_key:
207
220
  specification_version: 4
208
221
  summary: "Expectation library with RFC 2119's requirement levels \U0001F6A5"
@@ -1,180 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spectus
4
- module Result
5
- # Common collection of methods for Result's classes.
6
- module Common
7
- # @return [#object_id] Returned value by the challenged subject.
8
- attr_reader :actual
9
-
10
- # @return [Exception, nil] Any possible raised exception.
11
- attr_reader :error
12
-
13
- # @return [#object_id] The expected value.
14
- attr_reader :expected
15
-
16
- # @return [#object_id] The result of the boolean comparison between the
17
- # actual value and the expected value through the matcher.
18
- attr_reader :got
19
-
20
- # @return [#object_id] The matcher.
21
- attr_reader :matcher
22
-
23
- # @return [:MUST, :SHOULD, :MAY] The requirement level of the expectation.
24
- attr_reader :level
25
-
26
- # Common initialize method.
27
- #
28
- # @param actual [#object_id] Returned value by the challenged subject.
29
- # @param error [Exception, nil] Any possible raised exception.
30
- # @param expected [#object_id] The expected value.
31
- # @param got [Boolean, nil] The result of the boolean comparison
32
- # between the actual value and the expected value through the matcher.
33
- # @param negate [Boolean] Evaluated to a negative assertion?
34
- # @param valid [Boolean] Report if the test was true or false?
35
- # @param matcher [Symbol] The matcher.
36
- # @param level [:MUST, :SHOULD, :MAY] The requirement level.
37
- def initialize(actual:, error:, expected:, got:, negate:, valid:,
38
- matcher:, level:)
39
-
40
- @actual = actual
41
- @error = error
42
- @expected = expected
43
- @got = got
44
- @negate = negate
45
- @valid = valid
46
- @matcher = matcher
47
- @level = level
48
-
49
- super(to_s) if failed?
50
- end
51
-
52
- # Did the test pass?
53
- #
54
- # @return [Boolean] The spec passed or failed?
55
- def passed?
56
- !failed?
57
- end
58
-
59
- # The value of the negate instance variable.
60
- #
61
- # @return [Boolean] Evaluated to a negative assertion?
62
- def negate?
63
- @negate
64
- end
65
-
66
- # The state of error.
67
- #
68
- # @return [Boolean] The test raised an error?
69
- def error?
70
- !error.nil?
71
- end
72
-
73
- # The state of success.
74
- #
75
- # @return [Boolean] The test was a success?
76
- def success?
77
- got.equal?(true)
78
- end
79
-
80
- # The value of the boolean comparison between the actual value and the
81
- # expected value.
82
- #
83
- # @return [Boolean] The test was true or false?
84
- def valid?
85
- @valid
86
- end
87
-
88
- # A string containing a human-readable representation of the result.
89
- #
90
- # @return [String] The human-readable representation of the result.
91
- def inspect
92
- "#{self.class}(actual: #{actual.inspect}, " \
93
- "error: #{error.inspect}, " \
94
- "expected: #{expected.inspect}, " \
95
- "got: #{got.inspect}, " \
96
- "matcher: #{matcher.inspect}, " \
97
- "negate: #{negate?.inspect}, " \
98
- "level: #{level.inspect}, " \
99
- "valid: #{valid?.inspect})" \
100
- end
101
-
102
- # The readable definition.
103
- #
104
- # @return [String] A readable string of the definition.
105
- def definition
106
- [matcher, expected&.inspect].compact.join(" ")
107
- end
108
-
109
- # The negation, if any.
110
- #
111
- # @return [String] The negation, or an empty string.
112
- def maybe_negate
113
- negate? ? " not" : ""
114
- end
115
-
116
- # The summary of the result.
117
- #
118
- # @return [String] A string representing the summary of the result.
119
- def summary
120
- if error?
121
- error.message
122
- elsif actual.is_a?(::Exception)
123
- actual.message
124
- elsif actual == expected
125
- "expected#{maybe_negate} to #{definition}"
126
- else
127
- "expected #{actual.inspect}#{maybe_negate} to #{definition}"
128
- end
129
- end
130
-
131
- # Express the result with one colored char.
132
- #
133
- # @return [String] The colored char that identify the result.
134
- def colored_char
135
- color(char)
136
- end
137
-
138
- # The colored string representation of the result.
139
- #
140
- # @return [String] A string representing the result.
141
- def colored_string
142
- color(to_s)
143
- end
144
-
145
- # The representation of the result.
146
- #
147
- # @return [String] A string representing the result.
148
- def to_s
149
- "#{titre}: #{summary}."
150
- end
151
-
152
- # Titre for the result.
153
- #
154
- # @return [String] A string representing the titre.
155
- def titre
156
- if error?
157
- error.class.name
158
- else
159
- to_sym.to_s.capitalize
160
- end
161
- end
162
-
163
- protected
164
-
165
- def color(str)
166
- if success?
167
- "\e[32m#{str}\e[0m"
168
- elsif info?
169
- "\e[36m#{str}\e[0m"
170
- elsif warning?
171
- "\e[33m#{str}\e[0m"
172
- elsif failure?
173
- "\e[35m#{str}\e[0m"
174
- else
175
- "\e[31m#{str}\e[0m"
176
- end
177
- end
178
- end
179
- end
180
- end