spectus 3.3.0 → 3.4.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: 91207456a98d2640cdeb0dbf52ce04c532f72060c904aa15474f2eb86eb67481
4
- data.tar.gz: 26e7073807fa4bb734eb8e349682c41d2b23bd83c11012818ce443b5615089e3
3
+ metadata.gz: 2fea4a88991addc0a6b69ce46d6422e92df818447818975d6123848cbba9d5a7
4
+ data.tar.gz: 8dffb97e6e58cdf0c3e5661294238e42f5477f4e677a34868ce918156086cbdb
5
5
  SHA512:
6
- metadata.gz: '018827c15c82d74b1af062e57768809c89f6ad18e2b389b4150ae318f12fdbadd6709eff232483d67a7e9aa0234d008ade347503066b78c522f7291fa515f809'
7
- data.tar.gz: a57c6cfaf4b7292ca768fc309e61a025d85de984cf62af8f0a88c0b37d58189732babf03e3a8a6eed208838518af088d1d53448cc5c6c71842db1e52f0c60ab7
6
+ metadata.gz: 9a4798a255dcf0097dcba1bac46af91552a11348513c0d4af77a00a748cb950e90b113c264404cc745af3c7dc730154ad81893d879a495450f6cda5ca4b07942
7
+ data.tar.gz: ba56345d554c0483ce27fd6c7d876e7837d59a53a37a9b9e6417df849e0a6047b522a2c00e7f5d4327a76c1ed3e60cea68cff5970e7dcc4718d31ed89e3e6fa4
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # Spectus
2
2
 
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
- [![Gem Version](https://badge.fury.io/rb/spectus.svg)][gem]
6
- [![Inline docs](https://inch-ci.org/github/fixrb/spectus.svg?branch=main)][inchpages]
7
- [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
3
+ [![Build Status](https://api.travis-ci.org/fixrb/spectus.svg?branch=main)](https://travis-ci.org/fixrb/spectus)
4
+ [![Gem Version](https://badge.fury.io/rb/spectus.svg)](https://rubygems.org/gems/spectus)
5
+ [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)](https://rubydoc.info/gems/spectus/frames)
8
6
 
9
- > Expectation library with [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt)'s requirement levels 🚥
7
+ > Expectation library with [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) requirement levels 🚥
10
8
 
11
9
  ## Installation
12
10
 
@@ -18,80 +16,161 @@ gem "spectus"
18
16
 
19
17
  And then execute:
20
18
 
21
- $ bundle
19
+ ```sh
20
+ bundle
21
+ ```
22
22
 
23
23
  Or install it yourself as:
24
24
 
25
- $ gem install spectus
25
+ ```sh
26
+ gem install spectus
27
+ ```
28
+
29
+ ## Overview
30
+
31
+ Assuming that an expectation is an assertion that is either `true` or `false`,
32
+ qualifying it with `MUST`, `SHOULD` and `MAY`, we can draw up several scenarios:
33
+
34
+ | Requirement levels | **MUST** | **SHOULD** | **MAY** |
35
+ | ------------------------- | -------- | ---------- | ------- |
36
+ | Implemented & Matched | `true` | `true` | `true` |
37
+ | Implemented & Not matched | `false` | `true` | `false` |
38
+ | Implemented & Exception | `false` | `false` | `false` |
39
+ | Not implemented | `false` | `false` | `true` |
40
+
41
+ When an expectation is evaluated by __Spectus__,
42
+
43
+ * in case of a _passed_ expectation, a `Spectus::Result::Pass` instance is _returned_;
44
+ * in case of a _failed_ expectation, a `Spectus::Result::Fail` exception is _raised_.
26
45
 
27
46
  ## Usage
28
47
 
29
- To begin with, let's include __Spectus__:
48
+ The __Spectus__ library is basically a module containing an `it` instance method that accept a block representing the actual value to be evaluated through an expectation.
49
+
50
+ The `Spectus` module can be included inside a class and used as follows:
51
+
52
+ ```ruby
53
+ require "spectus"
54
+
55
+ class Spec
56
+ include ::Spectus
57
+
58
+ attr_reader :subject
59
+
60
+ def initialize(subject)
61
+ @subject = subject
62
+ end
63
+
64
+ def test_a
65
+ it { subject.upcase }.MUST eql "FOO"
66
+ end
67
+
68
+ def test_b
69
+ it { subject.blank? }.MAY be_true
70
+ end
71
+
72
+ def test_c
73
+ it { subject.length }.SHOULD equal 42
74
+ end
75
+ end
76
+ ```
77
+
78
+ ```ruby
79
+ t = Spec.new("foo")
80
+
81
+ t.test_a # => Spectus::Result::Pass(actual: "FOO", error: nil, expected: "FOO", got: true, matcher: :eql, negate: false, level: :MUST)
82
+
83
+ t.test_b # => Spectus::Result::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for "foo":String>, expected: nil, got: nil, matcher: :be_true, negate: false, level: :MAY)
84
+
85
+ t.test_c # => Spectus::Result::Pass(actual: 3, error: nil, expected: 42, got: false, matcher: :equal, negate: false, level: :SHOULD)
86
+ ```
30
87
 
31
88
  ```ruby
89
+ t = Spec.new(4)
90
+
91
+ t.test_a # => raises an exception:
92
+ # Traceback (most recent call last):
93
+ # 3: from ./bin/console:8:in `<main>'
94
+ # 2: from (irb):23
95
+ # 1: from (irb):11:in `test_a'
96
+ # Spectus::Result::Fail (NoMethodError: undefined method `upcase' for 4:Integer)
97
+
98
+ t.test_b # => Spectus::Result::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for 4:Integer>, expected: nil, got: nil, matcher: :be_true, negate: false, level: :MAY)
99
+
100
+ t.test_c # => raises an exception:
101
+ # Traceback (most recent call last):
102
+ # 3: from ./bin/console:8:in `<main>'
103
+ # 2: from (irb):25
104
+ # 1: from (irb):19:in `test_c'
105
+ # Spectus::Result::Fail (NoMethodError: undefined method `length' for 4:Integer.)
106
+ ```
107
+
108
+ ## More examples
109
+
110
+ To make __Spectus__ available:
111
+
112
+ ```ruby
113
+ require "spectus"
114
+
32
115
  include Spectus
33
116
  ```
34
117
 
118
+ All examples here assume that this has been done.
119
+
35
120
  ### Absolute Requirement
36
121
 
37
- Given the "`ルビー`" object, when it receives `valid_encoding?` method, then it **MUST** be `true`:
122
+ There's only one bat:
38
123
 
39
124
  ```ruby
40
- it { "ルビー".valid_encoding? }.MUST be_true
41
- # => Spectus::Result::Pass(actual: true, error: nil, expected: nil, got: true, matcher: :be_true, negate: false, level: :MUST, valid: true)
125
+ it { "🦇".size }.MUST equal 1
126
+ # => Spectus::Result::Pass(actual: 1, error: nil, expected: 1, got: true, matcher: :equal, negate: false, level: :MUST)
42
127
  ```
43
128
 
44
- The result of the test shows that the spec passed.
45
-
46
129
  ### Absolute Prohibition
47
130
 
48
- Given the "`foo`" object, when it receives `length` method, then it **MUST NOT** raise the `NoMethodError` exception:
131
+ The true from the false:
49
132
 
50
133
  ```ruby
51
- it { "foo".length }.MUST_NOT raise_exception NoMethodError
52
- # => Spectus::Result::Pass(actual: 3, error: nil, expected: NoMethodError, got: true, matcher: :raise_exception, negate: true, level: :MUST, valid: true)
134
+ it { false }.MUST_NOT be_true
135
+ # => Spectus::Result::Pass(actual: false, error: nil, expected: nil, got: true, matcher: :be_true, negate: true, level: :MUST)
53
136
  ```
54
137
 
55
- The result of the test shows that the spec passed.
56
-
57
138
  ### Recommended
58
139
 
59
- Given the `BasicObject` object, when it receives `superclass` method, then it **SHOULD** return the explicit blank class `NilClass`:
140
+ A well-known joke. An addition of `0.1` and `0.2` is deadly precise:
60
141
 
61
142
  ```ruby
62
- it { BasicObject.superclass }.SHOULD equal NilClass
63
- # => Spectus::Result::Pass(actual: nil, error: nil, expected: NilClass, got: false, matcher: :equal, negate: false, level: :SHOULD, valid: false)
143
+ it { 0.1 + 0.2 }.SHOULD equal 0.3
144
+ # => Spectus::Result::Pass(actual: 0.30000000000000004, error: nil, expected: 0.3, got: false, matcher: :equal, negate: false, level: :SHOULD)
64
145
  ```
65
146
 
66
- Instead of the expected `NilClass` class, its sole instance (which is `nil`) was returned.
67
- However, because there isn't any exception, the result of the test shows that the spec passed.
68
-
69
147
  ### Not Recommended
70
148
 
71
- Given the "`1`" object, when it receives `+(1)` method, then it **SHOULD NOT** return the "`11`" value:
149
+ The situation should still be under control:
72
150
 
73
151
  ```ruby
74
- it { "1" + 1 }.SHOULD_NOT eql "11"
75
- # raise Spectus::Result::Fail(actual: nil, error: #<TypeError: no implicit conversion of Integer into String>, expected: "11", got: nil, matcher: :eql, negate: true, level: :SHOULD, valid: false)
152
+ it { BOOM }.SHOULD_NOT raise_exception SystemExit
76
153
  ```
77
154
 
78
- There was a `TypeError` exception, the result of the test shows that the spec failed.
155
+ ```txt
156
+ Traceback (most recent call last):
157
+ 2: from ./bin/console:8:in `<main>'
158
+ 1: from (irb):8
159
+ Spectus::Result::Fail (NameError: uninitialized constant BOOM.)
160
+ ```
79
161
 
80
162
  ### Optional
81
163
 
82
- Given the "`foo`" object, when it receives `blank?` method, then it **MAY** be `false`:
164
+ An empty array is blank, right?
83
165
 
84
166
  ```ruby
85
- it { "foo".blank? }.MAY be_false
86
- # => Spectus::Result::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for "foo":String>, expected: nil, got: nil, matcher: :be_false, negate: false, level: :MAY, valid: false)
167
+ it { [].blank? }.MAY be_true
168
+ # => Spectus::Result::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for []:Array>, expected: nil, got: nil, matcher: :be_true, negate: false, level: :MAY)
87
169
  ```
88
170
 
89
- The optional `blank?` method is not implemented (unlike in [Ruby on Rails](https://api.rubyonrails.org/classes/Object.html#method-i-blank-3F), for instance), so the result of the test shows that the spec passed.
90
-
91
- ### More Examples
171
+ Damn, I forgot to load activesupport. 🤦‍♂️
92
172
 
93
- A full list of unit tests can be viewed (and executed) here:
94
- [./test.rb](https://github.com/fixrb/spectus/blob/main/test.rb)
173
+ That said, the test is passing due to the _not-implemented-like_ raised exception: `NoMethodError`.
95
174
 
96
175
  ## Code Isolation
97
176
 
@@ -104,20 +183,22 @@ Because they may or may not be desired, each requirement level has 2 versions:
104
183
  Example of test without isolation:
105
184
 
106
185
  ```ruby
107
- include Spectus
108
186
  greeting = "Hello, world!"
187
+
109
188
  it { greeting.gsub!("world", "Alice") }.MUST eql "Hello, Alice!"
110
- # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
189
+ # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST)
190
+
111
191
  greeting # => "Hello, Alice!"
112
192
  ```
113
193
 
114
194
  Example of test in isolation:
115
195
 
116
196
  ```ruby
117
- include Spectus
118
197
  greeting = "Hello, world!"
198
+
119
199
  it { greeting.gsub!("world", "Alice") }.MUST! eql "Hello, Alice!"
120
- # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST, valid: true)
200
+ # => Spectus::Result::Pass(actual: "Hello, Alice!", error: nil, expected: "Hello, Alice!", got: true, matcher: :eql, negate: false, level: :MUST)
201
+
121
202
  greeting # => "Hello, world!"
122
203
  ```
123
204
 
@@ -132,7 +213,7 @@ __Spectus__ follows [Semantic Versioning 2.0](https://semver.org/).
132
213
 
133
214
  ## License
134
215
 
135
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
216
+ The [gem](https://rubygems.org/gems/spectus) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
217
 
137
218
  ***
138
219
 
@@ -142,9 +223,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
142
223
  src="https://github.com/fixrb/spectus/raw/main/img/sashite.png"
143
224
  alt="Sashite" /></a>
144
225
  </p>
145
-
146
- [gem]: https://rubygems.org/gems/spectus
147
- [travis]: https://travis-ci.org/fixrb/spectus
148
- [codeclimate]: https://codeclimate.com/github/fixrb/spectus
149
- [inchpages]: https://inch-ci.org/github/fixrb/spectus
150
- [rubydoc]: https://rubydoc.info/gems/spectus/frames
data/lib/spectus.rb CHANGED
@@ -2,18 +2,108 @@
2
2
 
3
3
  require "matchi/helper"
4
4
 
5
+ require_relative File.join("spectus", "expectation_target")
6
+
5
7
  # Namespace for the Spectus library.
6
8
  #
7
- # @example It MUST equal 42.
9
+ # This module defines the {#it} method to create expectations, which can be
10
+ # automatically included into classes.
11
+ #
12
+ # @example
13
+ # class Spec
14
+ # include ::Spectus
15
+ #
16
+ # attr_reader :subject
17
+ #
18
+ # def initialize(subject)
19
+ # @subject = subject
20
+ # end
21
+ #
22
+ # def test_a
23
+ # it { subject.upcase }.MUST eql "FOO"
24
+ # end
25
+ #
26
+ # def test_b
27
+ # it { subject.blank? }.MAY be_true
28
+ # end
29
+ #
30
+ # def test_c
31
+ # it { subject.length }.SHOULD equal 42
32
+ # end
33
+ # end
34
+ #
35
+ # t = Spec.new("foo")
36
+ # t.test_a # => Spectus::Result::Pass(actual: "FOO", error: nil, expected: "FOO", got: true, matcher: :eql, negate: false, level: :MUST)
37
+ # t.test_b # => Spectus::Result::Pass(actual: nil, error: #<NoMethodError: undefined method `blank?' for "foo":String>, expected: nil, got: nil, matcher: :be_true, negate: false, level: :MAY)
38
+ # t.test_c # => Spectus::Result::Pass(actual: 3, error: nil, expected: 42, got: false, matcher: :equal, negate: false, level: :SHOULD)
39
+ #
40
+ # Or even directly used like this.
41
+ #
42
+ # @example
8
43
  # require 'spectus'
9
- # it { 42 }.MUST equal 42 # => #<Spectus::Result::Pass...>
44
+ #
45
+ # include Spectus
46
+ #
47
+ # it { 42 }.MUST equal 42 # => Spectus::Result::Pass(actual: 42, error: nil, expected: 42, got: true, matcher: :equal, negate: false, level: :MUST
48
+ #
49
+ # It also includes a collection of expectation matchers 🤹
50
+ #
51
+ # @example Equivalence matcher
52
+ # matcher = eql("foo") # => Matchi::Matcher::Eql.new("foo")
53
+ # matcher.matches? { "foo" } # => true
54
+ # matcher.matches? { "bar" } # => false
55
+ #
56
+ # @example Identity matcher
57
+ # object = "foo"
58
+ #
59
+ # matcher = equal(object) # => Matchi::Matcher::Equal.new(object)
60
+ # matcher.matches? { object } # => true
61
+ # matcher.matches? { "foo" } # => false
62
+ #
63
+ # @example Regular expressions matcher
64
+ # matcher = match(/^foo$/) # => Matchi::Matcher::Match.new(/^foo$/)
65
+ # matcher.matches? { "foo" } # => true
66
+ # matcher.matches? { "bar" } # => false
67
+ #
68
+ # @example Expecting errors matcher
69
+ # matcher = raise_exception(NameError) # => Matchi::Matcher::RaiseException.new(NameError)
70
+ # matcher.matches? { Boom } # => true
71
+ # matcher.matches? { true } # => false
72
+ #
73
+ # @example Truth matcher
74
+ # matcher = be_true # => Matchi::Matcher::BeTrue.new
75
+ # matcher.matches? { true } # => true
76
+ # matcher.matches? { false } # => false
77
+ # matcher.matches? { nil } # => false
78
+ # matcher.matches? { 4 } # => false
79
+ #
80
+ # @example Untruth matcher
81
+ # matcher = be_false # => Matchi::Matcher::BeFalse.new
82
+ # matcher.matches? { false } # => true
83
+ # matcher.matches? { true } # => false
84
+ # matcher.matches? { nil } # => false
85
+ # matcher.matches? { 4 } # => false
86
+ #
87
+ # @example Nil matcher
88
+ # matcher = be_nil # => Matchi::Matcher::BeNil.new
89
+ # matcher.matches? { nil } # => true
90
+ # matcher.matches? { false } # => false
91
+ # matcher.matches? { true } # => false
92
+ # matcher.matches? { 4 } # => false
93
+ #
94
+ # @example Type/class matcher
95
+ # matcher = be_an_instance_of(String) # => Matchi::Matcher::BeAnInstanceOf.new(String)
96
+ # matcher.matches? { "foo" } # => true
97
+ # matcher.matches? { 4 } # => false
98
+ #
99
+ # @see https://github.com/fixrb/matchi
10
100
  module Spectus
11
101
  include ::Matchi::Helper
12
102
 
13
103
  # Expectations are built with this method.
14
104
  #
15
105
  # @example An _absolute requirement_ definition.
16
- # it { 42 }.MUST equal 42 # => #<Spectus::Result::Pass...>
106
+ # it { 42 }.MUST equal 42 # => Spectus::Result::Pass(actual: 42, error: nil, expected: 42, got: true, matcher: :equal, negate: false, level: :MUST
17
107
  #
18
108
  # @param input [Proc] The code to test.
19
109
  #
@@ -22,5 +112,3 @@ module Spectus
22
112
  ExpectationTarget.new(&input)
23
113
  end
24
114
  end
25
-
26
- require_relative File.join("spectus", "expectation_target")
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative File.join("requirement_level", "must")
4
+ require_relative File.join("requirement_level", "should")
5
+ require_relative File.join("requirement_level", "may")
6
+
3
7
  module Spectus
4
8
  # Wraps the target of an expectation.
5
9
  #
@@ -196,7 +200,3 @@ module Spectus
196
200
  attr_reader :callable
197
201
  end
198
202
  end
199
-
200
- require_relative File.join("requirement_level", "must")
201
- require_relative File.join("requirement_level", "should")
202
- require_relative File.join("requirement_level", "may")
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "test_tube"
4
+
5
+ require_relative File.join("..", "result")
6
+
3
7
  module Spectus
4
8
  # Namespace for the requirement levels.
5
9
  module RequirementLevel
@@ -9,22 +13,21 @@ module Spectus
9
13
  #
10
14
  # @param callable [#call] The callable object to test.
11
15
  # @param isolation [Boolean] Compute actual in isolation?
12
- # @param negate [Boolean] Positive or negative assertion?
16
+ # @param negate [Boolean] Invert the matcher or not.
13
17
  # @param matcher [#matches?] The matcher.
14
- def initialize(callable:, isolation:, negate:, matcher:)
15
- @negate = negate
16
- @matcher = matcher
17
-
18
- @exam = Exam.new(
19
- callable: callable,
18
+ def initialize(callable:, isolation:, matcher:, negate:)
19
+ @negate = negate
20
+ @matcher = matcher
21
+ @experiment = ::TestTube.invoke(
22
+ callable,
20
23
  isolation: isolation,
21
- negate: negate,
22
- matcher: matcher
24
+ matcher: matcher,
25
+ negate: negate
23
26
  )
24
27
  end
25
28
 
26
- # @return [#Exam] The exam.
27
- attr_reader :exam
29
+ # @return [TestTube::Base] The experiment.
30
+ attr_reader :experiment
28
31
 
29
32
  # @return [#matches?] The matcher that performed a boolean comparison
30
33
  # between the actual value and the expected value.
@@ -32,24 +35,25 @@ module Spectus
32
35
 
33
36
  # The result of the expectation.
34
37
  #
35
- # @raise [Spectus::Result::Fail] The expectation is `false`.
36
- # @return [Spectus::Result::Pass] The expectation is `true`.
38
+ # @raise [Spectus::Result::Fail] The expectation failed.
39
+ # @return [Spectus::Result::Pass] The expectation passed.
37
40
  def call
38
41
  Result.call(pass?).with(
39
- actual: exam.actual,
40
- error: exam.exception,
42
+ actual: experiment.actual,
43
+ error: experiment.error,
41
44
  expected: matcher.expected,
42
- got: exam.got,
43
- negate: negate?,
44
- valid: exam.valid?,
45
+ got: experiment.got,
46
+ level: level,
45
47
  matcher: matcher.class.to_sym,
46
- level: level
48
+ negate: negate?
47
49
  )
48
50
  end
49
51
 
50
52
  protected
51
53
 
52
- # @return [Symbol] The requirement level.
54
+ # Some key words for use in RFCs to indicate requirement levels.
55
+ #
56
+ # @return [:MUST, :SHOULD, :MAY] The requirement level.
53
57
  def level
54
58
  self.class.name.split("::").fetch(-1).upcase.to_sym
55
59
  end
@@ -57,13 +61,10 @@ module Spectus
57
61
  # @note The boolean comparison between the actual value and the expected
58
62
  # value can be evaluated to a negative assertion.
59
63
  #
60
- # @return [Boolean] Positive or negative assertion?
64
+ # @return [Boolean] Invert the matcher or not.
61
65
  def negate?
62
66
  @negate
63
67
  end
64
68
  end
65
69
  end
66
70
  end
67
-
68
- require_relative File.join("..", "exam")
69
- require_relative File.join("..", "result")
@@ -10,7 +10,7 @@ module Spectus
10
10
  #
11
11
  # @return [Boolean] Report if the low expectation pass or fail?
12
12
  def pass?
13
- super || exam.exception.is_a?(::NoMethodError)
13
+ super || experiment.error.is_a?(::NoMethodError)
14
14
  end
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Spectus
10
10
  #
11
11
  # @return [Boolean] Report if the high expectation pass or fail?
12
12
  def pass?
13
- exam.valid?
13
+ experiment.got.equal?(true)
14
14
  end
15
15
  end
16
16
  end
@@ -10,7 +10,7 @@ module Spectus
10
10
  #
11
11
  # @return [Boolean] Report if the medium expectation pass or fail?
12
12
  def pass?
13
- super || exam.exception.nil?
13
+ super || experiment.error.nil?
14
14
  end
15
15
  end
16
16
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative File.join("result", "fail")
4
+ require_relative File.join("result", "pass")
5
+
3
6
  module Spectus
4
7
  # Namespace for the results.
5
8
  module Result
@@ -13,6 +16,3 @@ module Spectus
13
16
  end
14
17
  end
15
18
  end
16
-
17
- require_relative File.join("result", "fail")
18
- require_relative File.join("result", "pass")
@@ -5,6 +5,8 @@ require "expresenter/fail"
5
5
  module Spectus
6
6
  module Result
7
7
  # The class that is responsible for reporting that the expectation is false.
8
+ #
9
+ # @see https://github.com/fixrb/expresenter/blob/v1.2.1/lib/expresenter/fail.rb
8
10
  class Fail < ::Expresenter::Fail
9
11
  end
10
12
  end
@@ -5,6 +5,8 @@ require "expresenter/pass"
5
5
  module Spectus
6
6
  module Result
7
7
  # The class that is responsible for reporting that the expectation is true.
8
+ #
9
+ # @see https://github.com/fixrb/expresenter/blob/v1.2.1/lib/expresenter/pass.rb
8
10
  class Pass < ::Expresenter::Pass
9
11
  end
10
12
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.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-05-12 00:00:00.000000000 Z
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: defi
14
+ name: expresenter
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.4
19
+ version: 1.3.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: 2.0.4
26
+ version: 1.3.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: expresenter
28
+ name: matchi
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.0
33
+ version: 2.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.0
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: matchi
42
+ name: test_tube
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.0
47
+ version: 1.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.0
54
+ version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: brutal
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -187,7 +187,6 @@ files:
187
187
  - LICENSE.md
188
188
  - README.md
189
189
  - lib/spectus.rb
190
- - lib/spectus/exam.rb
191
190
  - lib/spectus/expectation_target.rb
192
191
  - lib/spectus/requirement_level/base.rb
193
192
  - lib/spectus/requirement_level/may.rb
@@ -215,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
214
  - !ruby/object:Gem::Version
216
215
  version: '0'
217
216
  requirements: []
218
- rubygems_version: 3.1.4
217
+ rubygems_version: 3.1.6
219
218
  signing_key:
220
219
  specification_version: 4
221
220
  summary: "Expectation library with RFC 2119's requirement levels \U0001F6A5"
data/lib/spectus/exam.rb DELETED
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "defi"
4
-
5
- module Spectus
6
- # This class evaluate the expectation with the passed block.
7
- class Exam
8
- # Execute the untested code from the passed block against the matcher.
9
- #
10
- # rubocop:disable Lint/RescueException
11
- #
12
- # @param callable [#call] The callable object to test.
13
- # @param isolation [Boolean] Compute actual in isolation?
14
- # @param negate [Boolean] Positive or negative assertion?
15
- # @param matcher [#matches?] The matcher.
16
- def initialize(callable:, isolation:, negate:, matcher:)
17
- @got = negate ^ matcher.matches? do
18
- value = if isolation
19
- send_call.to!(callable)
20
- else
21
- send_call.to(callable)
22
- end
23
-
24
- @actual = value.object
25
-
26
- value.call
27
- end
28
- rescue ::Exception => e
29
- @actual = nil
30
- @exception = e
31
- end
32
- # rubocop:enable Lint/RescueException
33
-
34
- # @return [#object_id] The actual value.
35
- attr_reader :actual
36
-
37
- # @return [Exception, nil] An exception.
38
- attr_reader :exception
39
-
40
- # @return [Boolean, nil] Report to the spec requirement level if the
41
- # expectation is true or false.
42
- attr_reader :got
43
-
44
- # @return [Defi::Challenge] The challenge for the callable object.
45
- def send_call
46
- ::Defi.send(:call)
47
- end
48
-
49
- # Report to the spec requirement level if the test pass or fail.
50
- #
51
- # @return [Boolean] Report if the test pass or fail?
52
- def valid?
53
- exception.nil? ? got : false
54
- end
55
- end
56
- end