spectus 3.0.10 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1,83 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
3
+ require_relative 'common'
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
8
  class Pass
9
- include Base
9
+ include Common
10
10
 
11
- # @!attribute [r] message
11
+ alias message to_s
12
+
13
+ # Did the test fail?
12
14
  #
13
- # @return [String] The message that describe the state.
14
- attr_reader :message
15
+ # @return [Boolean] The spec passed or failed?
16
+ def failed?
17
+ false
18
+ end
15
19
 
16
- # The value of the expectation of the spec.
20
+ # Did the test pass?
17
21
  #
18
- # @return [Boolean] The spec was true.
19
- def result?
20
- true
22
+ # @return [Boolean] The spec passed or failed?
23
+ def passed?
24
+ !failed?
21
25
  end
22
26
 
23
- # The state of success.
27
+ # The state of failure.
24
28
  #
25
- # @return [Boolean] The test was a success.
26
- def success?
27
- got.equal?(true)
29
+ # @return [Boolean] The test was a failure?
30
+ def failure?
31
+ false
28
32
  end
29
33
 
30
34
  # The state of info.
31
35
  #
32
- # @return [Boolean] The test was an info.
36
+ # @return [Boolean] The test was an info?
33
37
  def info?
34
- !success?
38
+ !error.nil?
39
+ end
40
+
41
+ # The state of warning.
42
+ #
43
+ # @return [Boolean] The test was a warning?
44
+ def warning?
45
+ got.equal?(false)
35
46
  end
36
47
 
37
48
  # Identify the state of the result.
38
49
  #
39
50
  # @return [Symbol] The identifier of the state.
40
51
  def to_sym
41
- success? ? :success : :info
52
+ return :success if success?
53
+ return :warning if warning?
54
+
55
+ :info
42
56
  end
43
57
 
44
58
  # Express the result with one char.
45
59
  #
46
- # @param color [Boolean] Enable the color.
47
- #
48
60
  # @return [String] The char that identify the result.
49
- def to_char(color = false)
61
+ def char
62
+ if success?
63
+ '.'
64
+ elsif warning?
65
+ 'W'
66
+ else
67
+ 'I'
68
+ end
69
+ end
70
+
71
+ # Express the result with one emoji.
72
+ #
73
+ # @return [String] The emoji that identify the result.
74
+ def emoji
50
75
  if success?
51
- color ? "\e[32m.\e[0m" : '.'
76
+ ''
77
+ elsif warning?
78
+ '⚠️'
52
79
  else
53
- color ? "\e[33mI\e[0m" : 'I'
80
+ '💡'
54
81
  end
55
82
  end
56
83
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.10
4
+ version: 3.1.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: 2019-12-08 00:00:00.000000000 Z
11
+ date: 2019-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aw
14
+ name: defi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.6
19
+ version: 2.0.3
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: 0.1.6
26
+ version: 2.0.3
27
27
  - !ruby/object:Gem::Dependency
28
- name: defi
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.5
33
+ version: 2.0.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.5
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: matchi
42
+ name: brutal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.4
48
- type: :runtime
47
+ version: '0.4'
48
+ type: :development
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: 1.0.4
54
+ version: '0.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '2.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '2.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.9'
139
- description: Expectation library with RFC 2119's requirement levels.
139
+ description: "Expectation library with RFC 2119's requirement levels \U0001F6A5"
140
140
  email: contact@cyril.email
141
141
  executables: []
142
142
  extensions: []
@@ -145,17 +145,15 @@ files:
145
145
  - LICENSE.md
146
146
  - README.md
147
147
  - lib/spectus.rb
148
+ - lib/spectus/exam.rb
148
149
  - lib/spectus/expectation_target.rb
149
- - lib/spectus/matchers.rb
150
- - lib/spectus/report.rb
151
150
  - lib/spectus/requirement_level/base.rb
152
- - lib/spectus/requirement_level/high.rb
153
- - lib/spectus/requirement_level/low.rb
154
- - lib/spectus/requirement_level/medium.rb
155
- - lib/spectus/result/base.rb
151
+ - lib/spectus/requirement_level/may.rb
152
+ - lib/spectus/requirement_level/must.rb
153
+ - lib/spectus/requirement_level/should.rb
154
+ - lib/spectus/result/common.rb
156
155
  - lib/spectus/result/fail.rb
157
156
  - lib/spectus/result/pass.rb
