expresenter 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fa35d343813c6913d049086af460babf8a5a84b18c7058853fe956c50a3f143
4
- data.tar.gz: cbcd35e730fd41b653b7ea944a3b2d0861229e204919747e60940074964aa97d
3
+ metadata.gz: 3460d51122770c7fdd769a71726f8ac91f7ee55d2a97008aac27137aaeb09a43
4
+ data.tar.gz: 2dfe5bac23440dd3a48e75d103da7dd3e12809936f7d3df02a299d7023328286
5
5
  SHA512:
6
- metadata.gz: 6d4e83fd46dc38ac64bae7ebf4577a0d964d11aa49e4ff88c573e294d943a3c450dc2212678b97d6976f7bc3850936db0df3f946b80da22e0d00615c76d48f97
7
- data.tar.gz: 4ad82f7aa266fc139e166821a3b18766c24c50ef5ee92fad16f013d8b4240cfd6ea135e105606dab014ea9afffccb8036b669950d0b8254cf576913aa363dba1
6
+ metadata.gz: d50f24c95d16d6417422c15c060c81b42d9e77f9426c3c7466c066f13f9de76a4e1f1c7dd73c70485e099b20a3e05c94c07c4c640fd796c1d927a217d764acfe
7
+ data.tar.gz: 7f8c9d1c7e6979766be2600d1db0b630ff9ab377f9223e5d8e8b4e874dfb6bd57ec3326a0c16fbf416034c7307c2b056d18bb8b151bdb32edbdd4763e919d427
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Expresenter
2
2
 
3
3
  [![Build Status](https://api.travis-ci.org/fixrb/expresenter.svg?branch=main)][travis]
4
- [![Code Climate](https://codeclimate.com/github/fixrb/expresenter/badges/gpa.svg)][codeclimate]
5
4
  [![Gem Version](https://badge.fury.io/rb/expresenter.svg)][gem]
6
5
  [![Inline docs](https://inch-ci.org/github/fixrb/expresenter.svg?branch=main)][inchpages]
7
6
  [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
@@ -18,11 +17,15 @@ gem "expresenter"
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 expresenter
26
+ ```sh
27
+ gem install expresenter
28
+ ```
26
29
 
27
30
  ## Usage
28
31
 
@@ -88,10 +91,9 @@ result.success? # => true
88
91
  result.valid? # => true
89
92
  result.inspect # => "Expresenter::Pass(actual: \"FOO\", error: nil, expected: \"foo\", got: true, matcher: :eql, negate: true, level: :MUST, valid: true)"
90
93
  result.definition # => "eql \"foo\""
91
- result.maybe_negate # => " not"
92
94
  result.summary # => "expected \"FOO\" not to eql \"foo\""
93
95
  result.colored_char # => "\e[32m.\e[0m"
94
- result.colored_string # => "\e[32mSuccess: expected \"FOO\" not to eql \"foo\".\e[0m"
96
+ result.colored_string # => "\e[32m\e[1mSuccess\e[22m: expected \"FOO\" not to eql \"foo\".\e[0m"
95
97
  result.message # => "Success: expected \"FOO\" not to eql \"foo\"."
96
98
  result.to_s # => "Success: expected \"FOO\" not to eql \"foo\"."
97
99
  result.titre # => "Success"
@@ -102,27 +104,26 @@ A failed expectation:
102
104
  ```ruby
103
105
  result = Expresenter.call(false).new(actual: "foo", error: Exception.new("BOOM"), expected: 42, got: true, negate: true, valid: true, matcher: :eql, level: :MUST)
104
106
 
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"
107
+ result.failed? # => true
108
+ result.failure? # => false
109
+ result.info? # => false
110
+ result.warning? # => false
111
+ result.to_sym # => :error
112
+ result.char # => "E"
113
+ result.emoji # => "💥"
114
+ result.passed? # => false
115
+ result.negate? # => true
116
+ result.error? # => true
117
+ result.success? # => true
118
+ result.valid? # => true
119
+ result.inspect # => "Expresenter::Fail(actual: \"foo\", error: #<Exception: BOOM>, expected: 42, got: true, matcher: :eql, negate: true, level: :MUST, valid: true)"
120
+ result.definition # => "eql 42"
121
+ result.summary # => "BOOM"
122
+ result.colored_char # => "\e[31mE\e[0m"
123
+ result.colored_string # => "\e[31m\e[1mException\e[22m: BOOM.\e[0m"
124
+ result.message # => "Exception: BOOM."
125
+ result.to_s # => "Exception: BOOM."
126
+ result.titre # => "Exception"
126
127
  ```
127
128
 
128
129
  ### Return or Raise
@@ -144,7 +145,7 @@ Expresenter.call(false).with(actual: "foo", error: Exception.new("BOOM"), expect
144
145
  > Traceback (most recent call last):
145
146
  > 3: from ./bin/console:7:in `<main>'
146
147
  > 2: from (irb):1
147
- > 1: from /Users/cyril/github/fixrb/expresenter/lib/expresenter/fail.rb:12:in `with'
148
+ > 1: from /Users/cyril/github/fixrb/expresenter/lib/expresenter/fail.rb:19:in `with'
148
149
  > Expresenter::Fail (Exception: BOOM.)
149
150
 
150
151
  ### More Examples
@@ -157,19 +158,13 @@ A full list of unit tests can be viewed (and executed) here:
157
158
  * Home page: https://github.com/fixrb/expresenter
158
159
  * Bugs/issues: https://github.com/fixrb/expresenter/issues
159
160
 
160
- ## Rubies
161
-
162
- * [MRI](https://www.ruby-lang.org/)
163
- * [Rubinius](https://rubinius.com/)
164
- * [JRuby](https://www.jruby.org/)
165
-
166
161
  ## Versioning
167
162
 
168
163
  __Expresenter__ follows [Semantic Versioning 2.0](https://semver.org/).
169
164
 
170
165
  ## License
171
166
 
172
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
167
+ The [gem](https://rubygems.org/gems/expresenter) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
173
168
 
174
169
  ***
175
170
 
@@ -182,6 +177,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
182
177
 
183
178
  [gem]: https://rubygems.org/gems/expresenter
184
179
  [travis]: https://travis-ci.org/fixrb/expresenter
185
- [codeclimate]: https://codeclimate.com/github/fixrb/expresenter
186
180
  [inchpages]: https://inch-ci.org/github/fixrb/expresenter
187
181
  [rubydoc]: https://rubydoc.info/gems/expresenter/frames
@@ -3,6 +3,8 @@
3
3
  module Expresenter
4
4
  # Common collection of methods.
5
5
  module Common
6
+ SPACE = " "
7
+
6
8
  # @return [#object_id] Returned value by the challenged subject.
7
9
  attr_reader :actual
8
10
 
@@ -76,14 +78,7 @@ module Expresenter
76
78
  #
77
79
  # @return [String] A readable string of the definition.
78
80
  def definition
79
- [matcher, expected&.inspect].compact.join(" ")
80
- end
81
-
82
- # The negation, if any.
83
- #
84
- # @return [String] The negation, or an empty string.
85
- def maybe_negate
86
- negate? ? " not" : ""
81
+ [matcher, expected&.inspect].compact.join(SPACE)
87
82
  end
88
83
 
89
84
  # The summary of the result.
@@ -95,9 +90,9 @@ module Expresenter
95
90
  elsif actual.is_a?(::Exception)
96
91
  actual.message
97
92
  elsif actual == expected
98
- "expected#{maybe_negate} to #{definition}"
93
+ ["expected", negation, "to", definition].compact.join(SPACE)
99
94
  else
100
- "expected #{actual.inspect}#{maybe_negate} to #{definition}"
95
+ ["expected", actual.inspect, negation, "to", definition].compact.join(SPACE)
101
96
  end
102
97
  end
103
98
 
@@ -112,7 +107,7 @@ module Expresenter
112
107
  #
113
108
  # @return [String] A string representing the result.
114
109
  def colored_string
115
- color(to_s)
110
+ color(to_bold_s)
116
111
  end
117
112
 
118
113
  # The representation of the result.
@@ -135,18 +130,18 @@ module Expresenter
135
130
 
136
131
  protected
137
132
 
138
- def color(str)
139
- if success?
140
- "\e[32m#{str}\e[0m"
141
- elsif info?
142
- "\e[36m#{str}\e[0m"
143
- elsif warning?
144
- "\e[33m#{str}\e[0m"
145
- elsif failure?
146
- "\e[35m#{str}\e[0m"
147
- else
148
- "\e[31m#{str}\e[0m"
149
- end
133
+ # The negation, if any.
134
+ #
135
+ # @return [String, nil] The negation, or an empty string.
136
+ def negation
137
+ "not" if negate?
138
+ end
139
+
140
+ # The representation of the result with the title in bold.
141
+ #
142
+ # @return [String] A string representing the result with the title in bold.
143
+ def to_bold_s
144
+ "\e[1m#{titre}\e[22m: #{summary}."
150
145
  end
151
146
  end
152
147
  end
@@ -5,6 +5,12 @@ require_relative "common"
5
5
  module Expresenter
6
6
  # The class that is responsible for reporting that an expectation is false.
7
7
  class Fail < ::StandardError
8
+ FAILURE_CHAR = "F"
9
+ FAILURE_EMOJI = "❌"
10
+
11
+ ERROR_CHAR = "E"
12
+ ERROR_EMOJI = "💥"
13
+
8
14
  include Common
9
15
 
10
16
  # @param (see Fail#initialize)
@@ -83,9 +89,9 @@ module Expresenter
83
89
  # @return [String] The char that identify the result.
84
90
  def char
85
91
  if failure?
86
- "F"
92
+ FAILURE_CHAR
87
93
  else
88
- "E"
94
+ ERROR_CHAR
89
95
  end
90
96
  end
91
97
 
@@ -94,9 +100,19 @@ module Expresenter
94
100
  # @return [String] The emoji that identify the result.
95
101
  def emoji
96
102
  if failure?
97
- "❌"
103
+ FAILURE_EMOJI
104
+ else
105
+ ERROR_EMOJI
106
+ end
107
+ end
108
+
109
+ protected
110
+
111
+ def color(str)
112
+ if failure?
113
+ "\e[35m#{str}\e[0m" # purple
98
114
  else
99
- "💥"
115
+ "\e[31m#{str}\e[0m" # red
100
116
  end
101
117
  end
102
118
  end
@@ -5,6 +5,15 @@ require_relative "common"
5
5
  module Expresenter
6
6
  # The class that is responsible for reporting that an expectation is true.
7
7
  class Pass
8
+ INFO_CHAR = "I"
9
+ INFO_EMOJI = "💡"
10
+
11
+ SUCCESS_CHAR = "."
12
+ SUCCESS_EMOJI = "✅"
13
+
14
+ WARNING_CHAR = "W"
15
+ WARNING_EMOJI = "⚠️"
16
+
8
17
  include Common
9
18
 
10
19
  # @param (see Pass#initialize)
@@ -71,10 +80,13 @@ module Expresenter
71
80
  #
72
81
  # @return [Symbol] The identifier of the state.
73
82
  def to_sym
74
- return :success if success?
75
- return :warning if warning?
76
-
77
- :info
83
+ if success?
84
+ :success
85
+ elsif warning?
86
+ :warning
87
+ else
88
+ :info
89
+ end
78
90
  end
79
91
 
80
92
  # Express the result with one char.
@@ -82,11 +94,11 @@ module Expresenter
82
94
  # @return [String] The char that identify the result.
83
95
  def char
84
96
  if success?
85
- "."
97
+ SUCCESS_CHAR
86
98
  elsif warning?
87
- "W"
99
+ WARNING_CHAR
88
100
  else
89
- "I"
101
+ INFO_CHAR
90
102
  end
91
103
  end
92
104
 
@@ -95,11 +107,23 @@ module Expresenter
95
107
  # @return [String] The emoji that identify the result.
96
108
  def emoji
97
109
  if success?
98
- "✅"
110
+ SUCCESS_EMOJI
111
+ elsif warning?
112
+ WARNING_EMOJI
113
+ else
114
+ INFO_EMOJI
115
+ end
116
+ end
117
+
118
+ protected
119
+
120
+ def color(str)
121
+ if success?
122
+ "\e[32m#{str}\e[0m" # green
99
123
  elsif warning?
100
- "⚠️"
124
+ "\e[33m#{str}\e[0m" # yellow
101
125
  else
102
- "💡"
126
+ "\e[36m#{str}\e[0m" # blue
103
127
  end
104
128
  end
105
129
  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.1.0
4
+ version: 1.2.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-12 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brutal
@@ -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.4
170
+ rubygems_version: 3.1.6
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Expectation result presenter.