spectus 3.0.10 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +75 -84
- data/lib/spectus.rb +3 -5
- data/lib/spectus/exam.rb +56 -0
- data/lib/spectus/expectation_target.rb +87 -70
- data/lib/spectus/requirement_level/base.rb +40 -81
- data/lib/spectus/requirement_level/may.rb +17 -0
- data/lib/spectus/requirement_level/must.rb +17 -0
- data/lib/spectus/requirement_level/should.rb +17 -0
- data/lib/spectus/result.rb +15 -0
- data/lib/spectus/result/common.rb +180 -0
- data/lib/spectus/result/fail.rb +38 -17
- data/lib/spectus/result/pass.rb +47 -22
- metadata +69 -42
- data/lib/spectus/matchers.rb +0 -33
- data/lib/spectus/report.rb +0 -92
- data/lib/spectus/requirement_level/high.rb +0 -27
- data/lib/spectus/requirement_level/low.rb +0 -27
- data/lib/spectus/requirement_level/medium.rb +0 -27
- data/lib/spectus/result/base.rb +0 -112
- data/lib/spectus/sandbox.rb +0 -61
@@ -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
|
data/lib/spectus/result/base.rb
DELETED
@@ -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
|
data/lib/spectus/sandbox.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spectus
|
4
|
-
# This class evaluate the expectation with the passed block.
|
5
|
-
#
|
6
|
-
# @api private
|
7
|
-
#
|
8
|
-
class Sandbox
|
9
|
-
# rubocop:disable Style/RescueStandardError
|
10
|
-
|
11
|
-
# Execute the untested code from the passed block against the matcher.
|
12
|
-
#
|
13
|
-
# @param matcher [#matches?] The matcher.
|
14
|
-
# @param negate [Boolean] The negation of the matcher's result.
|
15
|
-
# @param object [#object_id] The front object which is challenged.
|
16
|
-
# @param challenges [Array] The list of challenges.
|
17
|
-
def initialize(matcher, negate, object, *challenges)
|
18
|
-
@got = negate ^ matcher.matches? do
|
19
|
-
@actual = challenges.inject(object) do |subject, challenge|
|
20
|
-
@last_challenge = challenge
|
21
|
-
@last_challenge.to(subject)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
rescue => e
|
25
|
-
@exception = e
|
26
|
-
end
|
27
|
-
|
28
|
-
# rubocop:enable Style/RescueStandardError
|
29
|
-
|
30
|
-
# @!attribute [r] last_challenge
|
31
|
-
#
|
32
|
-
# @return [Defi::Challenge] The last evaluated challenge.
|
33
|
-
attr_reader :last_challenge
|
34
|
-
|
35
|
-
# @!attribute [r] actual
|
36
|
-
#
|
37
|
-
# @return [#object_id] The value that the subject return through its
|
38
|
-
# challenge.
|
39
|
-
attr_reader :actual
|
40
|
-
|
41
|
-
# @!attribute [r] exception
|
42
|
-
#
|
43
|
-
# @return [#exception, nil] Any possible raised exception.
|
44
|
-
attr_reader :exception
|
45
|
-
|
46
|
-
# @!attribute [r] got
|
47
|
-
#
|
48
|
-
# @return [#object_id] The result of the boolean comparison between the
|
49
|
-
# actual value and the expected value.
|
50
|
-
attr_reader :got
|
51
|
-
|
52
|
-
# Report to the spec's requirement level if the test is true or false.
|
53
|
-
#
|
54
|
-
# @return [Boolean] Report if the test was true or false.
|
55
|
-
def valid?
|
56
|
-
return false if defined?(@exception)
|
57
|
-
|
58
|
-
got
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|