rspec_matcher_define_constant 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41a9814445636eee6c7c5bf83d9102eb53d9be91
4
+ data.tar.gz: 2885e0ae1c02f0d296604f8723fee95fe15a1c96
5
+ SHA512:
6
+ metadata.gz: 1b838ae634a004909c276eee822dd50afcc7a24febe8da55040bb2a9d14fb7bfc8f81d2c650d2f10853e6082fc7d83de9c79a4608e08d6bea98362625fcc127b
7
+ data.tar.gz: 89f150577854b771d19434db5ee0ff26b6916afb2e292ff5791b7f048055ab0b8e3073f02eeaf01f32f06844885447547ec7338bfaee469afa47f16037233a51
@@ -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,7 @@
1
+ require "rspec_matcher_define_constant/identity"
2
+ require "rspec_matcher_define_constant/matcher"
3
+
4
+ # Makes sure block defines a constant and removes the constant after block is
5
+ # done.
6
+ module RSpecMatcherDefineConstant
7
+ end
@@ -0,0 +1,20 @@
1
+ module RSpecMatcherDefineConstant
2
+ # Gem identity information.
3
+ module Identity
4
+ def self.name
5
+ "rspec_matcher_define_constant"
6
+ end
7
+
8
+ def self.label
9
+ "RSpecMatcherDefineConstant"
10
+ end
11
+
12
+ def self.version
13
+ "0.1.0"
14
+ end
15
+
16
+ def self.version_label
17
+ "#{label} #{version}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,96 @@
1
+ # runs block, checks if it defines constant, removes defined constant
2
+ RSpec::Matchers.define :define_constant do |expected|
3
+ attr_accessor :message, :actual
4
+
5
+ match do |actual|
6
+ self.actual = actual
7
+ validate_input
8
+
9
+ begin
10
+ decision
11
+ # rubocop:disable Lint/RescueException
12
+ rescue Exception # it's fine, we're reraising exception
13
+ # rubocop:enable Lint/RescueException
14
+ remove_expected
15
+ raise
16
+ end
17
+ end
18
+
19
+ chain :of_type, :type
20
+
21
+ failure_message do
22
+ "expected that block defines #{expected} but #{message}"
23
+ end
24
+
25
+ supports_block_expectations
26
+
27
+ private
28
+
29
+ def validate_input
30
+ return :ok if actual.is_a? Proc
31
+ fail ArgumentError, "define constant needs a proc"
32
+ end
33
+
34
+ def decision
35
+ return @decision unless @decision.nil?
36
+ @decision = catch(:decision) { passes? }
37
+ remove_expected
38
+
39
+ @decision
40
+ end
41
+
42
+ def passes?
43
+ expected_shouldnt_exist
44
+ actual.call
45
+ expected_should_exist
46
+
47
+ expected_should_have_correct_type
48
+
49
+ throw :decision, true
50
+ end
51
+
52
+ def expected_exists?
53
+ Object.const_defined? expected
54
+ end
55
+
56
+ def expected_shouldnt_exist
57
+ return true unless expected_exists?
58
+
59
+ dont_remove_expected
60
+ self.message = "#{expected} was already defined"
61
+ throw :decision, false
62
+ end
63
+
64
+ def expected_should_exist
65
+ return true if expected_exists?
66
+
67
+ self.message = "#{expected} did not get defined"
68
+ throw :decision, false
69
+ end
70
+
71
+ def expected_should_have_correct_type
72
+ return true if type.nil?
73
+
74
+ const = Object.const_get(expected)
75
+ const = const.class unless [Class, Module].include? const.class
76
+
77
+ return true if const <= type
78
+
79
+ self.message = "#{expected} is not of type #{type} its ancestors are #{const.ancestors}"
80
+ throw :decision, false
81
+ end
82
+
83
+ def remove_expected
84
+ return nil unless remove_expected? && expected_exists?
85
+ Object.send(:remove_const, expected)
86
+ end
87
+
88
+ def remove_expected?
89
+ return true if @remove_expected.nil?
90
+ @remove_expected
91
+ end
92
+
93
+ def dont_remove_expected
94
+ @remove_expected = false
95
+ end
96
+ 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,266 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_matcher_define_constant
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-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: gemsmith
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-remote
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-state
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-rescue
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rb-fsevent
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: terminal-notifier
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: terminal-notifier-guard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: codeclimate-test-reporter
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description: |-
224
+ RSpec matcher define_constant. Runs block and tracks all defined constants
225
+ to make sure specified constant name gets defined. Removes defined constant
226
+ after expectation
227
+ email:
228
+ - pekhee@gmail.com
229
+ executables: []
230
+ extensions: []
231
+ extra_rdoc_files:
232
+ - README.md
233
+ - LICENSE.md
234
+ files:
235
+ - LICENSE.md
236
+ - README.md
237
+ - lib/rspec_matcher_define_constant.rb
238
+ - lib/rspec_matcher_define_constant/identity.rb
239
+ - lib/rspec_matcher_define_constant/matcher.rb
240
+ - lib/tasks/rspec.rake
241
+ - lib/tasks/rubocop.rake
242
+ homepage: https://github.com//rspec_matcher_define_constant
243
+ licenses:
244
+ - MIT
245
+ metadata: {}
246
+ post_install_message:
247
+ rdoc_options: []
248
+ require_paths:
249
+ - lib
250
+ required_ruby_version: !ruby/object:Gem::Requirement
251
+ requirements:
252
+ - - ">="
253
+ - !ruby/object:Gem::Version
254
+ version: '0'
255
+ required_rubygems_version: !ruby/object:Gem::Requirement
256
+ requirements:
257
+ - - ">="
258
+ - !ruby/object:Gem::Version
259
+ version: '0'
260
+ requirements: []
261
+ rubyforge_project:
262
+ rubygems_version: 2.4.5.1
263
+ signing_key:
264
+ specification_version: 4
265
+ summary: RSpec matcher to make sure block defines constant
266
+ test_files: []