spectus 4.0.1 → 4.0.2

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: ed1222cb49baae653e3e0650224f658c9efe61059d3a91e492db7d7a9c2b9ff4
4
- data.tar.gz: 6894d5af94f3bafb3164dfa129ee3ced2914fc22edb51968ff005037c0c292be
3
+ metadata.gz: 45d1a638f042621d43b991c15aea5311a0b370c82f63d37c8fefa6e0a29dba8b
4
+ data.tar.gz: 5bc2409a8d4daeb2e69ca70ac3c6e7d209f4c47a40088c859b545929a2841018
5
5
  SHA512:
6
- metadata.gz: 07f4bc04c3c3d02874f52f1f59c9436651933c4830d456ef64895a6d94e2c4c5672e341b416a998400e43fb861e89fa721cc0879af99c89e26e09b1d5f0c7724
7
- data.tar.gz: 9b7a1da40d5c191f00d4856259a8908aceb87fa73eeaaae6c447448866a73389ba23b7fd9b6b5845b5588e6adac3bd5cb0a1630ddb912752846d0d260c41f95e
6
+ metadata.gz: 8a5cea6a4c057897592889e4215963176011906d940367e2e62404302ba87bc2fa1550716aba9fe00b8896375f3cb6b4785b2c7d74338c17c3df745c3da4ffb6
7
+ data.tar.gz: 5ad609a281efbde26dacc5e57c3ec0955ce431755bd206aa2617a2bbbba7740bb6730bd22603dfc2ac3159c60f8fea003e9bb0a097ac5755bd01fbb88ac47648
data/README.md CHANGED
@@ -45,76 +45,73 @@ gem install matchi
45
45
  ```
46
46
 
47
47
  ```ruby
48
- require "matchi/helper"
49
-
50
- include Matchi::Helper
48
+ require "matchi"
51
49
  ```
52
50
 
53
51
  All examples here assume that this has been done.
54
52
 
55
53
  ### Absolute Requirement
56
54
 
57
- There's only one bat:
55
+ There is exactly one bat:
58
56
 
59
57
  ```ruby
60
- definition = Spectus.must equal 1
58
+ definition = Spectus.must Matchi::Be.new(1)
61
59
  definition.call { "🦇".size }
62
- # => Expresenter::Pass(actual: 1, error: nil, expected: 1, got: true, matcher: :equal, negate: false, level: :MUST
60
+ # => Expresenter::Pass(actual: 1, definition: "be 1", error: nil, expected: 1, got: true, negate: false, level: :MUST)
63
61
  ```
64
62
 
63
+ The test is passed.
64
+
65
65
  ### Absolute Prohibition
66
66
 
67
- The true from the false:
67
+ Truth and lies:
68
68
 
69
69
  ```ruby
70
- definition = Spectus.must_not be_true
70
+ definition = Spectus.must_not Matchi::Be.new(true)
71
71
  definition.call { false }
72
- # => Expresenter::Pass(actual: false, error: nil, expected: nil, got: true, matcher: :be_true, negate: true, level: :MUST
72
+ # => Expresenter::Pass(actual: false, definition: "be true", error: nil, expected: true, got: true, negate: true, level: :MUST)
73
73
  ```
74
74
 
75
75
  ### Recommended
76
76
 
77
- A well-known joke. An addition of `0.1` and `0.2` is deadly precise:
77
+ A well-known joke. The addition of `0.1` and `0.2` is deadly precise:
78
78
 
79
79
  ```ruby
80
- definition = Spectus.should equal 0.3
80
+ definition = Spectus.should Matchi::Be.new(0.3)
81
81
  definition.call { 0.1 + 0.2 }
82
- # => Expresenter::Pass(actual: 0.30000000000000004, error: nil, expected: 0.3, got: false, matcher: :equal, negate: false, level: :SHOULD
82
+ # => Expresenter::Pass(actual: 0.30000000000000004, definition: "be 0.3", error: nil, expected: 0.3, got: false, negate: false, level: :SHOULD)
83
83
  ```
84
84
 
85
85
  ### Not Recommended
86
86
 
87
- The situation should still be under control:
87
+ This should not be wrong:
88
88
 
89
89
  ```ruby
90
- definition = Spectus.should_not raise_exception SystemExit
91
- definition.call { BOOM }
92
- ```
90
+ definition = Spectus.should_not Matchi::Match.new("123456")
93
91
 
94
- ```txt
95
- Traceback (most recent call last):
96
- 6: from /Users/cyril/.rbenv/versions/2.7.3/bin/irb:23:in `<main>'
97
- 5: from /Users/cyril/.rbenv/versions/2.7.3/bin/irb:23:in `load'
98
- 4: from /Users/cyril/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
99
- 3: from (irb):11
100
- 2: from /Users/cyril/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/spectus-4.0.0/lib/spectus/requirement/base.rb:32:in `call'
101
- 1: from /Users/cyril/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/expresenter-1.3.0/lib/expresenter/fail.rb:25:in `with'
102
- Expresenter::Fail (NameError: uninitialized constant BOOM.)
92
+ definition.call do
93
+ require "securerandom"
94
+
95
+ SecureRandom.hex(3)
96
+ end
97
+ # => Expresenter::Pass(actual: "bb5716", definition: "match \"123456\"", error: nil, expected: "123456", got: true, negate: true, level: :SHOULD)
103
98
  ```
104
99
 
100
+ In any case, as long as there are no exceptions, the test passes.
101
+
105
102
  ### Optional
106
103
 
107
104
  An empty array is blank, right?
108
105
 
109
106
  ```ruby
110
- definition = Spectus.may be_true
107
+ definition = Spectus.may Matchi::Be.new(true)
111
108
  definition.call { [].blank? }
112
- # => Expresenter::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for []:Array>, expected: nil, got: nil, matcher: :be_true, negate: false, level: :MAY
109
+ # => Expresenter::Pass(actual: nil, definition: "be true", error: #<NoMethodError: undefined method `blank?' for []:Array>, expected: true, got: nil, negate: false, level: :MAY)
113
110
  ```
114
111
 
115
- Damn, I forgot to load activesupport. 🤦‍♂️
112
+ My bad! ActiveSupport was not imported. 🤦‍♂️
116
113
 
117
- That said, the test is passing due to the _not-implemented-like_ raised exception: `NoMethodError`.
114
+ Anyways, the test passes because the exception produced is `NoMethodError`, meaning that the functionality is not implemented.
118
115
 
119
116
  ## Code Isolation
120
117
 
@@ -129,9 +126,9 @@ Example of test without isolation:
129
126
  ```ruby
130
127
  greeting = "Hello, world!"
131
128
 
132
- definition = Spectus.must eql "Hello, Alice!"
129
+ definition = Spectus.must Matchi::Eq.new("Hello, Alice!")
133
130
  definition.call { greeting.gsub!("world", "Alice") }
134
- # => Expresenter::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST
131
+ # => Expresenter::Pass(actual: "Hello, Alice!", definition: "eq \"Hello, Alice!\"", error: nil, expected: "Hello, Alice!", got: true, negate: false, level: :MUST)
135
132
 
136
133
  greeting # => "Hello, Alice!"
137
134
  ```
@@ -141,9 +138,9 @@ Example of test in isolation:
141
138
  ```ruby
142
139
  greeting = "Hello, world!"
143
140
 
144
- definition = Spectus.must! eql "Hello, Alice!"
141
+ definition = Spectus.must! Matchi::Eq.new("Hello, Alice!")
145
142
  definition.call { greeting.gsub!("world", "Alice") }
146
- # => Expresenter::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST
143
+ # => Expresenter::Pass(actual: "Hello, Alice!", definition: "eq \"Hello, Alice!\"", error: nil, expected: "Hello, Alice!", got: true, negate: false, level: :MUST)
147
144
 
148
145
  greeting # => "Hello, world!"
149
146
  ```
data/lib/spectus.rb CHANGED
@@ -7,16 +7,15 @@ require_relative File.join("spectus", "requirement")
7
7
  # This module defines methods that can be used to qualify expectations in
8
8
  # specifications.
9
9
  module Spectus
10
- # This method mean that the definition is an absolute requirement of the specification.
10
+ # This method mean that the definition is an absolute requirement of the
11
+ # specification.
11
12
  #
12
13
  # @example An absolute requirement definition
13
14
  # require "spectus"
14
- # require "matchi/helper"
15
+ # require "matchi/eq"
15
16
  #
16
- # include Matchi::Helper
17
- #
18
- # Spectus.must eql "FOO"
19
- # # => #<MUST Matchi::Matcher::Eql("FOO") isolate=false negate=false>
17
+ # Spectus.must Matchi::Eq.new("FOO")
18
+ # # => #<MUST Matchi::Eq("FOO") isolate=false negate=false>
20
19
  #
21
20
  # @param matcher [#matches?] The matcher.
22
21
  #
@@ -33,12 +32,10 @@ module Spectus
33
32
 
34
33
  # @example An absolute requirement definition with isolation
35
34
  # require "spectus"
36
- # require "matchi/helper"
37
- #
38
- # include Matchi::Helper
35
+ # require "matchi/eq"
39
36
  #
40
- # Spectus.must! eql "FOO"
41
- # # => #<MUST Matchi::Matcher::Eql("FOO") isolate=true negate=false>
37
+ # Spectus.must! Matchi::Eq.new("FOO")
38
+ # # => #<MUST Matchi::Eq("FOO") isolate=true negate=false>
42
39
  #
43
40
  # @see must
44
41
  def self.must!(matcher)
@@ -53,12 +50,10 @@ module Spectus
53
50
  #
54
51
  # @example An absolute prohibition definition
55
52
  # require "spectus"
56
- # require "matchi/helper"
57
- #
58
- # include Matchi::Helper
53
+ # require "matchi/be"
59
54
  #
60
- # Spectus.must_not equal 42
61
- # # => #<MUST Matchi::Matcher::Equal(42) isolate=false negate=true>
55
+ # Spectus.must_not Matchi::Be.new(42)
56
+ # # => #<MUST Matchi::Be(42) isolate=false negate=true>
62
57
  #
63
58
  # @param matcher [#matches?] The matcher.
64
59
  #
@@ -73,12 +68,10 @@ module Spectus
73
68
 
74
69
  # @example An absolute prohibition definition with isolation
75
70
  # require "spectus"
76
- # require "matchi/helper"
71
+ # require "matchi/be"
77
72
  #
78
- # include Matchi::Helper
79
- #
80
- # Spectus.must_not! equal 42
81
- # # => #<MUST Matchi::Matcher::Equal(42) isolate=true negate=true>
73
+ # Spectus.must_not! Matchi::Be.new(42)
74
+ # # => #<MUST Matchi::Be(42) isolate=true negate=true>
82
75
  #
83
76
  # @see must_not
84
77
  def self.must_not!(matcher)
@@ -95,12 +88,10 @@ module Spectus
95
88
  #
96
89
  # @example A recommended definition
97
90
  # require "spectus"
98
- # require "matchi/helper"
99
- #
100
- # include Matchi::Helper
91
+ # require "matchi/be"
101
92
  #
102
- # Spectus.should equal true
103
- # # => #<SHOULD Matchi::Matcher::Equal(true) isolate=false negate=false>
93
+ # Spectus.should Matchi::Be.new(true)
94
+ # # => #<SHOULD Matchi::Be(true) isolate=false negate=false>
104
95
  #
105
96
  # @param matcher [#matches?] The matcher.
106
97
  #
@@ -115,12 +106,10 @@ module Spectus
115
106
 
116
107
  # @example A recommended definition with isolation
117
108
  # require "spectus"
118
- # require "matchi/helper"
109
+ # require "matchi/be"
119
110
  #
120
- # include Matchi::Helper
121
- #
122
- # Spectus.should! equal true
123
- # # => #<SHOULD Matchi::Matcher::Equal(true) isolate=true negate=false>
111
+ # Spectus.should! Matchi::Be.new(true)
112
+ # # => #<SHOULD Matchi::Be(true) isolate=true negate=false>
124
113
  #
125
114
  # @see should
126
115
  def self.should!(matcher)
@@ -138,12 +127,10 @@ module Spectus
138
127
  #
139
128
  # @example A not recommended definition
140
129
  # require "spectus"
141
- # require "matchi/helper"
142
- #
143
- # include Matchi::Helper
130
+ # require "matchi/raise_exception"
144
131
  #
145
- # Spectus.should_not raise_exception NoMethodError
146
- # # => #<SHOULD Matchi::Matcher::RaiseException(NoMethodError) isolate=false negate=true>
132
+ # Spectus.should_not Matchi::RaiseException.new(NoMethodError)
133
+ # # => #<SHOULD Matchi::RaiseException(NoMethodError) isolate=false negate=true>
147
134
  #
148
135
  # @param matcher [#matches?] The matcher.
149
136
  #
@@ -159,12 +146,10 @@ module Spectus
159
146
 
160
147
  # @example A not recommended definition with isolation
161
148
  # require "spectus"
162
- # require "matchi/helper"
163
- #
164
- # include Matchi::Helper
149
+ # require "matchi/raise_exception"
165
150
  #
166
- # Spectus.should_not! raise_exception NoMethodError
167
- # # => #<SHOULD Matchi::Matcher::RaiseException(NoMethodError) isolate=true negate=true>
151
+ # Spectus.should_not! Matchi::RaiseException.new(NoMethodError)
152
+ # # => #<SHOULD Matchi::RaiseException(NoMethodError) isolate=true negate=true>
168
153
  #
169
154
  # @see should_not
170
155
  def self.should_not!(matcher)
@@ -188,12 +173,10 @@ module Spectus
188
173
  #
189
174
  # @example An optional definition
190
175
  # require "spectus"
191
- # require "matchi/helper"
176
+ # require "matchi/match"
192
177
  #
193
- # include Matchi::Helper
194
- #
195
- # Spectus.may match /^foo$/
196
- # # => #<MAY Matchi::Matcher::Match(/^foo$/) isolate=false negate=false>
178
+ # Spectus.may Matchi::Match.new(/^foo$/)
179
+ # # => #<MAY Matchi::Match(/^foo$/) isolate=false negate=false>
197
180
  #
198
181
  # @param matcher [#matches?] The matcher.
199
182
  #
@@ -208,12 +191,10 @@ module Spectus
208
191
 
209
192
  # @example An optional definition with isolation
210
193
  # require "spectus"
211
- # require "matchi/helper"
212
- #
213
- # include Matchi::Helper
194
+ # require "matchi/match"
214
195
  #
215
- # Spectus.may! match /^foo$/
216
- # # => #<MAY Matchi::Matcher::Match(/^foo$/) isolate=true negate=false>
196
+ # Spectus.may! Matchi::Match.new(/^foo$/)
197
+ # # => #<MAY Matchi::Match(/^foo$/) isolate=true negate=false>
217
198
  #
218
199
  # @see may
219
200
  def self.may!(matcher)
@@ -31,13 +31,13 @@ module Spectus
31
31
  test = ::TestTube.invoke(isolate: @isolate, matcher: @matcher, negate: @negate, &block)
32
32
 
33
33
  ::Expresenter.call(passed?(test)).with(
34
- actual: test.actual,
35
- error: test.error,
36
- expected: @matcher.expected,
37
- got: test.got,
38
- level: self.class.level,
39
- matcher: @matcher.class.to_sym,
40
- negate: @negate
34
+ actual: test.actual,
35
+ definition: @matcher.to_s,
36
+ error: test.error,
37
+ expected: @matcher.expected,
38
+ got: test.got,
39
+ level: self.class.level,
40
+ negate: @negate
41
41
  )
42
42
  end
43
43
 
@@ -47,13 +47,11 @@ module Spectus
47
47
  #
48
48
  # @example The human-readable representation of an absolute requirement.
49
49
  # require "spectus"
50
- # require "matchi/helper"
50
+ # require "matchi/be"
51
51
  #
52
- # include Matchi::Helper
53
- #
54
- # definition = Spectus.must equal 1
52
+ # definition = Spectus.must Matchi::Be.new(1)
55
53
  # definition.inspect
56
- # # => #<MUST Matchi::Matcher::Equal(1) isolate=false negate=false>
54
+ # # => "#<MUST Matchi::Be(1) isolate=false negate=false>"
57
55
  #
58
56
  # @return [String] The human-readable representation of the definition.
59
57
  #
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: 4.0.1
4
+ version: 4.0.2
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-07-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: expresenter
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 1.4.0
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: 1.3.0
26
+ version: 1.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test_tube
29
29
  requirement: !ruby/object:Gem::Requirement