spectus 2.7.1 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07c8c866806313aa6dd76d20cd16a210b7ec463e
4
- data.tar.gz: 7230d480f8eeee4c7f4250585c17ce39dd5ee2f4
3
+ metadata.gz: f9c5f017cdf442b8b5b030ba4a89faec996d46d0
4
+ data.tar.gz: e92e7bce6997f75a1932d8593cf21e0150e95d08
5
5
  SHA512:
6
- metadata.gz: e4a66a9f0cfba508da590e374f0ad5fe14a79ab15afe4e4a4208f3f0b44c2d09f530e9d9a40cfc27eed059d0786b9561a4af2fcf3c6faba1d81e5e54629789cf
7
- data.tar.gz: 15274e958e2909d61f4ef169ff5a9847b8f262aa4540ab3581a966d5380820c3316ae956244763bcf58fbdea16d4c18a40b7677251c987a00ccc8cb962e35ee0
6
+ metadata.gz: 6ccc7b4ab0aea3ee90b6a9cb28fe62e7d4458118df8cb34ccdbf3fdd530cf1fce8f0c1aab2a9884df30f99a1586708bc071ce5056fb8277d4d94b6e7f7c3ee0e
7
+ data.tar.gz: 62c3f9dd0ab650be6226c5564f4df238876683175b9cd20694467674dc6533afcae2f07aef42f4908390a2a56244349dabbf719a9c243af7798b896881df2b94
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- "[=׾���j#�CO�^+-�mjgb@����-�+פ���"��dY$��S�'93��(H����v��
2
- /x��7��F����=){QЇ��%����{�����=�~�=^��ȹ�2��
1
+ H���{Û8AX��E 5J�T4�p�x1�Bx?Ž+Z�Qs� aZ�0+��G8�:�\�|@��W��'�7����dD�AR;� j�x%�@D�#vU�XX;Cy�:��Lu͚�]��Eۏ��$�T<����O�Qm(1Jl_��?7Ѫ���Y�ēLJD�~�1 M7S���ѭ4�KX��g�ͨl }��J��g���TP�� C�O<�ٷ��j�5 d���Ls{��t�6T����Qw���%$W+F��r�����X_
data/.rubocop.yml CHANGED
@@ -1,12 +1 @@
1
- TrivialAccessors:
2
- Enabled: true
3
- ExactNameMatch: true
4
-
5
- Style/MethodName:
6
- Enabled: false
7
-
8
- ParameterLists:
9
- Max: 11
10
-
11
- Metrics/MethodLength:
12
- Max: 16
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,29 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-10-10 17:44:08 +0200 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 18
12
+
13
+ # Offense count: 4
14
+ # Configuration parameters: CountComments.
15
+ Metrics/MethodLength:
16
+ Max: 12
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: CountKeywordArgs.
20
+ Metrics/ParameterLists:
21
+ Max: 10
22
+
23
+ # Offense count: 2
24
+ # Cop supports --auto-correct.
25
+ # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
26
+ Style/TrivialAccessors:
27
+ Exclude:
28
+ - 'lib/spectus/level/base.rb'
29
+ - 'lib/spectus/report.rb'
data/VERSION.semver CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 2.8.0
@@ -0,0 +1 @@
1
+ 7d429237e89c48a3f04e6299578fb5663b977b4191bbe99c6d0db155a06b85bd8a1985e06b18794f36e9320f05743d145ae16bf8e34beef341e7a0c56491fc93
data/lib/spectus.rb CHANGED
@@ -1,5 +1,3 @@
1
- require_relative File.join 'spectus', 'expectation_target'
2
-
3
1
  # Namespace for the Spectus library.
4
2
  #
5
3
  # @api public
@@ -19,3 +17,5 @@ module Spectus
19
17
  ExpectationTarget.new(&input)
20
18
  end
21
19
  end
20
+
21
+ require_relative File.join 'spectus', 'expectation_target'
@@ -1,6 +1,3 @@
1
- require_relative File.join 'level', 'high'
2
- require_relative File.join 'level', 'medium'
3
- require_relative File.join 'level', 'low'
4
1
  require 'defi'
5
2
 
6
3
  module Spectus
@@ -27,6 +24,8 @@ module Spectus
27
24
  # @return [Array] The challenges to call on the subject.
28
25
  attr_reader :challenges
29
26
 
27
+ # rubocop:disable Style/MethodName
28
+
30
29
  # This word, or the terms "REQUIRED" or "SHALL", mean that the
31
30
  # definition is an absolute requirement of the specification.
32
31
  #
@@ -107,3 +106,7 @@ module Spectus
107
106
  end
108
107
  end
109
108
  end
109
+
110
+ require_relative File.join 'level', 'high'
111
+ require_relative File.join 'level', 'medium'
112
+ require_relative File.join 'level', 'low'
@@ -1,7 +1,3 @@
1
- require_relative File.join '..', 'sandbox'
2
- require_relative File.join '..', 'result', 'fail'
3
- require_relative File.join '..', 'result', 'pass'
4
-
5
1
  module Spectus
6
2
  # Namespace for the requirement levels.
7
3
  #
@@ -24,21 +20,46 @@ module Spectus
24
20
  @challenges = challenges
25
21
  end
26
22
 
23
+ # @!attribute [r] req
24
+ #
25
+ # @return [Hash, Symbol] The definition of the expected value.
26
+ attr_reader :req
27
+
28
+ # The value of the negate instance variable.
29
+ #
30
+ # @return [Boolean] Evaluated to a negative assertion or not.
31
+ def negate?
32
+ @negate
33
+ end
34
+
35
+ # @!attribute [r] subject
36
+ #
37
+ # @return [#object_id] The front object to test.
38
+ attr_reader :subject
39
+
40
+ # @!attribute [r] challenges
41
+ #
42
+ # @return [Array] A list of challenges.
43
+ attr_reader :challenges
44
+
27
45
  protected
28
46
 
29
47
  # @param state [Sandbox] The sandbox that tested the code.
30
48
  #
31
49
  # @return [Result::Pass] Pass the spec.
32
50
  def pass!(state)
33
- Result::Pass.new(message(state, true), *result_signature(state))
51
+ msg = Report.new(req, negate?, state, true)
52
+
53
+ Result::Pass.new(msg, *result_signature(state))
34
54
  end
35
55
 
36
56
  # @param state [Sandbox] The sandbox that tested the code.
37
57
  #
38
58
  # @raise [Result::Fail] Fail the spec.
39
59
  def fail!(state)
40
- fail Result::Fail.new(message(state, false), *result_signature(state)),
41
- message(state, false), caller[2..-1]
60
+ msg = Report.new(req, negate?, state, false)
61
+
62
+ fail Result::Fail.new(msg, *result_signature(state)), msg, caller[2..-1]
42
63
  end
43
64
 
44
65
  # @param state [Sandbox] The sandbox that tested the code.
@@ -46,14 +67,14 @@ module Spectus
46
67
  # @return [Array] List of parameters.
47
68
  def result_signature(state)
48
69
  [
49
- @subject,
70
+ subject,
50
71
  state.last_challenge,
51
72
  state.actual,
52
- @req,
73
+ req,
53
74
  state.got,
54
75
  state.exception,
55
76
  level,
56
- @negate,
77
+ negate?,
57
78
  state.valid?
58
79
  ]
59
80
  end
@@ -65,69 +86,17 @@ module Spectus
65
86
 
66
87
  # @return [Sandbox] The sandbox.
67
88
  def sandbox
68
- if Process.respond_to?(:fork)
69
- fork_and_return { Sandbox.new(@req, @negate, @subject, *@challenges) }
70
- else
71
- Sandbox.new(@req, @negate, @subject, *@challenges)
72
- end
89
+ Process.respond_to?(:fork) ? fork_and_return { execute } : execute
73
90
  end
74
91
 
75
- # @param state [Sandbox] The sandbox that tested the code.
76
- # @param result [Boolean] The result of the test.
77
- #
78
- # @return [String] The message that describe the state.
79
- def message(state, result)
80
- "#{title(state, result)}: #{summary(state)}."
81
- end
82
-
83
- # The title of the state.
84
- #
85
- # @param state [Sandbox] The sandbox that tested the code.
86
- # @param result [Boolean] The result of the test.
87
- #
88
- # @return [String] The title of the state.
89
- def title(state, result)
90
- if result
91
- state.got ? 'Pass' : 'Info'
92
- else
93
- state.exception.nil? ? 'Failure' : 'Error'
94
- end
95
- end
96
-
97
- # The summary of the state.
98
- #
99
- # @param state [Sandbox] The sandbox that tested the code.
100
- #
101
- # @return [String] The summary of the state.
102
- def summary(state)
103
- if state.valid? || state.exception.nil?
104
- 'Expected ' + state.actual.inspect + (@negate ? ' not ' : ' ') +
105
- 'to ' + if @req.is_a?(Hash)
106
- readable(@req.keys.first) + ' ' +
107
- @req.values.first.inspect
108
- else
109
- readable(@req)
110
- end
111
- else
112
- state.exception.message
113
- end + (state.exception.nil? ? '' : " (#{state.exception.class})")
114
- end
115
-
116
- # @param st [#to_s] A UpperCamelCase string.
117
- #
118
- # @return [String] The snake_case string.
119
- def readable(st)
120
- st.to_s
121
- .gsub(/::/, '/')
122
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
123
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
124
- .tr('-_', ' ')
125
- .downcase
92
+ # @return [Sandbox] The sandbox.
93
+ def execute
94
+ Sandbox.new(req, negate?, subject, *challenges)
126
95
  end
127
96
 
128
97
  # Run the code in a separate process.
129
98
  #
130
- # @api private
99
+ # @yieldreturn [Sandbox] Execute the untested code in the sandbox.
131
100
  def fork_and_return
132
101
  read, write = IO.pipe
133
102
 
@@ -146,3 +115,8 @@ module Spectus
146
115
  end
147
116
  end
148
117
  end
118
+
119
+ require_relative File.join '..', 'report'
120
+ require_relative File.join '..', 'result', 'fail'
121
+ require_relative File.join '..', 'result', 'pass'
122
+ require_relative File.join '..', 'sandbox'
@@ -0,0 +1,110 @@
1
+ module Spectus
2
+ # The class that is responsible for reporting the result of the test.
3
+ #
4
+ # @api private
5
+ #
6
+ class Report
7
+ # Initialize the report class.
8
+ #
9
+ # @param req [Hash, Symbol] The definition of the expected value.
10
+ # @param negate [Boolean] Evaluate to a negative assertion.
11
+ # @param state [Sandbox] The sandbox that tested the code.
12
+ # @param result [Boolean] The result of the test.
13
+ def initialize(req, negate, state, result)
14
+ @req = req
15
+ @negate = negate
16
+ @state = state
17
+ @result = result
18
+ end
19
+
20
+ # @!attribute [r] req
21
+ #
22
+ # @return [Hash, Symbol] The definition of the expected value.
23
+ attr_reader :req
24
+
25
+ # The value of the negate instance variable.
26
+ #
27
+ # @return [Boolean] Evaluated to a negative assertion or not.
28
+ def negate?
29
+ @negate
30
+ end
31
+
32
+ # @!attribute [r] state
33
+ #
34
+ # @return [Sandbox] The sandbox that tested the code.
35
+ attr_reader :state
36
+
37
+ # @!attribute [r] result
38
+ #
39
+ # @return [Boolean] The result of the test.
40
+ attr_reader :result
41
+
42
+ # The message.
43
+ #
44
+ # @return [String] The message that describe the state.
45
+ def to_s
46
+ "#{title}: #{summary}#{maybe_exception}."
47
+ end
48
+
49
+ # The title of the state.
50
+ #
51
+ # @return [String] The title of the state.
52
+ def title
53
+ if result
54
+ state.got ? 'Pass' : 'Info'
55
+ else
56
+ state.exception.nil? ? 'Failure' : 'Error'
57
+ end
58
+ end
59
+
60
+ # The summary of the state.
61
+ #
62
+ # @return [String] The summary of the state.
63
+ def summary
64
+ return state.exception.message unless state.valid? || state.exception.nil?
65
+
66
+ 'Expected ' + state.actual.inspect + maybe_negate + ' to ' + definition
67
+ end
68
+
69
+ # The negation, if any.
70
+ #
71
+ # @return [String] The negation, or an empty string.
72
+ def maybe_negate
73
+ negate? ? ' not' : ''
74
+ end
75
+
76
+ # The type of exception, if any.
77
+ #
78
+ # @return [String] The type of exception, or an empty string.
79
+ def maybe_exception
80
+ state.exception.nil? ? '' : " (#{state.exception.class})"
81
+ end
82
+
83
+ # The readable definition.
84
+ #
85
+ # @return [String] The readable definition string.
86
+ def definition
87
+ if req.is_a?(Hash)
88
+ snake_case(req.keys.first) + ' ' + req.values.first.inspect
89
+ else
90
+ snake_case(req)
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ # @api private
97
+ #
98
+ # @param st [#to_s] An UpperCamelCase string.
99
+ #
100
+ # @return [String] The snake_case string.
101
+ def snake_case(st)
102
+ st.to_s
103
+ .gsub(/::/, '/')
104
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
105
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
106
+ .tr('-_', ' ')
107
+ .downcase
108
+ end
109
+ end
110
+ end
@@ -9,7 +9,7 @@ module Spectus
9
9
  module Base
10
10
  # Initialize the result class.
11
11
  #
12
- # @param message [String] It is describing the actual/error value.
12
+ # @param message [#to_s] It is describing the actual/error value.
13
13
  # @param subject [#object_id] The untrusted object to be tested.
14
14
  # @param challenge [Defi::Challenge] The challenge for the subject.
15
15
  # @param actual [#object_id] The value that the subject return through
@@ -24,7 +24,7 @@ module Spectus
24
24
  def initialize(message, subject, challenge, actual, expected, got, error,
25
25
  level, negate, valid)
26
26
 
27
- @message = message
27
+ @message = message.to_s
28
28
  @subject = subject
29
29
  @challenge = challenge
30
30
  @actual = actual
@@ -52,7 +52,7 @@ module Spectus
52
52
  if defined?(@exception)
53
53
  false
54
54
  else
55
- @got
55
+ got
56
56
  end
57
57
  end
58
58
 
data/spectus.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'rake', '~> 10.4'
22
22
  spec.add_development_dependency 'yard', '~> 0.8'
23
23
  spec.add_development_dependency 'simplecov', '~> 0.10'
24
- spec.add_development_dependency 'rubocop', '~> 0.32'
24
+ spec.add_development_dependency 'rubocop', '~> 0.34'
25
25
 
26
26
  spec.cert_chain = ['certs/gem-fixrb-public_cert.pem']
27
27
  private_key = File.expand_path('~/.ssh/gem-fixrb-private_key.pem')
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.7.1
4
+ version: 2.8.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-10-09 00:00:00.000000000 Z
33
+ date: 2015-10-10 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: defi
@@ -122,14 +122,14 @@ dependencies:
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0.32'
125
+ version: '0.34'
126
126
  type: :development
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '0.32'
132
+ version: '0.34'
133
133
  description: Expectation library with RFC 2119's requirement levels.
134
134
  email:
135
135
  - contact@cyril.email
@@ -139,6 +139,7 @@ extra_rdoc_files: []
139
139
  files:
140
140
  - ".gitignore"
141
141
  - ".rubocop.yml"
142
+ - ".rubocop_todo.yml"
142
143
  - ".travis.yml"
143
144
  - ".yardopts"
144
145
  - CODE_OF_CONDUCT.md
@@ -166,12 +167,14 @@ files:
166
167
  - checksum/spectus-2.5.0.gem.sha512
167
168
  - checksum/spectus-2.6.0.gem.sha512
168
169
  - checksum/spectus-2.7.0.gem.sha512
170
+ - checksum/spectus-2.7.1.gem.sha512
169
171
  - lib/spectus.rb
170
172
  - lib/spectus/expectation_target.rb
171
173
  - lib/spectus/level/base.rb
172
174
  - lib/spectus/level/high.rb
173
175
  - lib/spectus/level/low.rb
174
176
  - lib/spectus/level/medium.rb
177
+ - lib/spectus/report.rb
175
178
  - lib/spectus/result/base.rb
176
179
  - lib/spectus/result/fail.rb
177
180
  - lib/spectus/result/pass.rb
@@ -198,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
201
  version: '0'
199
202
  requirements: []
200
203
  rubyforge_project:
201
- rubygems_version: 2.4.5
204
+ rubygems_version: 2.4.5.1
202
205
  signing_key:
203
206
  specification_version: 4
204
207
  summary: Expectation library with RFC 2119 keywords.
metadata.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- 0c�):����#M�'��gR� ��������u���~Л.hƾ}����rÙ�yֶQ�.��8�)����� +}k�c��IP�e'�����bG
2
- �|<.��8xF��v?�Z��,�5qf<g�/��[��8������Ta��D�����_�?Q-#����ʁ�
3
- �j̍�,�%8|�9�/��-: v=K,ut��@�)ԯ��ۥƞ���'jz'îx7���� O����ܳI����}Jgb������`�5��ك��EidD'
1
+ ��'A!H���?r
2
+ �����>�n�O���.e�����ė銗 �.�:��X �
3
+ ����TuZ)O �ۊ�����ʍ���s����w��N:ɤ֋�뜗��`Dl ���/�b ��>P�{{�ctn��󩇍����,ю�\�����"3��W�kD��~��!%�N�e��h�ӫ�tMb�l��~�6�.㌔>�<Q��*,���:��C\�wz w��>^�� 5���W���b�qj��h�}iv�S"�q��4@