158
- - lib/spectus/sandbox.rb
159
157
  homepage: https://github.com/fixrb/spectus
160
158
  licenses:
161
159
  - MIT
@@ -175,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
173
  - !ruby/object:Gem::Version
176
174
  version: '0'
177
175
  requirements: []
178
- rubygems_version: 3.0.6
176
+ rubygems_version: 3.1.2
179
177
  signing_key:
180
178
  specification_version: 4
181
- summary: Expectation library with RFC 2119's requirement levels.
179
+ summary: "Expectation library with RFC 2119's requirement levels \U0001F6A5"
182
180
  test_files: []
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'matchi'
4
-
5
- module Spectus
6
- # The module includes the list of matcher methods.
7
- #
8
- # @api public
9
- #
10
- module Matchers
11
- ::Matchi::Matchers.constants.each do |const|
12
- name = const.to_s
13
- .gsub(/::/, '/')
14
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
15
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
16
- .downcase
17
-
18
- # Define a method for the given matcher.
19
- #
20
- # @example Given the `Matchi::Matchers::Equal::Matcher` matcher, its
21
- # method would be:
22
- #
23
- # def equal(expected)
24
- # Matchi::Matchers::Equal::Matcher.new(expected)
25
- # end
26
- #
27
- # @return [#matches?] The matcher.
28
- define_method name do |*args|
29
- ::Matchi::Matchers.const_get(const)::Matcher.new(*args)
30
- end
31
- end
32
- end
33
- end
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spectus
4
- # The class that is responsible for reporting the result of the test.
5
- #
6
- # @api private
7
- #
8
- class Report
9
- # Initialize the report class.
10
- #
11
- # @param matcher [#matches?] The matcher.
12
- # @param negate [Boolean] Evaluate to a negative assertion.
13
- # @param state [Sandbox] The sandbox that tested the code.
14
- # @param result [Boolean] The result of the test.
15
- def initialize(matcher, negate, state, result)
16
- @matcher = matcher
17
- @negate = negate
18
- @state = state
19
- @result = result
20
- end
21
-
22
- # @!attribute [r] matcher
23
- #
24
- # @return [#matches?] The matcher.
25
- attr_reader :matcher
26
-
27
- # The value of the negate instance variable.
28
- #
29
- # @return [Boolean] Evaluated to a negative assertion or not.
30
- def negate?
31
- @negate
32
- end
33
-
34
- # @!attribute [r] state
35
- #
36
- # @return [Sandbox] The sandbox that tested the code.
37
- attr_reader :state
38
-
39
- # @!attribute [r] result
40
- #
41
- # @return [Boolean] The result of the test.
42
- attr_reader :result
43
-
44
- # The message.
45
- #
46
- # @return [String] The message that describe the state.
47
- def to_s
48
- "#{title}: #{summary}#{maybe_exception}."
49
- end
50
-
51
- # The title of the state.
52
- #
53
- # @return [String] The title of the state.
54
- def title
55
- if result
56
- state.got ? 'Pass' : 'Info'
57
- else
58
- state.exception.nil? ? 'Failure' : 'Error'
59
- end
60
- end
61
-
62
- # The summary of the state.
63
- #
64
- # @return [String] The summary of the state.
65
- def summary
66
- return state.exception.message unless state.valid? || state.exception.nil?
67
-
68
- "Expected #{state.actual.inspect}#{maybe_negate} to #{definition}"
69
- end
70
-
71
- # The negation, if any.
72
- #
73
- # @return [String] The negation, or an empty string.
74
- def maybe_negate
75
- negate? ? ' not' : ''
76
- end
77
-
78
- # The type of exception, if any.
79
- #
80
- # @return [String] The type of exception, or an empty string.
81
- def maybe_exception
82
- state.exception.nil? ? '' : " (#{state.exception.class})"
83
- end
84
-
85
- # The readable definition.
86
- #
87
- # @return [String] The readable definition string.
88
- def definition
89
- matcher.to_s
90
- end
91
- end
92
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base'
4
-
5
- module Spectus
6
- module RequirementLevel
7
- # High requirement level's class.
8
- #
9
- # @api private
10
- #
11
- class High < Base
12
- # Evaluate the expectation.
13
- #
14
- # @return [Result::Fail, Result::Pass] Report if the high expectation
15
- # pass or fail.
16
- def result(isolation = false)
17
- state = sandbox(isolation)
18
-
19
- if state.valid?
20
- pass!(state)
21
- else
22
- fail!(state)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base'
4
-
5
- module Spectus
6
- module RequirementLevel
7
- # Low requirement level's class.
8
- #
9
- # @api private
10
- #
11
- class Low < Base
12
- # Evaluate the expectation.
13
- #
14
- # @return [Result::Fail, Result::Pass] Report if the low expectation
15
- # pass or fail.
16
- def result(isolation = false)
17
- state = sandbox(isolation)
18
-
19
- if state.valid? || state.exception.is_a?(::NoMethodError)
20
- pass!(state)
21
- else
22
- fail!(state)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base'
4
-
5
- module Spectus
6
- module RequirementLevel
7
- # Medium requirement level's class.
8
- #
9
- # @api private
10
- #
11
- class Medium < Base
12
- # Evaluate the expectation.
13
- #
14
- # @return [Result::Fail, Result::Pass] Report if the medium expectation
15
- # pass or fail.
16
- def result(isolation = false)
17
- state = sandbox(isolation)
18
-
19
- if state.valid? || state.exception.nil?
20
- pass!(state)
21
- else
22
- fail!(state)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spectus
4
- # Namespace for the results.
5
- #
6
- # @api private
7
- #
8
- module Result
9
- # Result base's module.
10
- #
11
- module Base
12
- # Initialize the result class.
13
- #
14
- # @param message [#to_s] It is describing the actual/error value.
15
- # @param subject [#object_id] The untrusted object to be tested.
16
- # @param challenge [Defi::Challenge] The challenge for the subject.
17
- # @param actual [#object_id] The value that the subject return through
18
- # its challenge.
19
- # @param expected [#matches?] The definition of the expected value.
20
- # @param got [#object_id] The result of the boolean comparison
21
- # between the actual value and the expected value.
22
- # @param error [#exception, nil] Any possible raised exception.
23
- # @param level [:High, :Medium, :Low] The level of the expectation.
24
- # @param negate [Boolean] Evaluate to a negative assertion.
25
- # @param valid [Boolean] Report if the test was true or false.
26
- def initialize(message, subject, challenge, actual, expected, got, error,
27
- level, negate, valid)
28
-
29
- @message = message.to_s
30
- @subject = subject
31
- @challenge = challenge
32
- @actual = actual
33
- @expected = expected
34
- @got = got
35
- @error = error
36
- @level = level
37
- @negate = negate
38
- @valid = valid
39
- end
40
-
41
- # @!attribute [r] subject
42
- #
43
- # @return [#object_id] The untrusted object to be tested.
44
- attr_reader :subject
45
-
46
- # @!attribute [r] challenge
47
- #
48
- # @return [Symbol] The method to call on the subject.
49
- attr_reader :challenge
50
-
51
- # @!attribute [r] actual
52
- #
53
- # @return [#object_id] The value that the subject return through its
54
- # challenge.
55
- attr_reader :actual
56
-
57
- # @!attribute [r] expected
58
- #
59
- # @return [#matches?] The definition of the expected value.
60
- attr_reader :expected
61
-
62
- # @!attribute [r] got
63
- #
64
- # @return [#object_id] The result of the boolean comparison between the
65
- # actual value and the expected value.
66
- attr_reader :got
67
-
68
- # @!attribute [r] error
69
- #
70
- # @return [#exception, nil] Any possible raised exception.
71
- attr_reader :error
72
-
73
- # @!attribute [r] level
74
- #
75
- # @return [:High, :Medium, :Low] The level of the expectation.
76
- attr_reader :level
77
-
78
- # The value of the negate instance variable.
79
- #
80
- # @return [Boolean] Evaluated to a negative assertion or not.
81
- def negate?
82
- @negate
83
- end
84
-
85
- # The value of the boolean comparison between the actual value and the
86
- # expected value.
87
- #
88
- # @return [Boolean] The test was true or false.
89
- def valid?
90
- @valid
91
- end
92
-
93
- # Properties of the result.
94
- #
95
- # @return [Hash] The properties of the result.
96
- def to_h
97
- {
98
- subject: subject,
99
- challenge: challenge.to_h,
100
- actual: actual,
101
- expected: expected.to_h,
102
- got: got,
103
- error: error,
104
- level: level,
105
- negate: negate?,
106
- valid: valid?,
107
- result: result?
108
- }
109
- end
110
- end
111
- end
112
- end