rspec-matchers-define_constant 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cee4893d6dca296de762a92fbeca8ae74c15347
4
+ data.tar.gz: daa8f45752f72ce6f2a2cd0015cf3636d759f00e
5
+ SHA512:
6
+ metadata.gz: 61acd1aa9f6944cbaa13f2ac19be3406de3966dd4c426f3626267e75b294e0204115c12bffca026010ab8bf236c37a83ff14a508624acd6ea1d012d4d5eb3639
7
+ data.tar.gz: 99b72f5fb88a2a310ed11f5535dff47f9ab9d90b6038cc29c5e43b0a6a78ec756e7fa94192f47734bcb1800e391566c9fe22b5b19f1dd62c6967097c35b3d093
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 []().
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.
@@ -0,0 +1,94 @@
1
+ # RSpec Matcher `define_constant(constant_name).of_type(Type)`
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rspec_matcher_define_constant.svg)](http://badge.fury.io/rb/rspec_matcher_define_constant)
4
+ [![Code Climate GPA](https://codeclimate.com/github/pekhee/rspec_matcher_define_constant.svg)](https://codeclimate.com/github/pekhee/rspec_matcher_define_constant)
5
+ [![Code Climate Coverage](https://codeclimate.com/github/pekhee/rspec_matcher_define_constant/coverage.svg)](https://codeclimate.com/github/pekhee/rspec_matcher_define_constant)
6
+ [![Gemnasium Status](https://gemnasium.com/pekhee/rspec_matcher_define_constant.svg)](https://gemnasium.com/pekhee/rspec_matcher_define_constant)
7
+ [![Travis CI Status](https://secure.travis-ci.org/pekhee/rspec_matcher_define_constant.svg)](https://travis-ci.org/pekhee/rspec_matcher_define_constant)
8
+
9
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
10
+
11
+ # Table of Contents
12
+
13
+ - [Features](#features)
14
+ - [Requirements](#requirements)
15
+ - [Setup](#setup)
16
+ - [Usage](#usage)
17
+ - [Tests](#tests)
18
+ - [Versioning](#versioning)
19
+ - [Code of Conduct](#code-of-conduct)
20
+ - [Contributions](#contributions)
21
+ - [License](#license)
22
+ - [History](#history)
23
+ - [Credits](#credits)
24
+
25
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
26
+
27
+ # Features
28
+ Makes sure block defines a constant and removes the constant after block is done.
29
+
30
+ # Requirements
31
+
32
+ 0. [MRI 2.x](https://www.ruby-lang.org)
33
+ 1. [RSpec 3.x](http://rspec.info)
34
+
35
+ # Setup
36
+ To install, type the following:
37
+
38
+ gem install rspec_matcher_define_constant
39
+
40
+ Add the following to your Gemfile:
41
+
42
+ gem "rspec_matcher_define_constant"
43
+
44
+ # Usage
45
+
46
+ RSpec.describe "a block that defines a constant" do
47
+ subject do
48
+ proc do
49
+ Object.const_set "Stuff", 1
50
+ end
51
+ end
52
+
53
+ it "defines Stuff" do
54
+ expect { subject.call }.to define_constant "Stuff"
55
+ # Stuff is not defined here.
56
+ end
57
+ end
58
+
59
+ # Tests
60
+
61
+ To test, run:
62
+
63
+ bundle exec rake
64
+
65
+ # Versioning
66
+
67
+ Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
68
+
69
+ - Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
70
+ - Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
71
+ - Major (X.y.z) - Incremented for any backwards incompatible public API changes.
72
+
73
+ # Code of Conduct
74
+
75
+ Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By participating in this project
76
+ you agree to abide by its terms.
77
+
78
+ # Contributions
79
+
80
+ Read [CONTRIBUTING](CONTRIBUTING.md) for details.
81
+
82
+ # License
83
+
84
+ Copyright (c) 2016 [Pooyan Khosravi]().
85
+ Read the [LICENSE](LICENSE.md) for details.
86
+
87
+ # History
88
+
89
+ Read the [CHANGELOG](CHANGELOG.md) for details.
90
+ Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
91
+
92
+ # Credits
93
+
94
+ Developed by [Pooyan Khosravi]().
@@ -0,0 +1,12 @@
1
+ require "rspec/matchers/define_constant/identity"
2
+ require "rspec/matcher"
3
+ require "rspec/matchers/define_constant/matcher"
4
+
5
+ module RSpec
6
+ module Matchers
7
+ # Makes sure block defines a constant and removes the constant after block is
8
+ # done.
9
+ module DefineConstant
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module RSpec
2
+ module Matchers
3
+ module DefineConstant
4
+ # Gem identity information.
5
+ module Identity
6
+ def self.name
7
+ "rspec-matchers-define_constant"
8
+ end
9
+
10
+ def self.label
11
+ "RSpec::Matchers::DefineConstant"
12
+ end
13
+
14
+ def self.version
15
+ "0.1.1"
16
+ end
17
+
18
+ def self.version_label
19
+ "#{label} #{version}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,81 @@
1
+ module RSpec
2
+ module Matchers
3
+ module DefineConstant
4
+ # runs block, checks if it defines constant, removes defined constant
5
+ class Matcher
6
+ include RSpec::Matcher
7
+ register_as :define_constant
8
+ attr_accessor :type
9
+
10
+ def match
11
+ validate_input
12
+ expected_shouldnt_exist
13
+ actual.call
14
+ expected_should_exist
15
+ expected_should_have_correct_type
16
+
17
+ true
18
+ end
19
+
20
+ def description
21
+ "define constant"
22
+ end
23
+
24
+ def supports_block_expectations?
25
+ true
26
+ end
27
+
28
+ def of_type type
29
+ self.type = type and self
30
+ end
31
+
32
+ private
33
+
34
+ def validate_input
35
+ actual.is_a? Proc or raise ArgumentError, "define constant needs a proc"
36
+ end
37
+
38
+ def expected_exists?
39
+ Object.const_defined? expected
40
+ end
41
+
42
+ def expected_shouldnt_exist
43
+ return true unless expected_exists?
44
+
45
+ dont_remove_expected
46
+ reject_expectation "#{expected} was already defined"
47
+ end
48
+
49
+ def expected_should_exist
50
+ expected_exists? or reject_expectation "#{expected} did not get defined"
51
+ end
52
+
53
+ def expected_should_have_correct_type
54
+ return true if type.nil?
55
+
56
+ const = Object.const_get(expected)
57
+ const = const.class unless [Class, Module].include? const.class
58
+
59
+ return true if const <= type
60
+
61
+ reject_expectation "#{expected} is not of type #{type} its ancestors are #{const.ancestors}"
62
+ end
63
+
64
+ def remove_expected
65
+ return nil unless remove_expected? && expected_exists?
66
+ Object.send(:remove_const, expected)
67
+ end
68
+ alias_method :clean_up, :remove_expected
69
+
70
+ def remove_expected?
71
+ return true if @remove_expected.nil?
72
+ @remove_expected
73
+ end
74
+
75
+ def dont_remove_expected
76
+ @remove_expected = false
77
+ end
78
+ end
79
+ end
80
+ end
81
+ 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,287 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-matchers-define_constant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Pooyan Khosravi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-matcher
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.5
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 0.2.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.5
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
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: gemsmith
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
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-byebug
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-remote
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-state
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-rescue
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: pry-stack_explorer
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: |-
244
+ RSpec matcher define_constant. Runs block and tracks all defined constants
245
+ to make sure specified constant name gets defined. Removes defined constant
246
+ after expectation
247
+ email:
248
+ - pekhee@gmail.com
249
+ executables: []
250
+ extensions: []
251
+ extra_rdoc_files:
252
+ - README.md
253
+ - LICENSE.md
254
+ files:
255
+ - LICENSE.md
256
+ - README.md
257
+ - lib/rspec/matchers/define_constant.rb
258
+ - lib/rspec/matchers/define_constant/identity.rb
259
+ - lib/rspec/matchers/define_constant/matcher.rb
260
+ - lib/tasks/rspec.rake
261
+ - lib/tasks/rubocop.rake
262
+ homepage: https://github.com/pekhee/rspec-matchers-define_constant
263
+ licenses:
264
+ - MIT
265
+ metadata: {}
266
+ post_install_message:
267
+ rdoc_options: []
268
+ require_paths:
269
+ - lib
270
+ required_ruby_version: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - ">="
273
+ - !ruby/object:Gem::Version
274
+ version: '0'
275
+ required_rubygems_version: !ruby/object:Gem::Requirement
276
+ requirements:
277
+ - - ">="
278
+ - !ruby/object:Gem::Version
279
+ version: '0'
280
+ requirements: []
281
+ rubyforge_project:
282
+ rubygems_version: 2.4.5.1
283
+ signing_key:
284
+ specification_version: 4
285
+ summary: RSpec matcher to make sure block defines constant
286
+ test_files: []
287
+ has_rdoc: