spectus 2.2.0 → 2.3.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +19 -7
- data/VERSION.semver +1 -1
- data/checksum/spectus-2.3.0.gem.sha512 +1 -0
- data/lib/spectus/challenge.rb +9 -5
- data/lib/spectus/expectation_target.rb +6 -2
- data/lib/spectus/level/base.rb +71 -4
- data/lib/spectus/result/base.rb +51 -8
- data/lib/spectus/result/pass.rb +5 -0
- data/lib/spectus/sandbox.rb +17 -2
- data/lib/spectus.rb +0 -2
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af3530d553018e8e3edb227a935720e3d059710
|
4
|
+
data.tar.gz: ba087a69cc7fdb7fa34b77f9533c613dfe212b1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e87dc18064518c251a502e63a719e8f8ae4e5646c1e9dfd2ebb468ba1188eda8a8e2a3418d61e3d430b94a6f8cd68754b72a7b291cca4294394cf7c4f893ae6
|
7
|
+
data.tar.gz: 5416775288db9e161101a4759e8aaad4ae600809ca90db34b5213303aa8c247f1b59a7fef1c7c83372295c5f64d1586c9142cf8a50d4d9aaafce344b007a0428
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -30,6 +30,16 @@ To be sure the gem you install hasn't been tampered with, add my public key (if
|
|
30
30
|
|
31
31
|
The `HighSecurity` trust profile will verify all gems. All of __Spectus__'s dependencies are signed.
|
32
32
|
|
33
|
+
Or add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'spectus'
|
37
|
+
```
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
|
41
|
+
$ bundle
|
42
|
+
|
33
43
|
## Expectation
|
34
44
|
|
35
45
|
An expectation is an assertion that is either `true` or `false`.
|
@@ -58,7 +68,7 @@ Given the `"ルビー"` object, when it receives `valid_encoding?` method, then
|
|
58
68
|
|
59
69
|
```ruby
|
60
70
|
Spectus.this { 'ルビー'.valid_encoding? }.MUST :BeTrue
|
61
|
-
# => #<Spectus::Result::Pass:
|
71
|
+
# => #<Spectus::Result::Pass:0x007f9329c45090 @message="Pass: Expected true to be true.", @subject=#<Proc:0x007f9329c45d60@(irb):1>, @challenge=:call, @context=[], @actual=true, @expected=:BeTrue, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
|
62
72
|
```
|
63
73
|
|
64
74
|
The result of the test shows that the spec passed.
|
@@ -69,7 +79,7 @@ Given the `"foo"` object, when it receives `length` method, then it **MUST NOT**
|
|
69
79
|
|
70
80
|
```ruby
|
71
81
|
Spectus.this { 'foo'.length }.MUST_NOT RaiseException: NoMethodError
|
72
|
-
# => #<Spectus::Result::Pass:
|
82
|
+
# => #<Spectus::Result::Pass:0x007f9329c341f0 @message="Pass: Expected 3 not to raise exception NoMethodError.", @subject=#<Proc:0x007f9329c34da8@(irb):2>, @challenge=:call, @context=[], @actual=3, @expected={:RaiseException=>NoMethodError}, @got=true, @error=nil, @level=:High, @negate=true, @valid=true>
|
73
83
|
```
|
74
84
|
|
75
85
|
The result of the test shows that the spec passed.
|
@@ -80,7 +90,7 @@ Given the `BasicObject` object, when it receives `superclass` method, then it **
|
|
80
90
|
|
81
91
|
```ruby
|
82
92
|
Spectus.this { BasicObject.superclass }.SHOULD Equal: NilClass
|
83
|
-
# => #<Spectus::Result::Pass:
|
93
|
+
# => #<Spectus::Result::Pass:0x007f9329c1def0 @message="Info: Expected nil to equal NilClass.", @subject=#<Proc:0x007f9329c1e990@(irb):3>, @challenge=:call, @context=[], @actual=nil, @expected={:Equal=>NilClass}, @got=false, @error=nil, @level=:Medium, @negate=false, @valid=false>
|
84
94
|
```
|
85
95
|
|
86
96
|
Instead of the expected `NilClass` class, its sole instance (which is `nil`) was returned.
|
@@ -92,7 +102,9 @@ Given the `"1"` object, when it receives `+(1)` method, then it **SHOULD NOT** r
|
|
92
102
|
|
93
103
|
```ruby
|
94
104
|
Spectus.this { '1' + 1 }.SHOULD_NOT Eql: '11'
|
95
|
-
#
|
105
|
+
# Spectus::Result::Fail: Error: no implicit conversion of Fixnum into String (TypeError).
|
106
|
+
# from (irb):4
|
107
|
+
# from ./bin/console:7:in `<main>'
|
96
108
|
```
|
97
109
|
|
98
110
|
There was a `TypeError` exception, the result of the test shows that the spec failed.
|
@@ -103,7 +115,7 @@ Given the `"foo"` object, when it receives `blank?` method, then it **MAY** be `
|
|
103
115
|
|
104
116
|
```ruby
|
105
117
|
Spectus.this { 'foo'.blank? }.MAY :BeFalse
|
106
|
-
# => #<Spectus::Result::Pass:
|
118
|
+
# => #<Spectus::Result::Pass:0x007f932b91feb8 @message="Info: undefined method `blank?' for \"foo\":String (NoMethodError).", @subject=#<Proc:0x007f9329bfc5e8@(irb):5>, @challenge=:call, @context=[], @actual=nil, @expected=:BeFalse, @got=nil, @error=#<NoMethodError: undefined method `blank?' for "foo":String>, @level=:Low, @negate=false, @valid=false>
|
107
119
|
```
|
108
120
|
|
109
121
|
The optional `blank?` method is not implemented (unlike in [Ruby on Rails](http://api.rubyonrails.org/classes/Object.html#method-i-blank-3F), for instance), so the result of the test shows that the spec passed.
|
@@ -118,8 +130,8 @@ built Gem they can be used for basic integrity verification purposes.
|
|
118
130
|
The checksum of a file can be checked using the `sha512sum` command. For
|
119
131
|
example:
|
120
132
|
|
121
|
-
$ sha512sum pkg/spectus-2.
|
122
|
-
|
133
|
+
$ sha512sum pkg/spectus-2.3.0.gem
|
134
|
+
d12d7d9c2a4fdfe075cbb7a141fa5f2195175891e4098c7e1a28c8bca655ab44fb9d67b6a2e3991d0f852026c5e4537fdf7e314575c68d1c80b3a4b1eb1c041f pkg/spectus-2.3.0.gem
|
123
135
|
|
124
136
|
## Versioning
|
125
137
|
|
data/VERSION.semver
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
@@ -0,0 +1 @@
|
|
1
|
+
0bf8cbdb18e983b524e5857af066f4d948ea6e2d70b2cb97d56cb37f5ccf8a33931f3e9786097f1aea6183be01106d6e3d40a97f1fbf58dfaf89eb9f01cab260
|
data/lib/spectus/challenge.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Spectus
|
2
|
-
# This class
|
2
|
+
# This class contains a challenge to apply against an object.
|
3
3
|
#
|
4
|
-
# @api
|
4
|
+
# @api public
|
5
5
|
#
|
6
6
|
class Challenge
|
7
|
-
#
|
7
|
+
# Initialize the challenge class.
|
8
8
|
#
|
9
9
|
# @param [#to_sym] method_id the identifier of a method.
|
10
10
|
# @param [Array] args the arguments of the method.
|
@@ -13,10 +13,14 @@ module Spectus
|
|
13
13
|
@args = args
|
14
14
|
end
|
15
15
|
|
16
|
-
#
|
16
|
+
# @!attribute [r] symbol
|
17
|
+
#
|
18
|
+
# @return [Symbol] The method to call on the subject.
|
17
19
|
attr_reader :symbol
|
18
20
|
|
19
|
-
#
|
21
|
+
# @!attribute [r] args
|
22
|
+
#
|
23
|
+
# @return [Array] The parameters following the method.
|
20
24
|
attr_reader :args
|
21
25
|
end
|
22
26
|
end
|
@@ -17,10 +17,14 @@ module Spectus
|
|
17
17
|
@challenge = Challenge.new(:call)
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
20
|
+
# @!attribute [r] subject
|
21
|
+
#
|
22
|
+
# @return [BasicObject] The front object to be tested.
|
21
23
|
attr_reader :subject
|
22
24
|
|
23
|
-
#
|
25
|
+
# @!attribute [r] challenge
|
26
|
+
#
|
27
|
+
# @return [Challenge] The challenge to call on the subject.
|
24
28
|
attr_reader :challenge
|
25
29
|
|
26
30
|
# This word, or the terms "REQUIRED" or "SHALL", mean that the
|
data/lib/spectus/level/base.rb
CHANGED
@@ -3,11 +3,13 @@ require_relative File.join '..', 'result', 'fail'
|
|
3
3
|
require_relative File.join '..', 'result', 'pass'
|
4
4
|
|
5
5
|
module Spectus
|
6
|
+
# Namespace for the requirement levels.
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
#
|
6
10
|
module RequirementLevel
|
7
11
|
# Requirement level's base class.
|
8
12
|
#
|
9
|
-
# @api private
|
10
|
-
#
|
11
13
|
class Base
|
12
14
|
# Initialize the requirement level class.
|
13
15
|
#
|
@@ -29,14 +31,15 @@ module Spectus
|
|
29
31
|
#
|
30
32
|
# @return [Result::Pass] pass the spec.
|
31
33
|
def pass!(state)
|
32
|
-
Result::Pass.new(*result_signature(state))
|
34
|
+
Result::Pass.new(message(state, true), *result_signature(state))
|
33
35
|
end
|
34
36
|
|
35
37
|
# @param state [Sandbox] The sandbox that tested the code.
|
36
38
|
#
|
37
39
|
# @raise [Result::Fail] fail the spec.
|
38
40
|
def fail!(state)
|
39
|
-
fail Result::Fail.new(*result_signature(state)),
|
41
|
+
fail Result::Fail.new(message(state, false), *result_signature(state)),
|
42
|
+
message(state, false), caller[2..-1]
|
40
43
|
end
|
41
44
|
|
42
45
|
# @param state [Sandbox] The sandbox that tested the code.
|
@@ -67,6 +70,70 @@ module Spectus
|
|
67
70
|
Sandbox.new(@definition, @negate, @subject, @challenge.symbol,
|
68
71
|
*@challenge.args)
|
69
72
|
end
|
73
|
+
|
74
|
+
# @param state [Sandbox] The sandbox that tested the code.
|
75
|
+
# @param result [Boolean] The result of the test.
|
76
|
+
#
|
77
|
+
# @return [String] the message that describe the state.
|
78
|
+
def message(state, result)
|
79
|
+
"#{title(state, result)}: #{summary(state)}."
|
80
|
+
end
|
81
|
+
|
82
|
+
# The title of the state.
|
83
|
+
#
|
84
|
+
# @param state [Sandbox] The sandbox that tested the code.
|
85
|
+
# @param result [Boolean] The result of the test.
|
86
|
+
#
|
87
|
+
# @return [String] the title of the state.
|
88
|
+
def title(state, result)
|
89
|
+
if result
|
90
|
+
if state.got
|
91
|
+
'Pass'
|
92
|
+
else
|
93
|
+
'Info'
|
94
|
+
end
|
95
|
+
else
|
96
|
+
if state.exception.nil?
|
97
|
+
'Failure'
|
98
|
+
else
|
99
|
+
'Error'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# The summary of the state.
|
105
|
+
#
|
106
|
+
# @param state [Sandbox] The sandbox that tested the code.
|
107
|
+
#
|
108
|
+
# @return [String] the summary of the state.
|
109
|
+
def summary(state)
|
110
|
+
if state.valid? || state.exception.nil?
|
111
|
+
'Expected ' + state.actual.inspect + (@negate ? ' not ' : ' ') +
|
112
|
+
'to ' + if @definition.is_a?(Hash)
|
113
|
+
readable(@definition.keys.first.to_s) +
|
114
|
+
" #{@definition.values.first.inspect}"
|
115
|
+
else
|
116
|
+
readable(@definition.to_s)
|
117
|
+
end
|
118
|
+
else
|
119
|
+
state.exception.message
|
120
|
+
end + if state.exception.nil?
|
121
|
+
''
|
122
|
+
else
|
123
|
+
" (#{state.exception.class})"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# @param string [String] A UpperCamelCase string.
|
128
|
+
#
|
129
|
+
# @return [String] the snake_case string.
|
130
|
+
def readable(string)
|
131
|
+
string.gsub(/::/, '/')
|
132
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
133
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
134
|
+
.tr('-_', ' ')
|
135
|
+
.downcase
|
136
|
+
end
|
70
137
|
end
|
71
138
|
end
|
72
139
|
end
|
data/lib/spectus/result/base.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Spectus
|
2
|
+
# Namespace for the results.
|
3
|
+
#
|
4
|
+
# @api private
|
5
|
+
#
|
2
6
|
module Result
|
3
7
|
# Result base's module.
|
4
8
|
#
|
5
|
-
# @api public
|
6
|
-
#
|
7
9
|
module Base
|
8
10
|
# Initialize the result class.
|
9
11
|
#
|
12
|
+
# @param message [String] It is describing the actual/error value.
|
10
13
|
# @param subject [#object_id] The untrusted object to be tested.
|
11
14
|
# @param challenge [Symbol] The method to call on the subject.
|
12
15
|
# @param context [Array] Parameters of the challenge.
|
@@ -20,9 +23,10 @@ module Spectus
|
|
20
23
|
# @param level [:High, :Medium, :Low] The level of the expectation.
|
21
24
|
# @param negate [Boolean] Evaluate to a negative assertion.
|
22
25
|
# @param valid [Boolean] Report if the test was true or false.
|
23
|
-
def initialize(subject, challenge, context, actual, expected,
|
24
|
-
level, negate, valid)
|
26
|
+
def initialize(message, subject, challenge, context, actual, expected,
|
27
|
+
got, error, level, negate, valid)
|
25
28
|
|
29
|
+
@message = message
|
26
30
|
@subject = subject
|
27
31
|
@challenge = challenge
|
28
32
|
@context = context
|
@@ -35,8 +39,47 @@ module Spectus
|
|
35
39
|
@valid = valid
|
36
40
|
end
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
# @!attribute [r] subject
|
43
|
+
#
|
44
|
+
# @return [#object_id] The untrusted object to be tested.
|
45
|
+
attr_reader :subject
|
46
|
+
|
47
|
+
# @!attribute [r] challenge
|
48
|
+
#
|
49
|
+
# @return [Symbol] The method to call on the subject.
|
50
|
+
attr_reader :challenge
|
51
|
+
|
52
|
+
# @!attribute [r] context
|
53
|
+
#
|
54
|
+
# @return [Array] Parameters of the challenge.
|
55
|
+
attr_reader :context
|
56
|
+
|
57
|
+
# @!attribute [r] actual
|
58
|
+
#
|
59
|
+
# @return [#object_id] The value that the subject return through its
|
60
|
+
# challenge.
|
61
|
+
attr_reader :actual
|
62
|
+
|
63
|
+
# @!attribute [r] expected
|
64
|
+
#
|
65
|
+
# @return [Array, Hash, Symbol] The definition of the expected value.
|
66
|
+
attr_reader :expected
|
67
|
+
|
68
|
+
# @!attribute [r] got
|
69
|
+
#
|
70
|
+
# @return [#object_id] The result of the boolean comparison between the
|
71
|
+
# actual value and the expected value.
|
72
|
+
attr_reader :got
|
73
|
+
|
74
|
+
# @!attribute [r] error
|
75
|
+
#
|
76
|
+
# @return [#exception, nil] Any possible raised exception.
|
77
|
+
attr_reader :error
|
78
|
+
|
79
|
+
# @!attribute [r] level
|
80
|
+
#
|
81
|
+
# @return [:High, :Medium, :Low] The level of the expectation.
|
82
|
+
attr_reader :level
|
40
83
|
|
41
84
|
# The value of the negate instance variable.
|
42
85
|
#
|
@@ -53,9 +96,9 @@ module Spectus
|
|
53
96
|
@valid
|
54
97
|
end
|
55
98
|
|
56
|
-
#
|
99
|
+
# Properties of the result.
|
57
100
|
#
|
58
|
-
# @return [
|
101
|
+
# @return [Hash] the properties of the result.
|
59
102
|
def to_h
|
60
103
|
{
|
61
104
|
subject: subject,
|
data/lib/spectus/result/pass.rb
CHANGED
data/lib/spectus/sandbox.rb
CHANGED
@@ -6,8 +6,6 @@ module Spectus
|
|
6
6
|
# @api private
|
7
7
|
#
|
8
8
|
class Sandbox
|
9
|
-
attr_reader :actual, :exception, :got
|
10
|
-
|
11
9
|
# Execute the untested code from the passed block against the definition.
|
12
10
|
#
|
13
11
|
# @param [Array, Hash, Symbol] definition
|
@@ -23,6 +21,23 @@ module Spectus
|
|
23
21
|
@exception = e
|
24
22
|
end
|
25
23
|
|
24
|
+
# @!attribute [r] actual
|
25
|
+
#
|
26
|
+
# @return [#object_id] The value that the subject return through its
|
27
|
+
# challenge.
|
28
|
+
attr_reader :actual
|
29
|
+
|
30
|
+
# @!attribute [r] exception
|
31
|
+
#
|
32
|
+
# @return [#exception, nil] Any possible raised exception.
|
33
|
+
attr_reader :exception
|
34
|
+
|
35
|
+
# @!attribute [r] got
|
36
|
+
#
|
37
|
+
# @return [#object_id] The result of the boolean comparison between the
|
38
|
+
# actual value and the expected value.
|
39
|
+
attr_reader :got
|
40
|
+
|
26
41
|
# Report to the spec's requirement level if the test is true or false.
|
27
42
|
#
|
28
43
|
# @return [Boolean] Report if the test was true or false.
|
data/lib/spectus.rb
CHANGED
@@ -9,8 +9,6 @@ require_relative File.join 'spectus', 'expectation_target'
|
|
9
9
|
module Spectus
|
10
10
|
# Expectations are built with this method.
|
11
11
|
#
|
12
|
-
# @api public
|
13
|
-
#
|
14
12
|
# @example Absolute requirement definition
|
15
13
|
# this { 42 }.MUST Equal: 42 # => #<Spectus::Result::Pass...>
|
16
14
|
#
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Wack
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
dzJvWzQ1+dJU6WQv75E9ddSkaQrK3nhdgQVu+/wgvGSrsMvOGNz+LXaSDxQqZuwX
|
31
31
|
0KNQFuIukfrdk8URwRnHoAnvx4U93iUw
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-08-
|
33
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: matchi
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- checksum/spectus-2.1.2.gem.sha512
|
147
147
|
- checksum/spectus-2.1.3.gem.sha512
|
148
148
|
- checksum/spectus-2.2.0.gem.sha512
|
149
|
+
- checksum/spectus-2.3.0.gem.sha512
|
149
150
|
- lib/spectus.rb
|
150
151
|
- lib/spectus/challenge.rb
|
151
152
|
- lib/spectus/expectation_target.rb
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
�({]���V��'�<Lt���Օ�0� ��he���|�q ��{��_��Hxr����o�R�=�S`_��� �N�
|
1
|
+
�q����eңM�O����x���Hл��z�өs����CW�G���ZAs�d����:�����Fk��8��8#�FZ�� ��X��("�Q��oΟ�I��Y\�9�*A`�MCV��M�F_���B��q3��w��!���kF|�h�|�7�3����`��b齄�me���S�)� kO�2��k:�S�������J�h`¬�i"㟪��5���=n��5��gЇ��e�E�,<���Q���Af��
|