matchi 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +16 -10
  3. data/VERSION.semver +1 -1
  4. data/lib/matchi.rb +15 -0
  5. metadata +20 -38
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2112c16da9d008dbe0c5ff3b62756b0fdebd2b4
4
+ data.tar.gz: 91fcdf7bac95139ea1c5ae149c54e12902c85fe5
5
+ SHA512:
6
+ metadata.gz: 492a24a9cf62fd1ddbcd50dfec9e9ec304c75dc0aee3eec40324a890b42491b9c0448aa07c2287c9fbcb4685be6b05bd24d0305ae15b68f5030d0d243ead6ee9
7
+ data.tar.gz: a46f7f36dc216905c76048d03cdd2a01ac1151fd26ee592e62b691ab3c07c2c55a6cac86304975588f00f6d6c6d7b15f613f62a6d1c86b6a409199aa8d9bf6be
data/README.md CHANGED
@@ -38,54 +38,60 @@ Or install it yourself as:
38
38
 
39
39
  ## Usage
40
40
 
41
+ List all available matchers:
42
+
43
+ ```ruby
44
+ Matchi.constants # => [:BeFalse, :BeNil, :BeTrue, :Eql, :Equal, :Match, :RaiseException]
45
+ ```
46
+
41
47
  ### Built-in matchers
42
48
 
43
49
  **Equivalence** matcher:
44
50
 
45
51
  ```ruby
46
- eql = Matchi::Eql.new('foo')
52
+ eql = Matchi.fetch(:Eql, 'foo')
47
53
  eql.matches? { 'foo' } # => true
48
54
  ```
49
55
 
50
56
  **Identity** matcher:
51
57
 
52
58
  ```ruby
53
- equal = Matchi::Equal.new(:foo)
59
+ equal = Matchi.fetch(:Equal, :foo)
54
60
  equal.matches? { :foo } # => true
55
61
  ```
56
62
 
57
63
  **Regular expressions** matcher:
58
64
 
59
65
  ```ruby
60
- match = Matchi::Match.new(/^foo$/)
66
+ match = Matchi.fetch(:Match, /^foo$/)
61
67
  match.matches? { 'foo' } # => true
62
68
  ```
63
69
 
64
70
  **Expecting errors** matcher:
65
71
 
66
72
  ```ruby
67
- raise_exception = Matchi::RaiseException.new(NameError)
73
+ raise_exception = Matchi.fetch(:RaiseException, NameError)
68
74
  raise_exception.matches? { Boom } # => true
69
75
  ```
70
76
 
71
77
  **Truth** matcher:
72
78
 
73
79
  ```ruby
74
- be_true = Matchi::BeTrue.new
80
+ be_true = Matchi.fetch(:BeTrue)
75
81
  be_true.matches? { true } # => true
76
82
  ```
77
83
 
78
84
  **Untruth** matcher:
79
85
 
80
86
  ```ruby
81
- be_false = Matchi::BeFalse.new
87
+ be_false = Matchi.fetch(:BeFalse)
82
88
  be_false.matches? { false } # => true
83
89
  ```
84
90
 
85
91
  **Nil** matcher:
86
92
 
87
93
  ```ruby
88
- be_nil = Matchi::BeNil.new
94
+ be_nil = Matchi.fetch(:BeNil)
89
95
  be_nil.matches? { nil } # => true
90
96
  ```
91
97
 
@@ -104,7 +110,7 @@ module Matchi
104
110
  end
105
111
  end
106
112
 
107
- be_the_answer = Matchi::BeTheAnswer.new
113
+ be_the_answer = Matchi.fetch(:BeTheAnswer)
108
114
  be_the_answer.matches? { 42 } # => true
109
115
  ```
110
116
 
@@ -121,7 +127,7 @@ module Matchi
121
127
  end
122
128
  end
123
129
 
124
- be_prime = Matchi::BePrime.new
130
+ be_prime = Matchi.fetch(:BePrime)
125
131
  be_prime.matches? { 42 } # => false
126
132
  ```
127
133
 
@@ -140,7 +146,7 @@ module Matchi
140
146
  end
141
147
  end
142
148
 
143
- start_with = Matchi::StartWith.new('foo')
149
+ start_with = Matchi.fetch(:StartWith, 'foo')
144
150
  start_with.matches? { 'foobar' } # => true
145
151
  ```
146
152
 
data/VERSION.semver CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/lib/matchi.rb CHANGED
@@ -3,5 +3,20 @@ Dir[File.join File.dirname(__FILE__), 'matchi', '*.rb'].each do |fname|
3
3
  end
4
4
 
5
5
  # 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
6
12
  module Matchi
13
+ # Select a matcher from those available.
14
+ #
15
+ # @param [Symbol] matcher_id the name of the constant of the matcher to fetch
16
+ # @param [Array] args 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
7
22
  end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cyril Wack
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-02-21 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.8'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.8'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: yard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0.8'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0.8'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: simplecov
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: 0.9.1
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.9.1
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rubocop
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0.29'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0.29'
94
83
  description: Collection of expectation matchers for Ruby.
@@ -98,9 +87,9 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - .gitignore
102
- - .travis.yml
103
- - .yardopts
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - ".yardopts"
104
93
  - CODE_OF_CONDUCT.md
105
94
  - Gemfile
106
95
  - LICENSE.md
@@ -121,33 +110,26 @@ files:
121
110
  homepage: https://github.com/fixrb/matchi
122
111
  licenses:
123
112
  - MIT
113
+ metadata: {}
124
114
  post_install_message:
125
115
  rdoc_options: []
126
116
  require_paths:
127
117
  - lib
128
118
  required_ruby_version: !ruby/object:Gem::Requirement
129
- none: false
130
119
  requirements:
131
- - - ! '>='
120
+ - - ">="
132
121
  - !ruby/object:Gem::Version
133
122
  version: '0'
134
- segments:
135
- - 0
136
- hash: 3719578946741581766
137
123
  required_rubygems_version: !ruby/object:Gem::Requirement
138
- none: false
139
124
  requirements:
140
- - - ! '>='
125
+ - - ">="
141
126
  - !ruby/object:Gem::Version
142
127
  version: '0'
143
- segments:
144
- - 0
145
- hash: 3719578946741581766
146
128
  requirements: []
147
129
  rubyforge_project:
148
- rubygems_version: 1.8.23.2
130
+ rubygems_version: 2.4.5
149
131
  signing_key:
150
- specification_version: 3
132
+ specification_version: 4
151
133
  summary: Collection of matchers.
152
134
  test_files: []
153
135
  has_rdoc: