rspec-matcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8341fb1025efb39d3636ec52f6fe98122f8e04a6
4
+ data.tar.gz: 0548717cf018015a0ea92211e8fd09dfbf643be7
5
+ SHA512:
6
+ metadata.gz: 0cb7ee5d8b98ab55ae7265ace61f2768c39e674f25bac70f4a95b11b8349e5b566f12fc1640969bf1294ffd967ac3b05bcfc1bdebf84b17a7102947a89cd5b5f
7
+ data.tar.gz: 937e1327820d681dbed4dec4062128529ce57be1ef5b1148dc6c29931b9e93fa1bfd1b4a50f05d0e7437f476cd24c753789781c9df684114fd6ceb5623fc5a8d
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 [Pooyan Khosravi](https://www.github.com/pekhee).
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # RspecMatcher
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rspec-matcher.svg)](http://badge.fury.io/rb/rspec-matcher)
4
+ [![Code Climate GPA](https://codeclimate.com/github/pekhee/rspec-matcher.svg)](https://codeclimate.com/github/pekhee/rspec-matcher)
5
+ [![Code Climate Coverage](https://codeclimate.com/github/pekhee/rspec-matcher/coverage.svg)](https://codeclimate.com/github/pekhee/rspec-matcher)
6
+ [![Gemnasium Status](https://gemnasium.com/pekhee/rspec-matcher.svg)](https://gemnasium.com/pekhee/rspec-matcher)
7
+ [![Travis CI Status](https://secure.travis-ci.org/pekhee/rspec-matcher.svg)](https://travis-ci.org/pekhee/rspec-matcher)
8
+ [![Inch CI](https://inch-ci.org/github/pekhee/rspec-matcher.svg?branch=master)](https://inch-ci.org/github/pekhee/rspec-matcher)
9
+ [![Gitter](https://camo.githubusercontent.com/da2edb525cde1455a622c58c0effc3a90b9a181c/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/pekhee/rspec-matcher)
10
+
11
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
12
+
13
+ # Table of Contents
14
+
15
+ - [Features](#features)
16
+ - [Requirements](#requirements)
17
+ - [Setup](#setup)
18
+ - [Usage](#usage)
19
+ - [Tests](#tests)
20
+ - [Versioning](#versioning)
21
+ - [Code of Conduct](#code-of-conduct)
22
+ - [Contributions](#contributions)
23
+ - [License](#license)
24
+ - [History](#history)
25
+ - [Credits](#credits)
26
+
27
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
28
+
29
+ # Features
30
+ - Implementes RSpec matcher interface as a module.
31
+ - Registers matcher with RSpec.
32
+ - It is stable in contrast to RSpec::Matchers::BaseMatcher.
33
+ - Well tested and documented.
34
+
35
+ # Requirements
36
+
37
+ 0. [MRI 2.1.0](https://www.ruby-lang.org)
38
+
39
+ # Setup
40
+
41
+ For a secure install, type the following (recommended):
42
+
43
+ gem cert --add <(curl -Ls https://raw.githubusercontent.com/pekhee/rspec-matcher/master/gem-public.pem)
44
+ gem install rspec-matcher --trust-policy MediumSecurity
45
+
46
+ NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while
47
+ allowing the installation of unsigned dependencies since they are beyond the scope of this gem.
48
+
49
+ For an insecure install, type the following (not recommended):
50
+
51
+ gem install rspec-matcher
52
+
53
+ Add the following to your Gemfile:
54
+
55
+ gem "rspec-matcher"
56
+
57
+ # Usage
58
+ [API Reference](http://www.rubydoc.info/github/pekhee/rspec-matcher/master)
59
+
60
+ class BeNilMatcher
61
+ include RSpec::Matcher
62
+ register_as "be_nil"
63
+
64
+ def match
65
+ actual.nil?
66
+ end
67
+
68
+ def failure_message
69
+ "expected #{expected} to be nil"
70
+ end
71
+ end
72
+
73
+ expect(nil).to be_nil
74
+
75
+ # Tests
76
+
77
+ To test, run:
78
+
79
+ bundle exec rake
80
+
81
+ # Versioning
82
+
83
+ Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
84
+
85
+ - Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
86
+ - Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
87
+ - Major (X.y.z) - Incremented for any backwards incompatible public API changes.
88
+
89
+ # Code of Conduct
90
+
91
+ Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By participating in this project
92
+ you agree to abide by its terms.
93
+
94
+ # Contributions
95
+
96
+ Read [CONTRIBUTING](CONTRIBUTING.md) for details.
97
+
98
+ # License
99
+
100
+ Copyright (c) 2016 [Pooyan Khosravi](https://www.github.com/pekhee).
101
+ Read the [LICENSE](LICENSE.md) for details.
102
+
103
+ # History
104
+
105
+ Read the [CHANGELOG](CHANGELOG.md) for details.
106
+ Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
107
+
108
+ # Credits
109
+
110
+ Developed by [Pooyan Khosravi](https://www.github.com/pekhee) at [Pooyan Khosravi](https://www.github.com/pekhee).
@@ -0,0 +1,23 @@
1
+ module RSpec
2
+ module Matcher
3
+ # Gem identity information.
4
+ # @api private
5
+ module Identity #:nodoc:
6
+ def self.name
7
+ "rspec-matcher"
8
+ end
9
+
10
+ def self.label
11
+ "RSpec::Matcher"
12
+ end
13
+
14
+ def self.version
15
+ "0.1.0"
16
+ end
17
+
18
+ def self.version_label
19
+ "#{label} #{version}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,158 @@
1
+ require "rspec/matcher/identity"
2
+ require "active_support/concern"
3
+
4
+ module RSpec
5
+ # Provides minimal interface for creating RSpec Matchers.
6
+ #
7
+ # Register matcher with RSpec via `register_as`.
8
+ #
9
+ # Include `RSpec::Matchers::Composable` to support composable matchers.
10
+ #
11
+ # @example
12
+ # class BeNil
13
+ # include RSpec::Matcher
14
+ # register_as "be_nil"
15
+ #
16
+ # def match
17
+ # return actual.nil?
18
+ # end
19
+ # end
20
+ #
21
+ # expect(actual).to be_nil
22
+ #
23
+ # ## Required Methods:
24
+ # - `match`
25
+ #
26
+ # ## Optional Methods:
27
+ # - `description`
28
+ # - `failure_message`
29
+ # - `failure_message_when_negated`
30
+ # - `diffable?`
31
+ # - `supports_block_expectations?`
32
+ module Matcher
33
+ extend ActiveSupport::Concern
34
+
35
+ # To indicate no value was passed to matcher
36
+ UNDEFINED = Object.new.freeze
37
+
38
+ included do
39
+ prepend RSpec::Matcher::PrependedMethods
40
+
41
+ attr_accessor :expected, :actual
42
+ end
43
+
44
+ # @api private
45
+ # Used to let user define initialize
46
+ module PrependedMethods #:nodoc:
47
+ # Stores expected and passes all args to super
48
+ # @api private
49
+ # @param [any] expected stored as expected and not passed to custom initializer
50
+ # @param [any] args... passed to custom initializer
51
+ # @param [Proc] block passed to custom initializer
52
+ def initialize expected = UNDEFINED, *args, &block
53
+ self.expected = expected
54
+ super(*args, &block)
55
+ end
56
+ end
57
+
58
+ # Methods added as class method to includer
59
+ module ClassMethods
60
+ # Registers this matcher in RSpec.
61
+ # @example
62
+ # class BeNil
63
+ # include RSpec::Matcher
64
+ # register_as "be_nil"
65
+ # #...
66
+ # end
67
+ #
68
+ # expect(actual).to be_nil
69
+ #
70
+ # @param [String] name what to register this matcher as
71
+ # @return [void]
72
+ def register_as name
73
+ s = self
74
+ m = Module.new do
75
+ define_method name do |*args, &block|
76
+ s.new(*args, &block)
77
+ end
78
+ end
79
+
80
+ RSpec.configure do |config|
81
+ config.include m
82
+ end
83
+ end
84
+ end
85
+
86
+ # @api private
87
+ # Hides RSpec internal api
88
+ def matches? actual
89
+ self.actual = actual
90
+ return match if method(:match).arity == 0
91
+
92
+ match actual
93
+ end
94
+
95
+ # @method actual
96
+ # @example expect(actual).to be(expected)
97
+ # @return [any] value passed to `expect()`
98
+
99
+ # @method expected
100
+ # @example expect(actual).to be(expected)
101
+ # @return [any] value passed to matcher function.
102
+
103
+ # @method initialize
104
+ # First argument passed to matcher is placed in expected and removed from
105
+ # arg list. Every argument beside that including a block is passed to
106
+ # initialize function.
107
+
108
+ # Determines if there is a match or not.
109
+ # @note Must be implemented.
110
+ # @param [any] actual same as actual method.
111
+ # @return [Boolean] true for success, false for failure.
112
+ def match _ = nil
113
+ raise "not implemented"
114
+ end
115
+
116
+ # Describes what this matcher does for composable matchers.
117
+ # @example be an string with X length
118
+ # @example match X regex
119
+ # @note raises by default
120
+ # @return [String]
121
+ def description
122
+ raise "not implemented"
123
+ end
124
+
125
+ # Describe failure.
126
+ # @example "expected EXPECTED to be of length X"
127
+ # @example "expected EXPECTED to match X"
128
+ # @note raises by default
129
+ # @return [String]
130
+ def failure_message
131
+ raise "not implemented"
132
+ end
133
+
134
+ # Describe failure when not_to is used.
135
+ # @example "expected EXPECTED not to be of length X"
136
+ # @example "expected EXPECTED not to match X"
137
+ # @note raises by default
138
+ # @return [String]
139
+ def failure_message_when_negated
140
+ raise "not implemented"
141
+ end
142
+
143
+ # Indicates if actual and expected should be diffed on failure.
144
+ # @note false by default
145
+ # @return [Boolean]
146
+ def diffable?
147
+ false
148
+ end
149
+
150
+ # Indicates if actual can be a block.
151
+ # @example expect { something }.not_to raise_error
152
+ # @note false by default
153
+ # @return [Boolean]
154
+ def supports_block_expectations?
155
+ false
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require "rspec/core/rake_task"
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ rescue LoadError => error
5
+ puts error.message
6
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require "rubocop/rake_task"
3
+ RuboCop::RakeTask.new
4
+ rescue LoadError => error
5
+ puts error.message
6
+ end
metadata ADDED
@@ -0,0 +1,283 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pooyan Khosravi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: gemsmith
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: pry
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry-byebug
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry-remote
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: pry-state
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: pry-rescue
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: pry-stack_explorer
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: rspec
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: rb-fsevent
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: guard-rspec
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: terminal-notifier
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: terminal-notifier-guard
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ - !ruby/object:Gem::Dependency
216
+ name: rubocop
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ - !ruby/object:Gem::Dependency
230
+ name: codeclimate-test-reporter
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ description: RSpec Base Matcher implementation with automatic registration as a module.
244
+ email:
245
+ - pekhee@gmail.com
246
+ executables: []
247
+ extensions: []
248
+ extra_rdoc_files:
249
+ - README.md
250
+ - LICENSE.md
251
+ files:
252
+ - LICENSE.md
253
+ - README.md
254
+ - lib/rspec/matcher.rb
255
+ - lib/rspec/matcher/identity.rb
256
+ - lib/tasks/rspec.rake
257
+ - lib/tasks/rubocop.rake
258
+ homepage: https://github.com/pekhee/rspec-matcher
259
+ licenses:
260
+ - MIT
261
+ metadata: {}
262
+ post_install_message:
263
+ rdoc_options: []
264
+ require_paths:
265
+ - lib
266
+ required_ruby_version: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - ">="
269
+ - !ruby/object:Gem::Version
270
+ version: '2.1'
271
+ required_rubygems_version: !ruby/object:Gem::Requirement
272
+ requirements:
273
+ - - ">="
274
+ - !ruby/object:Gem::Version
275
+ version: '0'
276
+ requirements: []
277
+ rubyforge_project:
278
+ rubygems_version: 2.4.5.1
279
+ signing_key:
280
+ specification_version: 4
281
+ summary: Implements RSpec Matcher interface as a module.
282
+ test_files: []
283
+ has_rdoc: