matchi 0.0.9 → 0.1.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: 659f29a670790e63d96ab4d838e3978b767e5a07
4
- data.tar.gz: 035aaf2bd805b1018ab474e374b3245f267f9c83
3
+ metadata.gz: 72d138a4f3f6057acdd0aad92c3c72fdc2cd955c
4
+ data.tar.gz: 6f045b969f91670bc966b2f90b45888a749cbb2a
5
5
  SHA512:
6
- metadata.gz: ccd2e3cef44f95a92b93c383421dd1d03821ae77c84607880383338ada5fc2fa1cf2c91af084b2a11e5a2c1d5fd2f47aede844cea74a3083233d00e3bb29d16a
7
- data.tar.gz: 670b8aaf1192527270fd656132547d2e75127dfed51a3b2dc0d9d7151091e571689643bb4b54d3dd812ec56fd0f5e3f6ec25b7e66e2269a08991faa603ee36c2
6
+ metadata.gz: 0b676b06bcfdb7f12af040df4dae8bf33c5094b8c9ed26a705e4c6978ebd768c5a1b43aa8a589e208c8fc31ba8dfe79dc078ee598766219bc3e0c5884aff4281
7
+ data.tar.gz: b125380c5114e9a295cd79b6dec2be4c4f120c023ef2ea70045227caba9bb0da3a4f67b247a3847e24f9e9de6954ccc4e20c695632737b6d2c5aa9a32cf20a31
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -32,68 +32,72 @@ To be sure the gem you install hasn't been tampered with, add my public key
32
32
  The `HighSecurity` trust profile will verify all gems. All of __Matchi__'s
33
33
  dependencies are signed.
34
34
 
35
- ## Usage
36
-
37
- ### List all matchers
35
+ Or add this line to your application's Gemfile:
38
36
 
39
37
  ```ruby
40
- Matchi.constants # => [:BeFalse, :BeNil, :BeTrue, :Eql, :Equal, :Match, :RaiseException]
38
+ gem 'matchi'
41
39
  ```
42
40
 
41
+ And then execute:
42
+
43
+ $ bundle
44
+
45
+ ## Usage
46
+
43
47
  ### Built-in matchers
44
48
 
45
49
  **Equivalence** matcher:
46
50
 
47
51
  ```ruby
48
- eql = Matchi.fetch(:Eql, 'foo')
52
+ eql = Matchi::Eql.new('foo')
49
53
  eql.matches? { 'foo' } # => true
50
54
  ```
51
55
 
52
56
  **Identity** matcher:
53
57
 
54
58
  ```ruby
55
- equal = Matchi.fetch(:Equal, :foo)
59
+ equal = Matchi::Equal.new(:foo)
56
60
  equal.matches? { :foo } # => true
57
61
  ```
58
62
 
59
63
  **Regular expressions** matcher:
60
64
 
61
65
  ```ruby
62
- match = Matchi.fetch(:Match, /^foo$/)
66
+ match = Matchi::Match.new(/^foo$/)
63
67
  match.matches? { 'foo' } # => true
64
68
  ```
65
69
 
66
70
  **Expecting errors** matcher:
67
71
 
68
72
  ```ruby
69
- raise_exception = Matchi.fetch(:RaiseException, NameError)
73
+ raise_exception = Matchi::RaiseException.new(NameError)
70
74
  raise_exception.matches? { Boom } # => true
71
75
  ```
72
76
 
73
77
  **Truth** matcher:
74
78
 
75
79
  ```ruby
76
- be_true = Matchi.fetch(:BeTrue)
80
+ be_true = Matchi::BeTrue.new
77
81
  be_true.matches? { true } # => true
78
82
  ```
79
83
 
80
84
  **Untruth** matcher:
81
85
 
82
86
  ```ruby
83
- be_false = Matchi.fetch(:BeFalse)
87
+ be_false = Matchi::BeFalse.new
84
88
  be_false.matches? { false } # => true
85
89
  ```
86
90
 
87
91
  **Nil** matcher:
88
92
 
89
93
  ```ruby
90
- be_nil = Matchi.fetch(:BeNil)
94
+ be_nil = Matchi::BeNil.new
91
95
  be_nil.matches? { nil } # => true
92
96
  ```
93
97
 
94
98
  ### Custom matchers
95
99
 
96
- Custom matchers can easily be defined for expressing expectations.
100
+ Custom matchers can easily be defined for expressing expectations. They can be any Ruby class that responds to `matches?`, `to_s` and `to_h` instance methods.
97
101
 
98
102
  **Be the answer** matcher:
99
103
 
@@ -103,10 +107,18 @@ module Matchi
103
107
  def matches?
104
108
  42.equal? yield
105
109
  end
110
+
111
+ def to_s
112
+ 'be_the_answer'
113
+ end
114
+
115
+ def to_h
116
+ { BeTheAnswer: [] }
117
+ end
106
118
  end
107
119
  end
108
120
 
109
- be_the_answer = Matchi.fetch(:BeTheAnswer)
121
+ be_the_answer = Matchi::BeTheAnswer.new
110
122
  be_the_answer.matches? { 42 } # => true
111
123
  ```
112
124
 
@@ -120,10 +132,18 @@ module Matchi
120
132
  def matches?
121
133
  Prime.prime? yield
122
134
  end
135
+
136
+ def to_s
137
+ 'be_prime'
138
+ end
139
+
140
+ def to_h
141
+ { BePrime: [] }
142
+ end
123
143
  end
124
144
  end
125
145
 
126
- be_prime = Matchi.fetch(:BePrime)
146
+ be_prime = Matchi::BePrime.new
127
147
  be_prime.matches? { 42 } # => false
128
148
  ```
129
149
 
@@ -132,17 +152,25 @@ be_prime.matches? { 42 } # => false
132
152
  ```ruby
133
153
  module Matchi
134
154
  class StartWith
135
- def initialize expected
155
+ def initialize(expected)
136
156
  @expected = expected
137
157
  end
138
158
 
139
159
  def matches?
140
160
  !Regexp.new("^#{@expected}").match(yield).nil?
141
161
  end
162
+
163
+ def to_s
164
+ 'start_with'
165
+ end
166
+
167
+ def to_h
168
+ { StartWith: [@expected] }
169
+ end
142
170
  end
143
171
  end
144
172
 
145
- start_with = Matchi.fetch(:StartWith, 'foo')
173
+ start_with = Matchi::StartWith.new('foo')
146
174
  start_with.matches? { 'foobar' } # => true
147
175
  ```
148
176
 
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.1.0
@@ -1 +1 @@
1
- 2fec09a07ba40a3a78fbf475f84fd8f620d90e3bd4596ca05b828d379302aef5c748543bb585c78b5ee536be68e9b444f92e4b99fc39eed50165ad1b3561da31
1
+ e09fc68126ef7683b72d98b0ac7aa198b451442ecace0b1c2d0843ca53873abee397ba1aa1e42ced97f03f6c1be18221f856b50a089a87878edc70a4ad90bd61
@@ -1,22 +1,7 @@
1
- Dir[File.join File.dirname(__FILE__), 'matchi', '*.rb'].each do |fname|
2
- require_relative fname
3
- end
4
-
5
1
  # Namespace for the Matchi library.
6
- #
7
- # @api public
8
- #
9
- # @example Match that 42 is equal to 42
10
- # matcher = Matchi.fetch(:Equal, 42)
11
- # matcher.matches? { 42 } # => true
12
2
  module Matchi
13
- # Select a matcher from those available.
14
- #
15
- # @param matcher_id [Symbol] The name of the constant of the matcher to fetch.
16
- # @param args [Array] Parameters to initialize the class of the matcher.
17
- #
18
- # @return [#matches?] the matcher
19
- def self.fetch(matcher_id, *args)
20
- const_get(matcher_id, false).new(*args)
21
- end
3
+ end
4
+
5
+ Dir[File.join File.dirname(__FILE__), 'matchi', '*.rb'].each do |fname|
6
+ require_relative fname
22
7
  end
@@ -1,6 +1,8 @@
1
1
  module Matchi
2
2
  # **Untruth** matcher.
3
- class BeFalse < BasicObject
3
+ class BeFalse
4
+ # Boolean comparison between the actual value and the expected value.
5
+ #
4
6
  # @example Is it false?
5
7
  # be_false = Matchi::BeFalse.new
6
8
  # be_false.matches? { false } # => true
@@ -11,5 +13,28 @@ module Matchi
11
13
  def matches?
12
14
  false.equal?(yield)
13
15
  end
16
+
17
+ # Returns a string representing the matcher.
18
+ #
19
+ # @example The readable definition of a FooBar matcher.
20
+ # matcher = Matchi::FooBar.new(42)
21
+ # matcher.to_s # => "foo_bar 42"
22
+ #
23
+ # @return [String] A string representing the matcher.
24
+ def to_s
25
+ 'be_false'
26
+ end
27
+
28
+ # Returns a hash of one key-value pair with a key corresponding to the
29
+ # matcher and a value corresponding to its initialize parameters.
30
+ #
31
+ # @example A FooBar matcher serialized into a hash.
32
+ # matcher = Matchi::FooBar.new(42)
33
+ # matcher.to_h # => { FooBar: 42 }
34
+ #
35
+ # @return [Hash] A hash of one key-value pair.
36
+ def to_h
37
+ { BeFalse: [] }
38
+ end
14
39
  end
15
40
  end
@@ -1,6 +1,8 @@
1
1
  module Matchi
2
2
  # **Nil** matcher.
3
3
  class BeNil < BasicObject
4
+ # Boolean comparison between the actual value and the expected value.
5
+ #
4
6
  # @example Is it nil?
5
7
  # be_nil = Matchi::BeNil.new
6
8
  # be_nil.matches? { nil } # => true
@@ -11,5 +13,28 @@ module Matchi
11
13
  def matches?
12
14
  nil.equal?(yield)
13
15
  end
16
+
17
+ # Returns a string representing the matcher.
18
+ #
19
+ # @example The readable definition of a FooBar matcher.
20
+ # matcher = Matchi::FooBar.new(42)
21
+ # matcher.to_s # => "foo_bar 42"
22
+ #
23
+ # @return [String] A string representing the matcher.
24
+ def to_s
25
+ 'be_nil'
26
+ end
27
+
28
+ # Returns a hash of one key-value pair with a key corresponding to the
29
+ # matcher and a value corresponding to its initialize parameters.
30
+ #
31
+ # @example A FooBar matcher serialized into a hash.
32
+ # matcher = Matchi::FooBar.new(42)
33
+ # matcher.to_h # => { FooBar: 42 }
34
+ #
35
+ # @return [Hash] A hash of one key-value pair.
36
+ def to_h
37
+ { BeNil: [] }
38
+ end
14
39
  end
15
40
  end
@@ -1,6 +1,8 @@
1
1
  module Matchi
2
2
  # **Truth** matcher.
3
3
  class BeTrue < BasicObject
4
+ # Boolean comparison between the actual value and the expected value.
5
+ #
4
6
  # @example Is it true?
5
7
  # be_true = Matchi::BeTrue.new
6
8
  # be_true.matches? { true } # => true
@@ -11,5 +13,28 @@ module Matchi
11
13
  def matches?
12
14
  true.equal?(yield)
13
15
  end
16
+
17
+ # Returns a string representing the matcher.
18
+ #
19
+ # @example The readable definition of a FooBar matcher.
20
+ # matcher = Matchi::FooBar.new(42)
21
+ # matcher.to_s # => "foo_bar 42"
22
+ #
23
+ # @return [String] A string representing the matcher.
24
+ def to_s
25
+ 'be_true'
26
+ end
27
+
28
+ # Returns a hash of one key-value pair with a key corresponding to the
29
+ # matcher and a value corresponding to its initialize parameters.
30
+ #
31
+ # @example A FooBar matcher serialized into a hash.
32
+ # matcher = Matchi::FooBar.new(42)
33
+ # matcher.to_h # => { FooBar: 42 }
34
+ #
35
+ # @return [Hash] A hash of one key-value pair.
36
+ def to_h
37
+ { BeTrue: [] }
38
+ end
14
39
  end
15
40
  end
@@ -3,7 +3,7 @@ module Matchi
3
3
  class Eql < BasicObject
4
4
  # Initialize the matcher with an object.
5
5
  #
6
- # @example The string 'foo' matcher
6
+ # @example The string 'foo' matcher.
7
7
  # Matchi::Eql.new('foo')
8
8
  #
9
9
  # @param expected [#eql?] An expected equivalent object.
@@ -11,6 +11,8 @@ module Matchi
11
11
  @expected = expected
12
12
  end
13
13
 
14
+ # Boolean comparison between the actual value and the expected value.
15
+ #
14
16
  # @example Is it equivalent to 'foo'?
15
17
  # eql = Matchi::Eql.new('foo')
16
18
  # eql.matches? { 'foo' } # => true
@@ -21,5 +23,28 @@ module Matchi
21
23
  def matches?
22
24
  @expected.eql?(yield)
23
25
  end
26
+
27
+ # Returns a string representing the matcher.
28
+ #
29
+ # @example The readable definition of a FooBar matcher.
30
+ # matcher = Matchi::FooBar.new(42)
31
+ # matcher.to_s # => "foo_bar 42"
32
+ #
33
+ # @return [String] A string representing the matcher.
34
+ def to_s
35
+ "eql #{@expected.inspect}"
36
+ end
37
+
38
+ # Returns a hash of one key-value pair with a key corresponding to the
39
+ # matcher and a value corresponding to its initialize parameters.
40
+ #
41
+ # @example A FooBar matcher serialized into a hash.
42
+ # matcher = Matchi::FooBar.new(42)
43
+ # matcher.to_h # => { FooBar: 42 }
44
+ #
45
+ # @return [Hash] A hash of one key-value pair.
46
+ def to_h
47
+ { Eql: [@expected] }
48
+ end
24
49
  end
25
50
  end
@@ -3,7 +3,7 @@ module Matchi
3
3
  class Equal < BasicObject
4
4
  # Initialize the matcher with an object.
5
5
  #
6
- # @example The number 42 matcher
6
+ # @example The number 42 matcher.
7
7
  # Matchi::Equal.new(42)
8
8
  #
9
9
  # @param expected [#equal?] An expected object.
@@ -11,6 +11,8 @@ module Matchi
11
11
  @expected = expected
12
12
  end
13
13
 
14
+ # Boolean comparison between the actual value and the expected value.
15
+ #
14
16
  # @example Is it equal to :foo?
15
17
  # equal = Matchi::Equal.new(:foo)
16
18
  # equal.matches? { :foo } # => true
@@ -21,5 +23,28 @@ module Matchi
21
23
  def matches?
22
24
  @expected.equal?(yield)
23
25
  end
26
+
27
+ # Returns a string representing the matcher.
28
+ #
29
+ # @example The readable definition of a FooBar matcher.
30
+ # matcher = Matchi::FooBar.new(42)
31
+ # matcher.to_s # => "foo_bar 42"
32
+ #
33
+ # @return [String] A string representing the matcher.
34
+ def to_s
35
+ "equal #{@expected.inspect}"
36
+ end
37
+
38
+ # Returns a hash of one key-value pair with a key corresponding to the
39
+ # matcher and a value corresponding to its initialize parameters.
40
+ #
41
+ # @example A FooBar matcher serialized into a hash.
42
+ # matcher = Matchi::FooBar.new(42)
43
+ # matcher.to_h # => { FooBar: 42 }
44
+ #
45
+ # @return [Hash] A hash of one key-value pair.
46
+ def to_h
47
+ { Equal: [@expected] }
48
+ end
24
49
  end
25
50
  end
@@ -3,7 +3,7 @@ module Matchi
3
3
  class Match < BasicObject
4
4
  # Initialize the matcher with an instance of Regexp.
5
5
  #
6
- # @example Username matcher
6
+ # @example Username matcher.
7
7
  # Matchi::Match.new(/^[a-z0-9_-]{3,16}$/)
8
8
  #
9
9
  # @param expected [#match] A regular expression.
@@ -11,6 +11,8 @@ module Matchi
11
11
  @expected = expected
12
12
  end
13
13
 
14
+ # Boolean comparison between the actual value and the expected value.
15
+ #
14
16
  # @example Is it matching /^foo$/ regex?
15
17
  # match = Matchi::Match.new(/^foo$/)
16
18
  # match.matches? { 'foo' } # => true
@@ -21,5 +23,28 @@ module Matchi
21
23
  def matches?
22
24
  @expected.match(yield).nil?.equal?(false)
23
25
  end
26
+
27
+ # Returns a string representing the matcher.
28
+ #
29
+ # @example The readable definition of a FooBar matcher.
30
+ # matcher = Matchi::FooBar.new(42)
31
+ # matcher.to_s # => "foo_bar 42"
32
+ #
33
+ # @return [String] A string representing the matcher.
34
+ def to_s
35
+ "match #{@expected.inspect}"
36
+ end
37
+
38
+ # Returns a hash of one key-value pair with a key corresponding to the
39
+ # matcher and a value corresponding to its initialize parameters.
40
+ #
41
+ # @example A FooBar matcher serialized into a hash.
42
+ # matcher = Matchi::FooBar.new(42)
43
+ # matcher.to_h # => { FooBar: 42 }
44
+ #
45
+ # @return [Hash] A hash of one key-value pair.
46
+ def to_h
47
+ { Match: [@expected] }
48
+ end
24
49
  end
25
50
  end
@@ -3,7 +3,7 @@ module Matchi
3
3
  class RaiseException < BasicObject
4
4
  # Initialize the matcher with a descendant of class Exception.
5
5
  #
6
- # @example Divided by 0 matcher
6
+ # @example Divided by 0 matcher.
7
7
  # Matchi::RaiseException.new(ZeroDivisionError)
8
8
  #
9
9
  # @param expected [.exception] The class of the expected exception.
@@ -11,6 +11,8 @@ module Matchi
11
11
  @expected = expected
12
12
  end
13
13
 
14
+ # Boolean comparison between the actual value and the expected value.
15
+ #
14
16
  # @example Is it raising NameError?
15
17
  # raise_exception = Matchi::RaiseException.new(NameError)
16
18
  # raise_exception.matches? { Boom } # => true
@@ -25,5 +27,28 @@ module Matchi
25
27
  else
26
28
  false
27
29
  end
30
+
31
+ # Returns a string representing the matcher.
32
+ #
33
+ # @example The readable definition of a FooBar matcher.
34
+ # matcher = Matchi::FooBar.new(42)
35
+ # matcher.to_s # => "foo_bar 42"
36
+ #
37
+ # @return [String] A string representing the matcher.
38
+ def to_s
39
+ "raise_exception #{@expected.inspect}"
40
+ end
41
+
42
+ # Returns a hash of one key-value pair with a key corresponding to the
43
+ # matcher and a value corresponding to its initialize parameters.
44
+ #
45
+ # @example A FooBar matcher serialized into a hash.
46
+ # matcher = Matchi::FooBar.new(42)
47
+ # matcher.to_h # => { FooBar: 42 }
48
+ #
49
+ # @return [Hash] A hash of one key-value pair.
50
+ def to_h
51
+ { RaiseException: [@expected] }
52
+ end
28
53
  end
29
54
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.add_development_dependency 'rake', '~> 10.4'
19
19
  spec.add_development_dependency 'yard', '~> 0.8'
20
20
  spec.add_development_dependency 'simplecov', '~> 0.10'
21
- spec.add_development_dependency 'rubocop', '~> 0.32'
21
+ spec.add_development_dependency 'rubocop', '~> 0.34'
22
22
 
23
23
  spec.cert_chain = ['certs/gem-fixrb-public_cert.pem']
24
24
  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: matchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.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-07-31 00:00:00.000000000 Z
33
+ date: 2015-10-30 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: bundler
@@ -94,14 +94,14 @@ dependencies:
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.32'
97
+ version: '0.34'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.32'
104
+ version: '0.34'
105
105
  description: Collection of expectation matchers for Ruby.
106
106
  email:
107
107
  - contact@cyril.email
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.4.5
163
+ rubygems_version: 2.4.5.1
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: Collection of matchers.
metadata.gz.sig CHANGED
Binary file