spectus 2.3.1 → 2.4.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: 10444e2f0561290610775d4d723f309c435180c6
4
- data.tar.gz: f31d8b2d8ce45b2f5bf63cbc180b957b4d760688
3
+ metadata.gz: dbcd04aaa8066c8ff3195c36b283169b10530296
4
+ data.tar.gz: b68284b11d486d8a0cec19bcdecd65adcf7bb674
5
5
  SHA512:
6
- metadata.gz: 9e3379bf0a32258ed4ec0d3d3baecc658f9ffd190245a6ecac454a6c99f1c05c73dd633b6d5a1546e017dd2572f92767bafb6ed65dea6fe0bbac82695ecf4034
7
- data.tar.gz: dcd9c3268a0bb38d05393c5a6b4932cf6dffc3d24d06783050509f8b1c40af65d31712786b5a64a62fb1c2fb7396554402e1fbc6e0575c5ca4e4aa0c6122c2ec
6
+ metadata.gz: 74cf34427dc5b39763a3bfb2f32469ff0e78013e54afb5218b3ac3555ff8357cd95fc0d097862ff4108beeaeab4a63746291865399e854732b84750a0bb912d1
7
+ data.tar.gz: 4ca5afde6ac2c85272caa1256ef4847d305f4aa045ed6369d9acc85bdd1aab192c9ec3bbc8538f9b68e2fa571b0ab2ccdd3831ac83013c1fba79fa8263207c4c
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- ْ���37GG����1�Pz�d�� W�r��f�Ǹ�Ї��l$ +ۣ߉C�e�,��3�ȏ�_��R�)��G���q�ʹ&>b&]�+�ٱ�_J�`�V8�+�89Ȝs����&��;V0�Y KOJ`r|\���=���Abg�m��l;]�+��4|�D����)T�_����$R�a4s���ɛ�PAs��nT��:WJ[>%�7c�t��D�����f����() ������A�M�uVr ���z�
1
+ �-�J�},�6����X\7:�: BE)9�:��)I�=dò���e��X�!+��U�~ ������Y��s����X_q���,sC��8�/��9w��ى�;p�Y�����i�%�aY��%=��&��?�Km�\-"r&��',��,uC�o �Ȇ0[PB���?�ߟPft?z��)��k<��`q��u�[Kf2������+��i�t��)��a��g�#d�Oe`���:򚜤]���
2
+ )�+� ���� P�
data/README.md CHANGED
@@ -68,7 +68,7 @@ Given the `"ルビー"` object, when it receives `valid_encoding?` method, then
68
68
 
69
69
  ```ruby
70
70
  Spectus.this { 'ルビー'.valid_encoding? }.MUST :BeTrue
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>
71
+ # => #<Spectus::Result::Pass:0x007fec19b1d638 @message="Pass: Expected true to be true.", @subject=#<Proc:0x007fec19b1e470@(irb):1>, @challenge=#<Spectus::Challenge:0x007fec19b1e3a8 @method=:call, @args=[]>, @actual=true, @expected=:BeTrue, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
72
72
  ```
73
73
 
74
74
  The result of the test shows that the spec passed.
@@ -79,7 +79,7 @@ Given the `"foo"` object, when it receives `length` method, then it **MUST NOT**
79
79
 
80
80
  ```ruby
81
81
  Spectus.this { 'foo'.length }.MUST_NOT RaiseException: NoMethodError
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>
82
+ # => #<Spectus::Result::Pass:0x007fec193a0fe0 @message="Pass: Expected 3 not to raise exception NoMethodError.", @subject=#<Proc:0x007fec193a1a08@(irb):2>, @challenge=#<Spectus::Challenge:0x007fec193a19b8 @method=:call, @args=[]>, @actual=3, @expected={:RaiseException=>NoMethodError}, @got=true, @error=nil, @level=:High, @negate=true, @valid=true>
83
83
  ```
84
84
 
85
85
  The result of the test shows that the spec passed.
@@ -90,7 +90,7 @@ Given the `BasicObject` object, when it receives `superclass` method, then it **
90
90
 
91
91
  ```ruby
92
92
  Spectus.this { BasicObject.superclass }.SHOULD Equal: NilClass
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>
93
+ # => #<Spectus::Result::Pass:0x007fec193b2ec0 @message="Info: Expected nil to equal NilClass.", @subject=#<Proc:0x007fec193b37f8@(irb):3>, @challenge=#<Spectus::Challenge:0x007fec193b37a8 @method=:call, @args=[]>, @actual=nil, @expected={:Equal=>NilClass}, @got=false, @error=nil, @level=:Medium, @negate=false, @valid=false>
94
94
  ```
95
95
 
96
96
  Instead of the expected `NilClass` class, its sole instance (which is `nil`) was returned.
@@ -115,7 +115,7 @@ Given the `"foo"` object, when it receives `blank?` method, then it **MAY** be `
115
115
 
116
116
  ```ruby
117
117
  Spectus.this { 'foo'.blank? }.MAY :BeFalse
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>
118
+ # => #<Spectus::Result::Pass:0x007fec19423af8 @message="Info: undefined method `blank?' for \"foo\":String (NoMethodError).", @subject=#<Proc:0x007fec193f0270@(irb):5>, @challenge=#<Spectus::Challenge:0x007fec193f0220 @method=:call, @args=[]>, @actual=nil, @expected=:BeFalse, @got=nil, @error=#<NoMethodError: undefined method `blank?' for "foo":String>, @level=:Low, @negate=false, @valid=false>
119
119
  ```
120
120
 
121
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.
data/VERSION.semver CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.4.0
@@ -0,0 +1 @@
1
+ c73bf4fc985ec06dd7876d394d32c27028e7475d77262e1f0bd4a57e688af327e4658bdc926662a43895aaf8b9b4d56404cd0720ef90c9b69090f27505863f9d
@@ -6,21 +6,28 @@ module Spectus
6
6
  class Challenge
7
7
  # Initialize the challenge class.
8
8
  #
9
- # @param [#to_sym] method_id the identifier of a method.
10
- # @param [Array] args the arguments of the method.
11
- def initialize(method_id, *args)
12
- @symbol = method_id.to_sym
9
+ # @param method [#to_sym] The identifier of a method.
10
+ # @param args [Array] The arguments of the method.
11
+ def initialize(method, *args)
12
+ @method = method.to_sym
13
13
  @args = args
14
14
  end
15
15
 
16
- # @!attribute [r] symbol
16
+ # @param object [#public_send] The subject of the challenge.
17
17
  #
18
- # @return [Symbol] The method to call on the subject.
19
- attr_reader :symbol
18
+ # @return [BasicObject] The result of the challenge.
19
+ def to(object)
20
+ object.public_send(@method, *@args)
21
+ end
20
22
 
21
- # @!attribute [r] args
23
+ # Properties of the challenge.
22
24
  #
23
- # @return [Array] The parameters following the method.
24
- attr_reader :args
25
+ # @return [Hash] The properties of the challenge.
26
+ def to_h
27
+ {
28
+ method: @method,
29
+ args: @args
30
+ }
31
+ end
25
32
  end
26
33
  end
@@ -11,10 +11,10 @@ module Spectus
11
11
  class ExpectationTarget < BasicObject
12
12
  # Create a new expection target
13
13
  #
14
- # @param subject [Proc] the value which is compared with the expected value.
14
+ # @param subject [Proc] The value which is compared with the expected value.
15
15
  def initialize(&subject)
16
16
  @subject = subject
17
- @challenge = Challenge.new(:call)
17
+ @challenges = [Challenge.new(:call)]
18
18
  end
19
19
 
20
20
  # @!attribute [r] subject
@@ -22,10 +22,10 @@ module Spectus
22
22
  # @return [BasicObject] The front object to be tested.
23
23
  attr_reader :subject
24
24
 
25
- # @!attribute [r] challenge
25
+ # @!attribute [r] challenges
26
26
  #
27
- # @return [Challenge] The challenge to call on the subject.
28
- attr_reader :challenge
27
+ # @return [Array] The challenges to call on the subject.
28
+ attr_reader :challenges
29
29
 
30
30
  # This word, or the terms "REQUIRED" or "SHALL", mean that the
31
31
  # definition is an absolute requirement of the specification.
@@ -33,11 +33,11 @@ module Spectus
33
33
  # @example _Absolute requirement_ definition
34
34
  # this { 'foo'.upcase }.MUST Eql: 'FOO'
35
35
  #
36
- # @param definition [Array, Hash, Symbol]
36
+ # @param req [Array, Hash, Symbol]
37
37
  #
38
- # @return [Result::Fail, Result::Pass] report if the spec pass or fail.
39
- def MUST(definition)
40
- RequirementLevel::High.new(definition, false, subject, challenge).result
38
+ # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
39
+ def MUST(req)
40
+ RequirementLevel::High.new(req, false, subject, *challenges).result
41
41
  end
42
42
 
43
43
  # This phrase, or the phrase "SHALL NOT", mean that the
@@ -46,11 +46,11 @@ module Spectus
46
46
  # @example _Absolute prohibition_ definition
47
47
  # this { 'foo'.size }.MUST_NOT Equal: 42
48
48
  #
49
- # @param definition [Array, Hash, Symbol]
49
+ # @param req [Array, Hash, Symbol]
50
50
  #
51
- # @return [Result::Fail, Result::Pass] report if the spec pass or fail.
52
- def MUST_NOT(definition)
53
- RequirementLevel::High.new(definition, true, subject, challenge).result
51
+ # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
52
+ def MUST_NOT(req)
53
+ RequirementLevel::High.new(req, true, subject, *challenges).result
54
54
  end
55
55
 
56
56
  # This word, or the adjective "RECOMMENDED", mean that there
@@ -61,11 +61,11 @@ module Spectus
61
61
  # @example _Recommended_ definition
62
62
  # this { 'foo'.valid_encoding? }.SHOULD Equal: true
63
63
  #
64
- # @param definition [Array, Hash, Symbol]
64
+ # @param req [Array, Hash, Symbol]
65
65
  #
66
- # @return [Result::Fail, Result::Pass] report if the spec pass or fail.
67
- def SHOULD(definition)
68
- RequirementLevel::Medium.new(definition, false, subject, challenge).result
66
+ # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
67
+ def SHOULD(req)
68
+ RequirementLevel::Medium.new(req, false, subject, *challenges).result
69
69
  end
70
70
 
71
71
  # This phrase, or the phrase "NOT RECOMMENDED" mean that
@@ -77,11 +77,11 @@ module Spectus
77
77
  # @example _Not recommended_ definition
78
78
  # this { ''.blank? }.SHOULD_NOT RaiseException: NoMethodError
79
79
  #
80
- # @param definition [Array, Hash, Symbol]
80
+ # @param req [Array, Hash, Symbol]
81
81
  #
82
- # @return [Result::Fail, Result::Pass] report if the spec pass or fail.
83
- def SHOULD_NOT(definition)
84
- RequirementLevel::Medium.new(definition, true, subject, challenge).result
82
+ # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
83
+ def SHOULD_NOT(req)
84
+ RequirementLevel::Medium.new(req, true, subject, *challenges).result
85
85
  end
86
86
 
87
87
  # This word, or the adjective "OPTIONAL", mean that an item is
@@ -99,11 +99,11 @@ module Spectus
99
99
  # @example _Optional_ definition
100
100
  # this { 'foo'.bar }.MAY Match: /^foo$/
101
101
  #
102
- # @param definition [Array, Hash, Symbol]
102
+ # @param req [Array, Hash, Symbol]
103
103
  #
104
- # @return [Result::Fail, Result::Pass] report if the spec pass or fail.
105
- def MAY(definition)
106
- RequirementLevel::Low.new(definition, false, subject, challenge).result
104
+ # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
105
+ def MAY(req)
106
+ RequirementLevel::Low.new(req, false, subject, *challenges).result
107
107
  end
108
108
  end
109
109
  end
@@ -13,30 +13,29 @@ module Spectus
13
13
  class Base
14
14
  # Initialize the requirement level class.
15
15
  #
16
- # @param definition [Array, Hash, Symbol] The definition of the expected
17
- # value.
18
- # @param negate [Boolean] Evaluate to a negative assertion.
19
- # @param subject [#object_id] the front object to test.
20
- # @param challenge [Challenge] a challenge for the subject.
21
- def initialize(definition, negate, subject, challenge)
22
- @definition = definition
16
+ # @param req [Hash, Symbol] The definition of the expected value.
17
+ # @param negate [Boolean] Evaluate to a negative assertion.
18
+ # @param subject [#object_id] The front object to test.
19
+ # @param challenges [Array] A list of challenges.
20
+ def initialize(req, negate, subject, *challenges)
21
+ @req = req
23
22
  @negate = negate
24
23
  @subject = subject
25
- @challenge = challenge
24
+ @challenges = challenges
26
25
  end
27
26
 
28
27
  protected
29
28
 
30
29
  # @param state [Sandbox] The sandbox that tested the code.
31
30
  #
32
- # @return [Result::Pass] pass the spec.
31
+ # @return [Result::Pass] Pass the spec.
33
32
  def pass!(state)
34
33
  Result::Pass.new(message(state, true), *result_signature(state))
35
34
  end
36
35
 
37
36
  # @param state [Sandbox] The sandbox that tested the code.
38
37
  #
39
- # @raise [Result::Fail] fail the spec.
38
+ # @raise [Result::Fail] Fail the spec.
40
39
  def fail!(state)
41
40
  fail Result::Fail.new(message(state, false), *result_signature(state)),
42
41
  message(state, false), caller[2..-1]
@@ -44,14 +43,13 @@ module Spectus
44
43
 
45
44
  # @param state [Sandbox] The sandbox that tested the code.
46
45
  #
47
- # @return [Array] list of parameters.
46
+ # @return [Array] List of parameters.
48
47
  def result_signature(state)
49
48
  [
50
49
  @subject,
51
- @challenge.symbol,
52
- @challenge.args,
50
+ state.last_challenge,
53
51
  state.actual,
54
- @definition,
52
+ @req,
55
53
  state.got,
56
54
  state.exception,
57
55
  level,
@@ -60,44 +58,35 @@ module Spectus
60
58
  ]
61
59
  end
62
60
 
63
- # @return [Symbol] the requirement level.
61
+ # @return [Symbol] The requirement level.
64
62
  def level
65
63
  self.class.name.split('::').last.to_sym
66
64
  end
67
65
 
68
- # @return [Sandbox] the sandbox.
66
+ # @return [Sandbox] The sandbox.
69
67
  def sandbox
70
- Sandbox.new(@definition, @negate, @subject, @challenge.symbol,
71
- *@challenge.args)
68
+ Sandbox.new(@req, @negate, @subject, *@challenges)
72
69
  end
73
70
 
74
71
  # @param state [Sandbox] The sandbox that tested the code.
75
72
  # @param result [Boolean] The result of the test.
76
73
  #
77
- # @return [String] the message that describe the state.
74
+ # @return [String] The message that describe the state.
78
75
  def message(state, result)
79
76
  "#{title(state, result)}: #{summary(state)}."
80
77
  end
81
78
 
82
79
  # The title of the state.
83
80
  #
84
- # @param state [Sandbox] The sandbox that tested the code.
81
+ # @param state [Sandbox] The sandbox that tested the code.
85
82
  # @param result [Boolean] The result of the test.
86
83
  #
87
- # @return [String] the title of the state.
84
+ # @return [String] The title of the state.
88
85
  def title(state, result)
89
86
  if result
90
- if state.got
91
- 'Pass'
92
- else
93
- 'Info'
94
- end
87
+ state.got ? 'Pass' : 'Info'
95
88
  else
96
- if state.exception.nil?
97
- 'Failure'
98
- else
99
- 'Error'
100
- end
89
+ state.exception.nil? ? 'Failure' : 'Error'
101
90
  end
102
91
  end
103
92
 
@@ -105,30 +94,27 @@ module Spectus
105
94
  #
106
95
  # @param state [Sandbox] The sandbox that tested the code.
107
96
  #
108
- # @return [String] the summary of the state.
97
+ # @return [String] The summary of the state.
109
98
  def summary(state)
110
99
  if state.valid? || state.exception.nil?
111
100
  '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}"
101
+ 'to ' + if @req.is_a?(Hash)
102
+ readable(@req.keys.first) + ' ' +
103
+ @req.values.first.inspect
115
104
  else
116
- readable(@definition.to_s)
105
+ readable(@req)
117
106
  end
118
107
  else
119
108
  state.exception.message
120
- end + if state.exception.nil?
121
- ''
122
- else
123
- " (#{state.exception.class})"
124
- end
109
+ end + (state.exception.nil? ? '' : " (#{state.exception.class})")
125
110
  end
126
111
 
127
- # @param string [String] A UpperCamelCase string.
112
+ # @param st [#to_s] A UpperCamelCase string.
128
113
  #
129
- # @return [String] the snake_case string.
130
- def readable(string)
131
- string.gsub(/::/, '/')
114
+ # @return [String] The snake_case string.
115
+ def readable(st)
116
+ st.to_s
117
+ .gsub(/::/, '/')
132
118
  .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
133
119
  .gsub(/([a-z\d])([A-Z])/, '\1_\2')
134
120
  .tr('-_', ' ')
@@ -9,7 +9,7 @@ module Spectus
9
9
  class High < Base
10
10
  # Evaluate the expectation.
11
11
  #
12
- # @return [Result::Fail, Result::Pass] report if the high expectation
12
+ # @return [Result::Fail, Result::Pass] Report if the high expectation
13
13
  # pass or fail.
14
14
  def result
15
15
  state = sandbox
@@ -9,7 +9,7 @@ module Spectus
9
9
  class Low < Base
10
10
  # Evaluate the expectation.
11
11
  #
12
- # @return [Result::Fail, Result::Pass] report if the low expectation
12
+ # @return [Result::Fail, Result::Pass] Report if the low expectation
13
13
  # pass or fail.
14
14
  def result
15
15
  state = sandbox
@@ -9,7 +9,7 @@ module Spectus
9
9
  class Medium < Base
10
10
  # Evaluate the expectation.
11
11
  #
12
- # @return [Result::Fail, Result::Pass] report if the medium expectation
12
+ # @return [Result::Fail, Result::Pass] Report if the medium expectation
13
13
  # pass or fail.
14
14
  def result
15
15
  state = sandbox
@@ -11,25 +11,22 @@ module Spectus
11
11
  #
12
12
  # @param message [String] It is describing the actual/error value.
13
13
  # @param subject [#object_id] The untrusted object to be tested.
14
- # @param challenge [Symbol] The method to call on the subject.
15
- # @param context [Array] Parameters of the challenge.
14
+ # @param challenge [Challenge] The method to call on the subject.
16
15
  # @param actual [#object_id] The value that the subject return through
17
16
  # its challenge.
18
- # @param expected [Array, Hash, Symbol] The definition of the expected
19
- # value.
17
+ # @param expected [Hash, Symbol] The definition of the expected value.
20
18
  # @param got [#object_id] The result of the boolean comparison
21
19
  # between the actual value and the expected value.
22
20
  # @param error [#exception, nil] Any possible raised exception.
23
21
  # @param level [:High, :Medium, :Low] The level of the expectation.
24
22
  # @param negate [Boolean] Evaluate to a negative assertion.
25
23
  # @param valid [Boolean] Report if the test was true or false.
26
- def initialize(message, subject, challenge, context, actual, expected,
27
- got, error, level, negate, valid)
24
+ def initialize(message, subject, challenge, actual, expected, got, error,
25
+ level, negate, valid)
28
26
 
29
27
  @message = message
30
28
  @subject = subject
31
29
  @challenge = challenge
32
- @context = context
33
30
  @actual = actual
34
31
  @expected = expected
35
32
  @got = got
@@ -49,11 +46,6 @@ module Spectus
49
46
  # @return [Symbol] The method to call on the subject.
50
47
  attr_reader :challenge
51
48
 
52
- # @!attribute [r] context
53
- #
54
- # @return [Array] Parameters of the challenge.
55
- attr_reader :context
56
-
57
49
  # @!attribute [r] actual
58
50
  #
59
51
  # @return [#object_id] The value that the subject return through its
@@ -83,7 +75,7 @@ module Spectus
83
75
 
84
76
  # The value of the negate instance variable.
85
77
  #
86
- # @return [Boolean] evaluated to a negative assertion or not.
78
+ # @return [Boolean] Evaluated to a negative assertion or not.
87
79
  def negate?
88
80
  @negate
89
81
  end
@@ -91,19 +83,18 @@ module Spectus
91
83
  # The value of the boolean comparison between the actual value and the
92
84
  # expected value.
93
85
  #
94
- # @return [Boolean] the test was true or false.
86
+ # @return [Boolean] The test was true or false.
95
87
  def valid?
96
88
  @valid
97
89
  end
98
90
 
99
91
  # Properties of the result.
100
92
  #
101
- # @return [Hash] the properties of the result.
93
+ # @return [Hash] The properties of the result.
102
94
  def to_h
103
95
  {
104
96
  subject: subject,
105
- challenge: challenge,
106
- context: context,
97
+ challenge: challenge.to_h,
107
98
  actual: actual,
108
99
  expected: expected,
109
100
  got: got,
@@ -8,14 +8,14 @@ module Spectus
8
8
 
9
9
  # The value of the expectation of the spec.
10
10
  #
11
- # @return [Boolean] the spec was false.
11
+ # @return [Boolean] The spec was false.
12
12
  def result?
13
13
  false
14
14
  end
15
15
 
16
16
  # Identify the state of the result.
17
17
  #
18
- # @return [String] the char that identify the state of the result.
18
+ # @return [String] The char that identify the state of the result.
19
19
  def to_char
20
20
  if error.nil?
21
21
  'F'
@@ -13,14 +13,14 @@ module Spectus
13
13
 
14
14
  # The value of the expectation of the spec.
15
15
  #
16
- # @return [Boolean] the spec was true.
16
+ # @return [Boolean] The spec was true.
17
17
  def result?
18
18
  true
19
19
  end
20
20
 
21
21
  # Identify the state of the result.
22
22
  #
23
- # @return [String] the char that identify the state of the result.
23
+ # @return [String] The char that identify the state of the result.
24
24
  def to_char
25
25
  if got
26
26
  '.'
@@ -8,19 +8,26 @@ module Spectus
8
8
  class Sandbox
9
9
  # Execute the untested code from the passed block against the definition.
10
10
  #
11
- # @param [Array, Hash, Symbol] definition
12
- # @param [Boolean] negate
13
- # @param [#object_id] object the front object which is challenged.
14
- # @param [Symbol] meth the name of the method.
15
- # @param [Array] args the arguments of the method.
16
- def initialize(definition, negate, object, meth, *args)
11
+ # @param definition [Hash, Symbol] Definition.
12
+ # @param negate [Boolean] Negate the expectation result.
13
+ # @param object [#object_id] The front object which is challenged.
14
+ # @param challenges [Array] The list of challenges.
15
+ def initialize(definition, negate, object, *challenges)
17
16
  @got = negate ^ matcher(definition).matches? do
18
- @actual = object.public_send(meth, *args)
17
+ @actual = challenges.inject(object) do |subject, challenge|
18
+ @last_challenge = challenge
19
+ @last_challenge.to(subject)
20
+ end
19
21
  end
20
22
  rescue => e
21
23
  @exception = e
22
24
  end
23
25
 
26
+ # @!attribute [r] last_challenge
27
+ #
28
+ # @return [Challenge] The last evaluated challenge.
29
+ attr_reader :last_challenge
30
+
24
31
  # @!attribute [r] actual
25
32
  #
26
33
  # @return [#object_id] The value that the subject return through its
@@ -55,7 +62,7 @@ module Spectus
55
62
  #
56
63
  # @param definition [Array, Hash, Symbol]
57
64
  #
58
- # @return [#matches?] the matcher
65
+ # @return [#matches?] The matcher.
59
66
  def matcher(definition)
60
67
  params = Array(definition).flatten(1)
61
68
  Matchi.fetch(params.first, *params[1..-1])
data/lib/spectus.rb CHANGED
@@ -9,12 +9,12 @@ require_relative File.join 'spectus', 'expectation_target'
9
9
  module Spectus
10
10
  # Expectations are built with this method.
11
11
  #
12
- # @example Absolute requirement definition
12
+ # @example _Absolute requirement_ definition
13
13
  # this { 42 }.MUST Equal: 42 # => #<Spectus::Result::Pass...>
14
14
  #
15
- # @param input [Proc] the code to test.
15
+ # @param input [Proc] The code to test.
16
16
  #
17
- # @return [ExpectationTarget] the expectation target.
17
+ # @return [ExpectationTarget] The expectation target.
18
18
  def self.this(&input)
19
19
  ExpectationTarget.new(&input)
20
20
  end
data/spectus.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
15
15
  spec.require_paths = ['lib']
16
16
 
17
- spec.add_dependency 'matchi', '~> 0.0'
17
+ spec.add_dependency 'matchi', '~> 0.0.9'
18
18
 
19
19
  spec.add_development_dependency 'bundler', '~> 1.10'
20
20
  spec.add_development_dependency 'rake', '~> 10.4'
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.3.1
4
+ version: 2.4.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-24 00:00:00.000000000 Z
33
+ date: 2015-09-10 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: matchi
@@ -38,14 +38,14 @@ dependencies:
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0.0'
41
+ version: 0.0.9
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.0'
48
+ version: 0.0.9
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: bundler
51
51
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +147,7 @@ files:
147
147
  - checksum/spectus-2.1.3.gem.sha512
148
148
  - checksum/spectus-2.2.0.gem.sha512
149
149
  - checksum/spectus-2.3.0.gem.sha512
150
+ - checksum/spectus-2.3.1.gem.sha512
150
151
  - lib/spectus.rb
151
152
  - lib/spectus/challenge.rb
152
153
  - lib/spectus/expectation_target.rb
metadata.gz.sig CHANGED
Binary file