spectus 2.10.0 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfcbf350bb48d6622bcfdc564ee7a9908e1d0339
4
- data.tar.gz: fd04d8e59ed8c78246f5a647e293c49e0e9dba97
3
+ metadata.gz: 31ef6ee6737598afad47492b26efadd3a2b47f6a
4
+ data.tar.gz: 9284aeab67d2c5648ce9a89c0a61ecd33470db69
5
5
  SHA512:
6
- metadata.gz: 1960978b6ba9f518fdb09af4d97cad7ac42b9c172ac386e19ca70d036948384349f5c9cddf762f668bc49446f013571bcd3e94e31ed2739eef37ef0763ef9c29
7
- data.tar.gz: 0ce52d6e6c8561b388f1277f74f348b8bd8e238dd09758127752022897bcec3b831b60e24a525b914ecf871cab35419aba8116a832f2efc8020d597eb65bf90b
6
+ metadata.gz: 18466599af7ec896dc1a7ea02c1c3eefc2f4b954bd5e6858357a2bb349164f654df705c307de0bc765539d5f4ba57754247117a1200c46dae77ab0dac9001221
7
+ data.tar.gz: 3ad1d7be4761e0072168921245c0fd726720db3cd17634795a4491dd78e3a09e74c2299aae5276774964ca650c4656461b4561203aff78bbd67e584faf7992af
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -62,8 +62,8 @@ Example of test in isolation:
62
62
 
63
63
  ```ruby
64
64
  greeting = 'Hello, world!'
65
- Spectus.this { greeting.gsub!('world', 'Alice') }.MUST! Eql: 'Hello, Alice!'
66
- # => #<Spectus::Result::Pass:0x007fd6312e5310 @message="Pass: Expected \"Hello, Alice!\" to eql \"Hello, Alice!\".", @subject=#<Proc:0x007fd6312e6238@(irb):2>, @challenge=#<Defi::Challenge:0x007fd6312e59c8 @method=:call, @args=[]>, @actual="Hello, Alice!", @expected={:Eql=>"Hello, Alice!"}, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
65
+ it { greeting.gsub!('world', 'Alice') }.MUST! eql 'Hello, Alice!'
66
+ # => #<Spectus::Result::Pass:0x007fc03bb56a78 @message="Pass: Expected \"Hello, Alice!\" to eql \"Hello, Alice!\".", @subject=#<Proc:0x007fc03bb57248@(irb):2>, @challenge=#<Defi::Challenge:0x007fc03bb56dc0 @method=:call, @args=[]>, @actual="Hello, Alice!", @expected={:Eql=>"Hello, Alice!"}, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
67
67
  greeting # => "Hello, world!"
68
68
  ```
69
69
 
@@ -71,8 +71,8 @@ Example of test without isolation:
71
71
 
72
72
  ```ruby
73
73
  greeting = 'Hello, world!'
74
- Spectus.this { greeting.gsub!('world', 'Alice') }.MUST Eql: 'Hello, Alice!'
75
- # => #<Spectus::Result::Pass:0x007fabbab88f68 @message="Pass: Expected \"Hello, Alice!\" to eql \"Hello, Alice!\".", @subject=#<Proc:0x007fabbab895a8@(irb):2>, @challenge=#<Defi::Challenge:0x007fabbab89530 @method=:call, @args=[]>, @actual="Hello, Alice!", @expected={:Eql=>"Hello, Alice!"}, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
74
+ it { greeting.gsub!('world', 'Alice') }.MUST eql: 'Hello, Alice!'
75
+ # => #<Spectus::Result::Pass:0x007f94b13de620 @message="Pass: Expected \"Hello, Alice!\" to eql \"Hello, Alice!\".", @subject=#<Proc:0x007f94b13deeb8@(irb):2>, @challenge=#<Defi::Challenge:0x007f94b13dee18 @method=:call, @args=[]>, @actual="Hello, Alice!", @expected={:Eql=>"Hello, Alice!"}, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
76
76
  greeting # => "Hello, Alice!"
77
77
  ```
78
78
 
@@ -87,13 +87,19 @@ Both instances share the same interface.
87
87
 
88
88
  ## Usage
89
89
 
90
+ To begin with, let's include __Spectus__:
91
+
92
+ ```ruby
93
+ include Spectus
94
+ ```
95
+
90
96
  ### Absolute requirement
91
97
 
92
98
  Given the `"ルビー"` object, when it receives `valid_encoding?` method, then it **MUST** be `true`:
93
99
 
94
100
  ```ruby
95
- Spectus.this { 'ルビー'.valid_encoding? }.MUST :BeTrue
96
- # => #<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>
101
+ it { 'ルビー'.valid_encoding? }.MUST be_true
102
+ # => #<Spectus::Result::Pass:0x007fd2791f1a50 @message="Pass: Expected true to be true.", @subject=#<Proc:0x007fd2791f23d8@(irb):1>, @challenge=#<Defi::Challenge:0x007fd2791f2338 @method=:call, @args=[]>, @actual=true, @expected=:BeTrue, @got=true, @error=nil, @level=:High, @negate=false, @valid=true>
97
103
  ```
98
104
 
99
105
  The result of the test shows that the spec passed.
@@ -103,8 +109,8 @@ The result of the test shows that the spec passed.
103
109
  Given the `"foo"` object, when it receives `length` method, then it **MUST NOT** raise the `NoMethodError` exception:
104
110
 
105
111
  ```ruby
106
- Spectus.this { 'foo'.length }.MUST_NOT RaiseException: NoMethodError
107
- # => #<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>
112
+ it { 'foo'.length }.MUST_NOT raise_exception NoMethodError
113
+ # => #<Spectus::Result::Pass:0x007f94e3408628 @message="Pass: Expected 3 not to raise exception NoMethodError.", @subject=#<Proc:0x007f94e3409050@(irb):1>, @challenge=#<Defi::Challenge:0x007f94e3408fd8 @method=:call, @args=[]>, @actual=3, @expected={:RaiseException=>NoMethodError}, @got=true, @error=nil, @level=:High, @negate=true, @valid=true>
108
114
  ```
109
115
 
110
116
  The result of the test shows that the spec passed.
@@ -114,8 +120,8 @@ The result of the test shows that the spec passed.
114
120
  Given the `BasicObject` object, when it receives `superclass` method, then it **SHOULD** return the explicit blank class `NilClass`:
115
121
 
116
122
  ```ruby
117
- Spectus.this { BasicObject.superclass }.SHOULD Equal: NilClass
118
- # => #<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>
123
+ it { BasicObject.superclass }.SHOULD equal NilClass
124
+ # => #<Spectus::Result::Pass:0x007fb5ac37cc10 @message="Info: Expected nil to equal NilClass.", @subject=#<Proc:0x007fb5ac37d5c0@(irb):1>, @challenge=#<Defi::Challenge:0x007fb5ac37d520 @method=:call, @args=[]>, @actual=nil, @expected={:Equal=>NilClass}, @got=false, @error=nil, @level=:Medium, @negate=false, @valid=false>
119
125
  ```
120
126
 
121
127
  Instead of the expected `NilClass` class, its sole instance (which is `nil`) was returned.
@@ -126,9 +132,9 @@ However, because there isn't any exception, the result of the test shows that th
126
132
  Given the `"1"` object, when it receives `+(1)` method, then it **SHOULD NOT** return the `"11"` value:
127
133
 
128
134
  ```ruby
129
- Spectus.this { '1' + 1 }.SHOULD_NOT Eql: '11'
135
+ it { '1' + 1 }.SHOULD_NOT eql '11'
130
136
  # Spectus::Result::Fail: Error: no implicit conversion of Fixnum into String (TypeError).
131
- # from (irb):4
137
+ # from (irb):1
132
138
  # from ./bin/console:7:in `<main>'
133
139
  ```
134
140
 
@@ -139,8 +145,8 @@ There was a `TypeError` exception, the result of the test shows that the spec fa
139
145
  Given the `"foo"` object, when it receives `blank?` method, then it **MAY** be `false`:
140
146
 
141
147
  ```ruby
142
- Spectus.this { 'foo'.blank? }.MAY :BeFalse
143
- # => #<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>
148
+ it { 'foo'.blank? }.MAY be_false
149
+ # => #<Spectus::Result::Pass:0x007fad1d057130 @message="Info: undefined method `blank?' for \"foo\":String (NoMethodError).", @subject=#<Proc:0x007fad1d057dd8@(irb):1>, @challenge=#<Defi::Challenge:0x007fad1d057ce8 @method=:call, @args=[]>, @actual=nil, @expected=:BeFalse, @got=nil, @error=#<NoMethodError: undefined method `blank?' for "foo":String>, @level=:Low, @negate=false, @valid=false>
144
150
  ```
145
151
 
146
152
  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.10.0
1
+ 3.0.0
@@ -0,0 +1 @@
1
+ b80e4f07089d0042497b5819020ee5f0f5c0170f65391d0f579c57f904e1481e71783a31371839b3cc6d968365ccfad390471765fdf89017092cf980626a5e70
data/lib/spectus.rb CHANGED
@@ -1,19 +1,43 @@
1
+ require 'matchi'
2
+
1
3
  # Namespace for the Spectus library.
2
4
  #
3
5
  # @api public
4
6
  #
5
- # @example 42 MUST be equal to 42
6
- # Spectus.this { 42 }.MUST Equal: 42 # => #<Spectus::Result::Pass...>
7
+ # @example It MUST equal 42.
8
+ # require 'spectus'
9
+ # it { 42 }.MUST equal 42 # => #<Spectus::Result::Pass...>
7
10
  module Spectus
11
+ Matchi.constants.each do |const|
12
+ name = const
13
+ .to_s
14
+ .gsub(/::/, '/')
15
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
16
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
17
+ .downcase
18
+
19
+ # Define a method for the given matcher.
20
+ #
21
+ # @example Given the `Matchi::Equal` matcher, its method will be defined as:
22
+ # def equal(expected)
23
+ # Matchi::Equal.new(expected)
24
+ # end
25
+ #
26
+ # @return [#matches?] The matcher.
27
+ define_method name do |*args|
28
+ Matchi.const_get(const).new(*args)
29
+ end
30
+ end
31
+
8
32
  # Expectations are built with this method.
9
33
  #
10
- # @example _Absolute requirement_ definition
11
- # this { 42 }.MUST Equal: 42 # => #<Spectus::Result::Pass...>
34
+ # @example An _absolute requirement_ definition.
35
+ # it { 42 }.MUST equal 42 # => #<Spectus::Result::Pass...>
12
36
  #
13
37
  # @param input [Proc] The code to test.
14
38
  #
15
39
  # @return [ExpectationTarget] The expectation target.
16
- def self.this(&input)
40
+ def it(&input)
17
41
  ExpectationTarget.new(&input)
18
42
  end
19
43
  end
@@ -6,7 +6,7 @@ module Spectus
6
6
  # @api public
7
7
  #
8
8
  # @example
9
- # this { actual value } # => ExpectationTarget wrapping the block
9
+ # it { actual value } # => ExpectationTarget wrapping the block
10
10
  class ExpectationTarget < BasicObject
11
11
  # Create a new expection target
12
12
  #
@@ -26,42 +26,42 @@ module Spectus
26
26
  # definition is an absolute requirement of the specification.
27
27
  #
28
28
  # @example _Absolute requirement_ definition
29
- # this { 'foo'.upcase }.MUST Eql: 'FOO'
29
+ # it { 'foo'.upcase }.MUST eql: 'FOO'
30
30
  #
31
- # @param req [Array, Hash, Symbol]
31
+ # @param m [#matches?] The matcher.
32
32
  #
33
33
  # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
34
- def MUST(req)
35
- RequirementLevel::High.new(req, false, subject, *challenges).result
34
+ def MUST(m)
35
+ RequirementLevel::High.new(m, false, subject, *challenges).result
36
36
  end
37
37
 
38
38
  # @example _Absolute requirement_ definition with isolation
39
- # this { 'foo'.upcase }.MUST! Eql: 'FOO'
39
+ # it { 'foo'.upcase }.MUST! eql: 'FOO'
40
40
  #
41
41
  # @see MUST
42
- def MUST!(req)
43
- RequirementLevel::High.new(req, false, subject, *challenges).result(true)
42
+ def MUST!(m)
43
+ RequirementLevel::High.new(m, false, subject, *challenges).result(true)
44
44
  end
45
45
 
46
46
  # This phrase, or the phrase "SHALL NOT", mean that the
47
47
  # definition is an absolute prohibition of the specification.
48
48
  #
49
49
  # @example _Absolute prohibition_ definition
50
- # this { 'foo'.size }.MUST_NOT Equal: 42
50
+ # it { 'foo'.size }.MUST_NOT equal: 42
51
51
  #
52
- # @param req [Array, Hash, Symbol]
52
+ # @param m [#matches?] The matcher.
53
53
  #
54
54
  # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
55
- def MUST_NOT(req)
56
- RequirementLevel::High.new(req, true, subject, *challenges).result
55
+ def MUST_NOT(m)
56
+ RequirementLevel::High.new(m, true, subject, *challenges).result
57
57
  end
58
58
 
59
59
  # @example _Absolute prohibition_ definition with isolation
60
- # this { 'foo'.size }.MUST_NOT! Equal: 42
60
+ # it { 'foo'.size }.MUST_NOT! equal: 42
61
61
  #
62
62
  # @see MUST_NOT
63
- def MUST_NOT!(req)
64
- RequirementLevel::High.new(req, true, subject, *challenges).result(true)
63
+ def MUST_NOT!(m)
64
+ RequirementLevel::High.new(m, true, subject, *challenges).result(true)
65
65
  end
66
66
 
67
67
  # This word, or the adjective "RECOMMENDED", mean that there
@@ -70,22 +70,21 @@ module Spectus
70
70
  # carefully weighed before choosing a different course.
71
71
  #
72
72
  # @example _Recommended_ definition
73
- # this { 'foo'.valid_encoding? }.SHOULD Equal: true
73
+ # it { 'foo'.valid_encoding? }.SHOULD equal: true
74
74
  #
75
- # @param req [Array, Hash, Symbol]
75
+ # @param m [#matches?] The matcher.
76
76
  #
77
77
  # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
78
- def SHOULD(req)
79
- RequirementLevel::Medium.new(req, false, subject, *challenges).result
78
+ def SHOULD(m)
79
+ RequirementLevel::Medium.new(m, false, subject, *challenges).result
80
80
  end
81
81
 
82
82
  # @example _Recommended_ definition with isolation
83
- # this { 'foo'.valid_encoding? }.SHOULD! Equal: true
83
+ # it { 'foo'.valid_encoding? }.SHOULD! equal: true
84
84
  #
85
85
  # @see SHOULD
86
- def SHOULD!(req)
87
- RequirementLevel::Medium.new(req, false, subject, *challenges)
88
- .result(true)
86
+ def SHOULD!(m)
87
+ RequirementLevel::Medium.new(m, false, subject, *challenges).result(true)
89
88
  end
90
89
 
91
90
  # This phrase, or the phrase "NOT RECOMMENDED" mean that
@@ -95,21 +94,21 @@ module Spectus
95
94
  # before implementing any behavior described with this label.
96
95
  #
97
96
  # @example _Not recommended_ definition
98
- # this { ''.blank? }.SHOULD_NOT RaiseException: NoMethodError
97
+ # it { ''.blank? }.SHOULD_NOT raise_exception: NoMethodError
99
98
  #
100
- # @param req [Array, Hash, Symbol]
99
+ # @param m [#matches?] The matcher.
101
100
  #
102
101
  # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
103
- def SHOULD_NOT(req)
104
- RequirementLevel::Medium.new(req, true, subject, *challenges).result
102
+ def SHOULD_NOT(m)
103
+ RequirementLevel::Medium.new(m, true, subject, *challenges).result
105
104
  end
106
105
 
107
106
  # @example _Not recommended_ definition with isolation
108
- # this { ''.blank? }.SHOULD_NOT! RaiseException: NoMethodError
107
+ # it { ''.blank? }.SHOULD_NOT! raise_exception: NoMethodError
109
108
  #
110
109
  # @see SHOULD_NOT
111
- def SHOULD_NOT!(req)
112
- RequirementLevel::Medium.new(req, true, subject, *challenges).result(true)
110
+ def SHOULD_NOT!(m)
111
+ RequirementLevel::Medium.new(m, true, subject, *challenges).result(true)
113
112
  end
114
113
 
115
114
  # This word, or the adjective "OPTIONAL", mean that an item is
@@ -125,21 +124,21 @@ module Spectus
125
124
  # option provides.)
126
125
  #
127
126
  # @example _Optional_ definition
128
- # this { 'foo'.bar }.MAY Match: /^foo$/
127
+ # it { 'foo'.bar }.MAY match: /^foo$/
129
128
  #
130
- # @param req [Array, Hash, Symbol]
129
+ # @param m [#matches?] The matcher.
131
130
  #
132
131
  # @return [Result::Fail, Result::Pass] Report if the spec pass or fail.
133
- def MAY(req)
134
- RequirementLevel::Low.new(req, false, subject, *challenges).result
132
+ def MAY(m)
133
+ RequirementLevel::Low.new(m, false, subject, *challenges).result
135
134
  end
136
135
 
137
136
  # @example _Optional_ definition with isolation
138
- # this { 'foo'.bar }.MAY! Match: /^foo$/
137
+ # it { 'foo'.bar }.MAY! match: /^foo$/
139
138
  #
140
139
  # @see MAY
141
- def MAY!(req)
142
- RequirementLevel::Low.new(req, false, subject, *challenges).result(true)
140
+ def MAY!(m)
141
+ RequirementLevel::Low.new(m, false, subject, *challenges).result(true)
143
142
  end
144
143
 
145
144
  # @!attribute [r] subject
@@ -6,21 +6,21 @@ module Spectus
6
6
  class Report
7
7
  # Initialize the report class.
8
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
9
+ # @param matcher [#matches?] The matcher.
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(matcher, negate, state, result)
14
+ @matcher = matcher
15
+ @negate = negate
16
+ @state = state
17
+ @result = result
18
18
  end
19
19
 
20
- # @!attribute [r] req
20
+ # @!attribute [r] matcher
21
21
  #
22
- # @return [Hash, Symbol] The definition of the expected value.
23
- attr_reader :req
22
+ # @return [#matches?] The matcher.
23
+ attr_reader :matcher
24
24
 
25
25
  # The value of the negate instance variable.
26
26
  #
@@ -84,27 +84,7 @@ module Spectus
84
84
  #
85
85
  # @return [String] The readable definition string.
86
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
87
+ matcher.to_s
108
88
  end
109
89
  end
110
90
  end
@@ -11,21 +11,21 @@ module Spectus
11
11
  class Base
12
12
  # Initialize the requirement level class.
13
13
  #
14
- # @param req [Hash, Symbol] The definition of the expected value.
15
- # @param negate [Boolean] Evaluate to a negative assertion.
16
- # @param subject [#object_id] The front object to test.
17
- # @param challenges [Array] A list of challenges.
18
- def initialize(req, negate, subject, *challenges)
19
- @req = req
14
+ # @param matcher [#matches?] The matcher.
15
+ # @param negate [Boolean] Evaluate to a negative assertion.
16
+ # @param subject [#object_id] The front object to test.
17
+ # @param challenges [Array] A list of challenges.
18
+ def initialize(matcher, negate, subject, *challenges)
19
+ @matcher = matcher
20
20
  @negate = negate
21
21
  @subject = subject
22
22
  @challenges = challenges
23
23
  end
24
24
 
25
- # @!attribute [r] req
25
+ # @!attribute [r] matcher
26
26
  #
27
- # @return [Hash, Symbol] The definition of the expected value.
28
- attr_reader :req
27
+ # @return [#matches?] The matcher.
28
+ attr_reader :matcher
29
29
 
30
30
  # The value of the negate instance variable.
31
31
  #
@@ -50,7 +50,7 @@ module Spectus
50
50
  #
51
51
  # @return [Result::Pass] Pass the spec.
52
52
  def pass!(state)
53
- msg = Report.new(req, negate?, state, true)
53
+ msg = Report.new(matcher, negate?, state, true)
54
54
 
55
55
  Result::Pass.new(msg, *result_signature(state))
56
56
  end
@@ -59,7 +59,7 @@ module Spectus
59
59
  #
60
60
  # @raise [Result::Fail] Fail the spec.
61
61
  def fail!(state)
62
- msg = Report.new(req, negate?, state, false)
62
+ msg = Report.new(matcher, negate?, state, false)
63
63
 
64
64
  fail Result::Fail.new(msg, *result_signature(state)), msg, caller[2..-1]
65
65
  end
@@ -72,7 +72,7 @@ module Spectus
72
72
  subject,
73
73
  state.last_challenge,
74
74
  state.actual,
75
- req,
75
+ matcher,
76
76
  state.got,
77
77
  state.exception,
78
78
  level,
@@ -95,7 +95,7 @@ module Spectus
95
95
 
96
96
  # @return [Sandbox] The sandbox.
97
97
  def execute
98
- Sandbox.new(req, negate?, subject, *challenges)
98
+ Sandbox.new(matcher, negate?, subject, *challenges)
99
99
  end
100
100
  end
101
101
  end
@@ -14,7 +14,7 @@ module Spectus
14
14
  # @param challenge [Defi::Challenge] The challenge for the subject.
15
15
  # @param actual [#object_id] The value that the subject return through
16
16
  # its challenge.
17
- # @param expected [Hash, Symbol] The definition of the expected value.
17
+ # @param expected [#matches?] The definition of the expected value.
18
18
  # @param got [#object_id] The result of the boolean comparison
19
19
  # between the actual value and the expected value.
20
20
  # @param error [#exception, nil] Any possible raised exception.
@@ -54,7 +54,7 @@ module Spectus
54
54
 
55
55
  # @!attribute [r] expected
56
56
  #
57
- # @return [Array, Hash, Symbol] The definition of the expected value.
57
+ # @return [#matches?] The definition of the expected value.
58
58
  attr_reader :expected
59
59
 
60
60
  # @!attribute [r] got
@@ -96,7 +96,7 @@ module Spectus
96
96
  subject: subject,
97
97
  challenge: challenge.to_h,
98
98
  actual: actual,
99
- expected: expected,
99
+ expected: expected.to_h,
100
100
  got: got,
101
101
  error: error,
102
102
  level: level,
@@ -1,19 +1,17 @@
1
- require 'matchi'
2
-
3
1
  module Spectus
4
2
  # This class evaluate the expectation with the passed block.
5
3
  #
6
4
  # @api private
7
5
  #
8
6
  class Sandbox
9
- # Execute the untested code from the passed block against the definition.
10
- #
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)
16
- @got = negate ^ matcher(definition).matches? do
7
+ # Execute the untested code from the passed block against the matcher.
8
+ #
9
+ # @param matcher [#matches?] The matcher.
10
+ # @param negate [Boolean] The negation of the matcher's result.
11
+ # @param object [#object_id] The front object which is challenged.
12
+ # @param challenges [Array] The list of challenges.
13
+ def initialize(matcher, negate, object, *challenges)
14
+ @got = negate ^ matcher.matches? do
17
15
  @actual = challenges.inject(object) do |subject, challenge|
18
16
  @last_challenge = challenge
19
17
  @last_challenge.to(subject)
@@ -55,17 +53,5 @@ module Spectus
55
53
  got
56
54
  end
57
55
  end
58
-
59
- private
60
-
61
- # Load the matcher.
62
- #
63
- # @param definition [Array, Hash, Symbol]
64
- #
65
- # @return [#matches?] The matcher.
66
- def matcher(definition)
67
- params = Array(definition).flatten(1)
68
- Matchi.fetch(params.first, *params[1..-1])
69
- end
70
56
  end
71
57
  end
data/spectus.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.add_dependency 'aw', '~> 0.1.0'
18
18
  spec.add_dependency 'defi', '~> 1.1.0'
19
- spec.add_dependency 'matchi', '~> 0.0.9'
19
+ spec.add_dependency 'matchi', '~> 0.1.1'
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.10'
22
22
  spec.add_development_dependency 'rake', '~> 10.4'
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.10.0
4
+ version: 3.0.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-18 00:00:00.000000000 Z
33
+ date: 2015-10-31 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: aw
@@ -66,14 +66,14 @@ dependencies:
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 0.0.9
69
+ version: 0.1.1
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 0.0.9
76
+ version: 0.1.1
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: bundler
79
79
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +174,7 @@ files:
174
174
  - checksum/spectus-2.1.1.gem.sha512
175
175
  - checksum/spectus-2.1.2.gem.sha512
176
176
  - checksum/spectus-2.1.3.gem.sha512
177
+ - checksum/spectus-2.10.0.gem.sha512
177
178
  - checksum/spectus-2.2.0.gem.sha512
178
179
  - checksum/spectus-2.3.0.gem.sha512
179
180
  - checksum/spectus-2.3.1.gem.sha512
metadata.gz.sig CHANGED
Binary file