spectus 4.0.3 → 5.0.1

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: 3d2dc0863871f3794105ca9de38893d86ca937fe09bc8f90772d22f23551db79
4
- data.tar.gz: efda8aae27fb68317b3d450ede09c13e22c7d5c8e638ba8c8fd8169ce5b93f03
3
+ metadata.gz: 11f7d2775c0de9fcba11f795927752e4f15aa1de85b63e2d5bd806b82c434bca
4
+ data.tar.gz: ebf62bbee1e7d30003995918b368f0905ee2305a3fb79a242f940837d94c793b
5
5
  SHA512:
6
- metadata.gz: 07e371fdb35d33e5451ca8188be95e153d08e58b0e32791081ecfed6d42a7eb16917ed711cff89bcaca7e27b2b10a59ba6676e1896e7f6cd15eb255861c1f2d4
7
- data.tar.gz: 777d8c69e1beede896cd074c3c839707497a6775fe2e4263f309d66128a25b914beeee4ae822fa43c58d0b6279215c0f8a39ffe08b595ced35cdf02714e15a4e
6
+ metadata.gz: 978d85aa4e676d8edea4c94644976a06284820b912602cb98808d1a39cf3ef3e2538bee688da3d7401593710de86b03f4b28b05cc0e6555c45741ca0782c78ad
7
+ data.tar.gz: 9c51ec6b30adb0590bdd514c5c6c74474508ab146a72dbd7ebddc375a6dedc765a7201e18022514cc5634c5f4fb377d064acac2ae0a8832f491437a614fbd83c
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2021 Cyril Kato
3
+ Copyright (c) 2014-2024 Cyril Kato
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Spectus
2
2
 
3
- [![Version](https://img.shields.io/github/v/tag/fixrb/spectus?label=Version&logo=github)](https://github.com/fixrb/spectus/releases)
3
+ [![Version](https://img.shields.io/github/v/tag/fixrb/spectus?label=Version&logo=github)](https://github.com/fixrb/spectus/tags)
4
4
  [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/spectus/main)
5
- [![CI](https://github.com/fixrb/spectus/workflows/CI/badge.svg?branch=main)](https://github.com/fixrb/spectus/actions?query=workflow%3Aci+branch%3Amain)
5
+ [![Ruby](https://github.com/fixrb/spectus/workflows/Ruby/badge.svg?branch=main)](https://github.com/fixrb/spectus/actions?query=workflow%3Aruby+branch%3Amain)
6
6
  [![RuboCop](https://github.com/fixrb/spectus/workflows/RuboCop/badge.svg?branch=main)](https://github.com/fixrb/spectus/actions?query=workflow%3Arubocop+branch%3Amain)
7
7
  [![License](https://img.shields.io/github/license/fixrb/spectus?label=License&logo=github)](https://github.com/fixrb/spectus/raw/main/LICENSE.md)
8
8
 
9
- > Expectation library with [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) requirement levels 🚥
9
+ > A Ruby library for defining expectations with precision, using [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) compliance levels. 🚥
10
10
 
11
11
  ## Installation
12
12
 
@@ -19,7 +19,7 @@ gem "spectus"
19
19
  And then execute:
20
20
 
21
21
  ```sh
22
- bundle
22
+ bundle install
23
23
  ```
24
24
 
25
25
  Or install it yourself as:
@@ -40,10 +40,6 @@ require "spectus"
40
40
 
41
41
  For convenience, we will also instantiate some matchers from the [Matchi library](https://github.com/fixrb/matchi):
42
42
 
43
- ```sh
44
- gem install matchi
45
- ```
46
-
47
43
  ```ruby
48
44
  require "matchi"
49
45
  ```
@@ -113,43 +109,11 @@ My bad! ActiveSupport was not imported. 🤦‍♂️
113
109
 
114
110
  Anyways, the test passes because the exception produced is `NoMethodError`, meaning that the functionality is not implemented.
115
111
 
116
- ## Code Isolation
117
-
118
- When executing expectations, side-effects may occur.
119
- Because they may or may not be desired, each requirement level has 2 versions:
120
-
121
- * if it does not end with `!`, its test is performed without isolation;
122
- * if it ends with `!`, its test is performed in isolation.
123
-
124
- Example of test without isolation:
125
-
126
- ```ruby
127
- greeting = "Hello, world!"
128
-
129
- definition = Spectus.must Matchi::Eq.new("Hello, Alice!")
130
- definition.call { greeting.gsub!("world", "Alice") }
131
- # => Expresenter::Pass(actual: "Hello, Alice!", definition: "eq \"Hello, Alice!\"", error: nil, expected: "Hello, Alice!", got: true, negate: false, level: :MUST)
132
-
133
- greeting # => "Hello, Alice!"
134
- ```
135
-
136
- Example of test in isolation:
137
-
138
- ```ruby
139
- greeting = "Hello, world!"
140
-
141
- definition = Spectus.must! Matchi::Eq.new("Hello, Alice!")
142
- definition.call { greeting.gsub!("world", "Alice") }
143
- # => Expresenter::Pass(actual: "Hello, Alice!", definition: "eq \"Hello, Alice!\"", error: nil, expected: "Hello, Alice!", got: true, negate: false, level: :MUST)
144
-
145
- greeting # => "Hello, world!"
146
- ```
147
-
148
112
  ## Contact
149
113
 
150
114
  * Home page: https://github.com/fixrb/spectus
151
115
  * Bugs/issues: https://github.com/fixrb/spectus/issues
152
- * Blog post: https://batman.buzz/a-spectus-tutorial-expectations-with-rfc-2119-compliance-1fc769861c1
116
+ * Blog post: https://cyrilllllll.medium.com/a-spectus-tutorial-expectations-with-rfc-2119-compliance-1fc769861c1
153
117
 
154
118
  ## Versioning
155
119
 
@@ -159,11 +123,6 @@ __Spectus__ follows [Semantic Versioning 2.0](https://semver.org/).
159
123
 
160
124
  The [gem](https://rubygems.org/gems/spectus) is available as open source under the terms of the [MIT License](https://github.com/fixrb/spectus/raw/main/LICENSE.md).
161
125
 
162
- ***
126
+ ## Sponsors
163
127
 
164
- <p>
165
- This project is sponsored by:<br />
166
- <a href="https://sashite.com/"><img
167
- src="https://github.com/fixrb/spectus/raw/main/img/sashite.png"
168
- alt="Sashite" /></a>
169
- </p>
128
+ This project is sponsored by [Sashité](https://sashite.com/)
@@ -10,11 +10,9 @@ module Spectus
10
10
  class Base
11
11
  # Initialize the requirement level class.
12
12
  #
13
- # @param isolate [Boolean] Compute actual in a subprocess.
14
- # @param matcher [#matches?] The matcher.
13
+ # @param matcher [#match?] The matcher.
15
14
  # @param negate [Boolean] Invert the matcher or not.
16
- def initialize(isolate:, matcher:, negate:)
17
- @isolate = isolate
15
+ def initialize(matcher:, negate:)
18
16
  @matcher = matcher
19
17
  @negate = negate
20
18
  end
@@ -27,14 +25,13 @@ module Spectus
27
25
  # @see https://github.com/fixrb/expresenter
28
26
  #
29
27
  # @api public
30
- def call(&block)
31
- test = ::TestTube.invoke(isolate: @isolate, matcher: @matcher, negate: @negate, &block)
28
+ def call(&)
29
+ test = ::TestTube.invoke(matcher: @matcher, negate: @negate, &)
32
30
 
33
31
  ::Expresenter.call(passed?(test)).with(
34
32
  actual: test.actual,
35
33
  definition: @matcher.to_s,
36
34
  error: test.error,
37
- expected: @matcher.expected,
38
35
  got: test.got,
39
36
  level: self.class.level,
40
37
  negate: @negate
@@ -51,13 +48,13 @@ module Spectus
51
48
  #
52
49
  # definition = Spectus.must Matchi::Be.new(1)
53
50
  # definition.inspect
54
- # # => "#<MUST Matchi::Be(1) isolate=false negate=false>"
51
+ # # => "#<MUST Matchi::Be(1) negate=false>"
55
52
  #
56
53
  # @return [String] The human-readable representation of the definition.
57
54
  #
58
55
  # @api public
59
56
  def inspect
60
- "#<#{self.class.level} #{@matcher.inspect} isolate=#{@isolate} negate=#{@negate}>"
57
+ "#<#{self.class.level} #{@matcher.inspect} negate=#{@negate}>"
61
58
  end
62
59
 
63
60
  # :nocov:
data/lib/spectus.rb CHANGED
@@ -15,35 +15,15 @@ module Spectus
15
15
  # require "matchi/eq"
16
16
  #
17
17
  # Spectus.must Matchi::Eq.new("FOO")
18
- # # => #<MUST Matchi::Eq("FOO") isolate=false negate=false>
18
+ # # => #<MUST Matchi::Eq("FOO") negate=false>
19
19
  #
20
- # @param matcher [#matches?] The matcher.
20
+ # @param matcher [#match?] The matcher.
21
21
  #
22
22
  # @return [Requirement::Required] An absolute requirement level instance.
23
23
  #
24
24
  # @api public
25
25
  def self.must(matcher)
26
- Requirement::Required.new(
27
- isolate: false,
28
- negate: false,
29
- matcher: matcher
30
- )
31
- end
32
-
33
- # @example An absolute requirement definition with isolation
34
- # require "spectus"
35
- # require "matchi/eq"
36
- #
37
- # Spectus.must! Matchi::Eq.new("FOO")
38
- # # => #<MUST Matchi::Eq("FOO") isolate=true negate=false>
39
- #
40
- # @see must
41
- def self.must!(matcher)
42
- Requirement::Required.new(
43
- isolate: true,
44
- negate: false,
45
- matcher: matcher
46
- )
26
+ Requirement::Required.new(negate: false, matcher:)
47
27
  end
48
28
 
49
29
  # This method mean that the definition is an absolute prohibition of the specification.
@@ -53,33 +33,13 @@ module Spectus
53
33
  # require "matchi/be"
54
34
  #
55
35
  # Spectus.must_not Matchi::Be.new(42)
56
- # # => #<MUST Matchi::Be(42) isolate=false negate=true>
36
+ # # => #<MUST Matchi::Be(42) negate=true>
57
37
  #
58
- # @param matcher [#matches?] The matcher.
38
+ # @param matcher [#match?] The matcher.
59
39
  #
60
40
  # @return [Requirement::Required] An absolute prohibition level instance.
61
41
  def self.must_not(matcher)
62
- Requirement::Required.new(
63
- isolate: false,
64
- negate: true,
65
- matcher: matcher
66
- )
67
- end
68
-
69
- # @example An absolute prohibition definition with isolation
70
- # require "spectus"
71
- # require "matchi/be"
72
- #
73
- # Spectus.must_not! Matchi::Be.new(42)
74
- # # => #<MUST Matchi::Be(42) isolate=true negate=true>
75
- #
76
- # @see must_not
77
- def self.must_not!(matcher)
78
- Requirement::Required.new(
79
- isolate: true,
80
- negate: true,
81
- matcher: matcher
82
- )
42
+ Requirement::Required.new(negate: true, matcher:)
83
43
  end
84
44
 
85
45
  # This method mean that there may exist valid reasons in particular
@@ -91,33 +51,13 @@ module Spectus
91
51
  # require "matchi/be"
92
52
  #
93
53
  # Spectus.should Matchi::Be.new(true)
94
- # # => #<SHOULD Matchi::Be(true) isolate=false negate=false>
54
+ # # => #<SHOULD Matchi::Be(true) negate=false>
95
55
  #
96
- # @param matcher [#matches?] The matcher.
56
+ # @param matcher [#match?] The matcher.
97
57
  #
98
58
  # @return [Requirement::Recommended] A recommended requirement level instance.
99
59
  def self.should(matcher)
100
- Requirement::Recommended.new(
101
- isolate: false,
102
- negate: false,
103
- matcher: matcher
104
- )
105
- end
106
-
107
- # @example A recommended definition with isolation
108
- # require "spectus"
109
- # require "matchi/be"
110
- #
111
- # Spectus.should! Matchi::Be.new(true)
112
- # # => #<SHOULD Matchi::Be(true) isolate=true negate=false>
113
- #
114
- # @see should
115
- def self.should!(matcher)
116
- Requirement::Recommended.new(
117
- isolate: true,
118
- negate: false,
119
- matcher: matcher
120
- )
60
+ Requirement::Recommended.new(negate: false, matcher:)
121
61
  end
122
62
 
123
63
  # This method mean that there may exist valid reasons in particular
@@ -130,34 +70,14 @@ module Spectus
130
70
  # require "matchi/raise_exception"
131
71
  #
132
72
  # Spectus.should_not Matchi::RaiseException.new(NoMethodError)
133
- # # => #<SHOULD Matchi::RaiseException(NoMethodError) isolate=false negate=true>
73
+ # # => #<SHOULD Matchi::RaiseException(NoMethodError) negate=true>
134
74
  #
135
- # @param matcher [#matches?] The matcher.
75
+ # @param matcher [#match?] The matcher.
136
76
  #
137
77
  # @return [Requirement::Recommended] A not recommended requirement level
138
78
  # instance.
139
79
  def self.should_not(matcher)
140
- Requirement::Recommended.new(
141
- isolate: false,
142
- negate: true,
143
- matcher: matcher
144
- )
145
- end
146
-
147
- # @example A not recommended definition with isolation
148
- # require "spectus"
149
- # require "matchi/raise_exception"
150
- #
151
- # Spectus.should_not! Matchi::RaiseException.new(NoMethodError)
152
- # # => #<SHOULD Matchi::RaiseException(NoMethodError) isolate=true negate=true>
153
- #
154
- # @see should_not
155
- def self.should_not!(matcher)
156
- Requirement::Recommended.new(
157
- isolate: true,
158
- negate: true,
159
- matcher: matcher
160
- )
80
+ Requirement::Recommended.new(negate: true, matcher:)
161
81
  end
162
82
 
163
83
  # This method mean that an item is truly optional.
@@ -176,32 +96,12 @@ module Spectus
176
96
  # require "matchi/match"
177
97
  #
178
98
  # Spectus.may Matchi::Match.new(/^foo$/)
179
- # # => #<MAY Matchi::Match(/^foo$/) isolate=false negate=false>
99
+ # # => #<MAY Matchi::Match(/^foo$/) negate=false>
180
100
  #
181
- # @param matcher [#matches?] The matcher.
101
+ # @param matcher [#match?] The matcher.
182
102
  #
183
103
  # @return [Requirement::Optional] An optional requirement level instance.
184
104
  def self.may(matcher)
185
- Requirement::Optional.new(
186
- isolate: false,
187
- negate: false,
188
- matcher: matcher
189
- )
190
- end
191
-
192
- # @example An optional definition with isolation
193
- # require "spectus"
194
- # require "matchi/match"
195
- #
196
- # Spectus.may! Matchi::Match.new(/^foo$/)
197
- # # => #<MAY Matchi::Match(/^foo$/) isolate=true negate=false>
198
- #
199
- # @see may
200
- def self.may!(matcher)
201
- Requirement::Optional.new(
202
- isolate: true,
203
- negate: false,
204
- matcher: matcher
205
- )
105
+ Requirement::Optional.new(negate: false, matcher:)
206
106
  end
207
107
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectus
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-07-31 00:00:00.000000000 Z
10
+ date: 2024-12-30 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: expresenter
@@ -16,168 +15,42 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 1.4.0
18
+ version: 1.5.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 1.4.0
25
+ version: 1.5.0
27
26
  - !ruby/object:Gem::Dependency
28
- name: test_tube
27
+ name: matchi
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: 2.1.1
32
+ version: '4.0'
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: 2.1.1
41
- - !ruby/object:Gem::Dependency
42
- name: brutal
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: bundler
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: matchi
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: 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'
39
+ version: '4.0'
97
40
  - !ruby/object:Gem::Dependency
98
- name: rubocop-md
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: rubocop-performance
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: rubocop-rake
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'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop-thread_safety
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: simplecov
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: yard
41
+ name: test_tube
169
42
  requirement: !ruby/object:Gem::Requirement
170
43
  requirements:
171
- - - ">="
44
+ - - "~>"
172
45
  - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
46
+ version: 4.0.0
47
+ type: :runtime
175
48
  prerelease: false
176
49
  version_requirements: !ruby/object:Gem::Requirement
177
50
  requirements:
178
- - - ">="
51
+ - - "~>"
179
52
  - !ruby/object:Gem::Version
180
- version: '0'
53
+ version: 4.0.0
181
54
  description: "Expectation library with RFC 2119's requirement levels \U0001F6A5"
182
55
  email: contact@cyril.email
183
56
  executables: []
@@ -195,8 +68,8 @@ files:
195
68
  homepage: https://github.com/fixrb/spectus
196
69
  licenses:
197
70
  - MIT
198
- metadata: {}
199
- post_install_message:
71
+ metadata:
72
+ rubygems_mfa_required: 'true'
200
73
  rdoc_options: []
201
74
  require_paths:
202
75
  - lib
@@ -204,15 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
77
  requirements:
205
78
  - - ">="
206
79
  - !ruby/object:Gem::Version
207
- version: 2.7.0
80
+ version: 3.2.0
208
81
  required_rubygems_version: !ruby/object:Gem::Requirement
209
82
  requirements:
210
83
  - - ">="
211
84
  - !ruby/object:Gem::Version
212
85
  version: '0'
213
86
  requirements: []
214
- rubygems_version: 3.1.6
215
- signing_key:
87
+ rubygems_version: 3.6.2
216
88
  specification_version: 4
217
89
  summary: "Expectation library with RFC 2119's requirement levels \U0001F6A5"
218
90
  test_files: []