rspec_be_type_of_matcher 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
+ SHA256:
3
+ metadata.gz: 68c6d2e7d8ea6015c225a59bacf96283547c973219e12241bdf1604aded74257
4
+ data.tar.gz: 0df986b89b5a21332a378ca43950e4e760e9b7eceb8fc236fcb31027697e848e
5
+ SHA512:
6
+ metadata.gz: be13f4d16f14bbba0e3da7d559b5e11573d49ad9034f7742e958d3a72fad3c2dcc23e59f1a31287e4c0b3d3b2fc1f6d7b7ed81591307b036d26d5f4724757a7a
7
+ data.tar.gz: 65dbfc16a5a399a55751177ab7394ad4148174f3bdd80dadd5bc29d1523faf6cb2421f88df059b8f1f55ae3445206a10d86f0a5152360aa688357b0ebeb72b75
@@ -0,0 +1,161 @@
1
+ c
2
+ failure_message
3
+ object
4
+ s
5
+ description
6
+ s
7
+ n
8
+ @failure_message
9
+ n
10
+ c
11
+ message
12
+ n
13
+ message
14
+ n
15
+ c
16
+ n
17
+ message
18
+ n
19
+ message
20
+ @failure_message
21
+ c
22
+ n
23
+ @failure_message
24
+ message
25
+ c
26
+ @failure_message
27
+ n
28
+ s
29
+ n
30
+ expected_type
31
+ actual
32
+ n
33
+ s
34
+ val
35
+ s
36
+ n
37
+ expected_type
38
+ n
39
+ s
40
+ n
41
+ c
42
+ @actual_error
43
+ n
44
+ s
45
+ n
46
+ s
47
+ c
48
+ n
49
+ orig_notifier
50
+ n
51
+ expected_type.size > 1
52
+ s
53
+ n
54
+ s
55
+ c
56
+ n
57
+ expected_type
58
+ actual
59
+ s
60
+ n
61
+ s
62
+ c
63
+ n
64
+ s
65
+ n
66
+ c
67
+ s
68
+ actual.map{|val| BeTypeOfMatcher.values_match?(value_type, val, or_nil) }
69
+ actual.all?{|val| BeTypeOfMatcher.values_match?(value_type, val, or_nil) }
70
+ value_type
71
+ n
72
+ actual
73
+ s
74
+ n
75
+ s
76
+ n
77
+ s
78
+ types
79
+ c
80
+ @or_nil
81
+ c
82
+ s
83
+ c
84
+ s
85
+ n
86
+ s
87
+ n
88
+ s
89
+ n
90
+ s
91
+ n
92
+ s
93
+ n
94
+ s
95
+ n
96
+ s
97
+ c
98
+ n
99
+ c
100
+ n
101
+ block.arity.zero?
102
+ s
103
+ n
104
+ s
105
+ n
106
+ s
107
+ n
108
+ s
109
+ n
110
+ s
111
+ c
112
+ n
113
+ s
114
+ n
115
+ s
116
+ n
117
+ s
118
+ n
119
+ s
120
+ c
121
+ n
122
+ message
123
+ n
124
+ s
125
+ n
126
+ s
127
+ @actual
128
+ n
129
+ self
130
+ s
131
+ n
132
+ initial_matcher
133
+ s
134
+ matcher
135
+ n
136
+ s
137
+ n
138
+ matcher
139
+ n
140
+ s
141
+ be_type_of(String).matches?("foo")
142
+ be_type_of(String).match?
143
+ be_type_of(String)
144
+ be_type_of
145
+ c
146
+ n
147
+ name
148
+ expected
149
+ name
150
+ n
151
+ name
152
+ n
153
+ name
154
+ s
155
+ c
156
+ q
157
+ c
158
+ matcher
159
+ n
160
+ name
161
+ s
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,387 @@
1
+ # target_version:
2
+ # rubocop v0.34.2
3
+ #
4
+ # https://gist.github.com/onk/38bfbd78899d892e0e83
5
+ require:
6
+ - "rubocop-rails"
7
+
8
+ # 自動生成されるものはチェック対象から除外する
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
11
+ Exclude:
12
+ - "vendor/**/*" # rubocop config/default.yml
13
+ - "db/schema.rb"
14
+ - "bin/**/*"
15
+ DisplayCopNames: true
16
+
17
+ ##################### Style ##################################
18
+
19
+ # redirect_to xxx and return のイディオムを維持したい
20
+ Style/AndOr:
21
+ EnforcedStyle: conditionals
22
+
23
+ # 日本語のコメントを許可する
24
+ Style/AsciiComments:
25
+ Enabled: false
26
+
27
+ Style/BlockDelimiters:
28
+ Enabled: false
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ Enabled: false
32
+
33
+ # option 等、明示的にハッシュにした方が分かりやすい場合もある
34
+ Style/BracesAroundHashParameters:
35
+ Enabled: false
36
+
37
+ # Style/CollectionMethods 自体は無効になっているのだが、
38
+ # https://github.com/bbatsov/rubocop/issues/1084
39
+ # https://github.com/bbatsov/rubocop/issues/1334
40
+ # Performance/Detect がこの設定値を見るので PreferredMethods だけ変更しておく。
41
+ #
42
+ # デフォルト値から変えたのは
43
+ # find -> detect
44
+ # ActiveRecord の find と間違えやすいため
45
+ # reduce -> inject
46
+ # detect, reject, select と並べたときに韻を踏んでいるため。
47
+ # collect -> map を維持しているのは文字数が圧倒的に少ないため。
48
+ Style/CollectionMethods:
49
+ PreferredMethods:
50
+ inject: "inject"
51
+ reduce: "inject"
52
+
53
+ # Hash#has_key? は許可したい
54
+ # Style/DeprecatedHashMethods:
55
+ # Enabled: false
56
+
57
+ # ドキュメントの無い public class を許可する
58
+ Style/Documentation:
59
+ Enabled: false
60
+
61
+ # !! のイディオムは積極的に使う
62
+ Style/DoubleNegation:
63
+ Enabled: false
64
+
65
+ # 明示的に else で nil を返すのは分かりやすいので許可する
66
+ Style/EmptyElse:
67
+ EnforcedStyle: empty
68
+
69
+ # いずれかに揃えるのならば `sprintf` や `format` より String#% が好きです
70
+ Style/FormatString:
71
+ EnforcedStyle: percent
72
+
73
+ # if 文の中に 3 行程度のブロックを書くぐらいは許容した方が現実的
74
+ Style/GuardClause:
75
+ MinBodyLength: 5
76
+
77
+ # rake タスクの順序の hash は rocket を許可する
78
+ Style/HashSyntax:
79
+ Exclude:
80
+ - "**/*.rake"
81
+ - "Rakefile"
82
+
83
+ # 複数行の3項演算子を許可する
84
+ Style/MultilineTernaryOperator:
85
+ Enabled: false
86
+
87
+ # 条件式の方を意識させたい場合には後置の if/unless を使わない方が分かりやすい
88
+ Style/IfUnlessModifier:
89
+ Enabled: false
90
+
91
+ # scope 等は複数行でも lambda ではなく ->{} で揃えた方が見た目が綺麗
92
+ Style/Lambda:
93
+ Enabled: false
94
+
95
+ Style/LambdaCall:
96
+ EnforcedStyle: braces
97
+
98
+ # num < 0 のかわりに num.negative? はrubyだけの書き方なので
99
+ Style/NumericPredicate:
100
+ Enabled: false
101
+
102
+ # 特に model 内において、ローカル変数とメソッド呼び出しの区別をつけた方が分かりやすい場合が多い
103
+ Style/RedundantSelf:
104
+ Enabled: false
105
+
106
+ # injectなどで使うので
107
+ Style/Semicolon:
108
+ Enabled: false
109
+
110
+ # 受け取り側で multiple assignment しろというのを明示
111
+ Style/RedundantReturn:
112
+ AllowMultipleReturnValues: true
113
+
114
+ # fail と使い分ける必要ナシ
115
+ Style/SignalException:
116
+ EnforcedStyle: only_raise
117
+
118
+ # * 式展開したい場合に書き換えるのが面倒
119
+ # * 文章ではダブルクォートよりもシングルクォートの方が頻出する
120
+ # ことから EnforcedStyle: double_quotes 推奨
121
+ Style/StringLiterals:
122
+ EnforcedStyle: double_quotes
123
+
124
+ # auto-correct 時に Style/StringLiterals とカニバって無限ループになる (v0.28.0)
125
+ Style/StringLiteralsInInterpolation:
126
+ Enabled: false
127
+
128
+ # いくらなんでも inject { |a, e| } は短すぎるので分かりやすい名前をつけたい
129
+ Style/SingleLineBlockParams:
130
+ Enabled: false
131
+
132
+ Style/WordArray:
133
+ Enabled: false
134
+
135
+ # 複数行の場合はケツカンマを入れる
136
+ Style/TrailingCommaInArrayLiteral:
137
+ EnforcedStyleForMultiline: comma
138
+ Style/TrailingCommaInHashLiteral:
139
+ EnforcedStyleForMultiline: comma
140
+
141
+ # method_body, line = <<-EOV, __LINE__ + 1
142
+ # みたいなやつのために無効にする
143
+ Style/ParallelAssignment:
144
+ Enabled: false
145
+
146
+ # 1行で書かれたメソッドを許可する
147
+ Style/SingleLineMethods:
148
+ Enabled: false
149
+
150
+ # Foo::Bar形式のclass/module宣言を許可する
151
+ Style/ClassAndModuleChildren:
152
+ Enabled: false
153
+
154
+ # each_with_objectは嫌いなのです
155
+ Style/EachWithObject:
156
+ Enabled: false
157
+
158
+ # FactroyGrilのDSLが壊れるので除外
159
+ Style/SymbolProc:
160
+ Exclude:
161
+ - "spec/factories/*.rb"
162
+
163
+ # resuce を後置で使うことを許可する
164
+ Style/RescueModifier:
165
+ Enabled: false
166
+
167
+ # かえって読みにくいので
168
+ Style/SymbolArray:
169
+ Enabled: false
170
+
171
+ # 可読性のために()つけることがあるので
172
+ Style/TernaryParentheses:
173
+ Enabled: false
174
+
175
+ # "%s" % foo のような1引数の場合にも名前つけるのはダルい
176
+ Style/FormatStringToken:
177
+ Enabled: false
178
+
179
+ # 省略せずに明示的に -(){ .. } と書いたほうがlambdaであると視認しやすい
180
+ Style/EmptyLambdaParameter:
181
+ Enabled: false
182
+
183
+ Style/NumericLiterals:
184
+ Enabled: false
185
+
186
+ Style/IfInsideElse:
187
+ Enabled: false
188
+
189
+ Style/RescueStandardError:
190
+ Enabled: false
191
+
192
+ Style/WhileUntilModifier:
193
+ Enabled: false
194
+
195
+ Style/MultipleComparison:
196
+ Enabled: false
197
+
198
+ ##################### Layout ###############################
199
+
200
+ # メソッドチェーンの改行は末尾に . を入れる
201
+ # REPL に貼り付けた際の暴発を防ぐため
202
+ Layout/DotPosition:
203
+ EnforcedStyle: trailing
204
+
205
+ # 桁揃えが綺麗にならないことが多いので migration は除外
206
+ Layout/ExtraSpacing:
207
+ # Enabled: false
208
+ AllowForAlignment: true
209
+ Exclude:
210
+ - "db/migrate/*.rb"
211
+
212
+ # ({ と hash を開始した場合に ( の位置にインデントさせる
213
+ # そもそも {} が必要ない可能性が高いが Layout/BracesAroundHashParameters はチェックしないことにしたので
214
+ Layout/FirstHashElementIndentation:
215
+ EnforcedStyle: consistent
216
+
217
+ # private/protected は一段深くインデントする
218
+ Layout/IndentationConsistency:
219
+ EnforcedStyle: indented_internal_methods
220
+
221
+ # Hashのkey, valueの位置合わせ
222
+ Layout/HashAlignment:
223
+ EnforcedColonStyle: table
224
+ EnforcedHashRocketStyle: table
225
+
226
+ # メソッド呼び出しの2行目以降のパラメータの
227
+ # インデントを固定する
228
+ Layout/ParameterAlignment:
229
+ EnforcedStyle: with_fixed_indentation
230
+
231
+ # case式のwhenのインデントを一段下げる
232
+ Layout/CaseIndentation:
233
+ EnforcedStyle: 'end'
234
+ IndentOneStep: false
235
+
236
+ # `||` も align に使うことがあるので追加する
237
+ Layout/SpaceAroundOperators:
238
+ AllowForAlignment: true
239
+
240
+ # * migrate
241
+ # * jbuilder
242
+ # * model の association
243
+ # * controller の callback
244
+ # 辺りの桁揃えで引っかかるので全体的にチェックしない
245
+ Layout/SpaceBeforeFirstArg:
246
+ Enabled: false
247
+
248
+ # ブロック呼び出しでメソッドと{の間のスペースを許可しない
249
+ # specやformat.json { ... とかで桁合わせしたい場合もあるので無効
250
+ Layout/SpaceBeforeBlockBraces:
251
+ Enabled: false
252
+ # EnforcedStyle: no_space
253
+
254
+ # ブロック引数の前のスペースは不要
255
+ Layout/SpaceInsideBlockBraces:
256
+ SpaceBeforeBlockParameters: false
257
+
258
+ # 文字列中の式展開でスペースをつける
259
+ Layout/SpaceInsideStringInterpolation:
260
+ # EnforcedStyle: space
261
+ Enabled: false # どちらでも許可する
262
+
263
+ ##################### Namging ###############################
264
+ Naming/MethodParameterName:
265
+ Enabled: false
266
+
267
+ Naming/MemoizedInstanceVariableName:
268
+ Enabled: false
269
+
270
+ Naming/PredicateName:
271
+ Enabled: false
272
+
273
+ Naming/AccessorMethodName:
274
+ Enabled: false
275
+
276
+ ##################### Lint ##################################
277
+
278
+ # * 同名のメソッドがある場合にローカル変数に `_` を付ける
279
+ # * 一時変数として `_` を付ける
280
+ # というテクニックは頻出する
281
+ Lint/UnderscorePrefixedVariableName:
282
+ Enabled: false
283
+
284
+ # 子クラスで実装させるつもりのメソッドで引っかかるので
285
+ Lint/UnusedMethodArgument:
286
+ Enabled: false
287
+
288
+ # modelのscopeとかで使うので
289
+ Lint/AmbiguousBlockAssociation:
290
+ Exclude:
291
+ - "app/models/**/*.rb"
292
+ - "spec/**/*.rb"
293
+
294
+ # specでは == をmatcherで使うので
295
+ Lint/Void:
296
+ Exclude:
297
+ - "spec/**/*_spec.rb"
298
+
299
+ Lint/RescueException:
300
+ Enabled: false
301
+
302
+ Lint/MultipleComparison:
303
+ Enabled: false
304
+
305
+ ##################### Metrics ##################################
306
+
307
+ # 30 まではギリギリ許せる範囲だった
308
+ Metrics/AbcSize:
309
+ Max: 40
310
+
311
+ # 6 は強すぎるので緩める
312
+ Metrics/CyclomaticComplexity:
313
+ Max: 10
314
+
315
+ # * 警告 120文字
316
+ # * 禁止 160文字
317
+ # のイメージ
318
+ Layout/LineLength:
319
+ Max: 160
320
+ Exclude:
321
+ - "db/migrate/*.rb"
322
+
323
+ # クラスは300まで
324
+ Metrics/ClassLength:
325
+ Max: 300
326
+ Exclude:
327
+ - "db/migrate/*.rb"
328
+
329
+ # クラスは300まで
330
+ Metrics/ModuleLength:
331
+ Max: 300
332
+ Exclude:
333
+ - "db/migrate/*.rb"
334
+
335
+ # メソッドは30 行まで
336
+ Metrics/MethodLength:
337
+ Max: 30
338
+ Exclude:
339
+ - "db/migrate/*.rb"
340
+
341
+ # 分岐の数。ガード句を多用しているとデフォルト 7 だと厳しい
342
+ Metrics/PerceivedComplexity:
343
+ Max: 8
344
+
345
+ # specのexpamleは長くなりがちなので
346
+ Metrics/BlockLength:
347
+ Exclude:
348
+ - "spec/**/*.rb"
349
+ - "config/routes.rb"
350
+ - "config/deploy.rb"
351
+ - "config/deploy/**/*.rb"
352
+ - "lib/tasks/**/*.rake"
353
+ - "app/main.rb"
354
+ ExcludedMethods:
355
+ - "class_methods"
356
+
357
+ Metrics/ParameterLists:
358
+ CountKeywordArgs: false
359
+
360
+ ##################### Rails ##################################
361
+ Rails:
362
+ Enabled: false
363
+
364
+ Rails/ActionFilter:
365
+ Enabled: false
366
+
367
+ # わかったうえで無効にしてる
368
+ Rails/TimeZone:
369
+ Enabled: false
370
+
371
+ Rails/Date:
372
+ Enabled: false
373
+
374
+ # あえてvalidationをskipしたいこともあるので
375
+ Rails/SkipsModelValidations:
376
+ Enabled: false
377
+
378
+ Rails/HasManyOrHasOneDependent:
379
+ Enabled: false
380
+
381
+ Rails/Exit:
382
+ Exclude:
383
+ - "app/tasks/task.rb"
384
+
385
+ Bundler/OrderedGems:
386
+ Enabled: false
387
+
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ozaki@yuroyoro.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rspec_be_type_of_matcher.gemspec
6
+ gemspec
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspec_be_type_of_matcher (0.1.0)
5
+ rspec (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (11.1.3)
11
+ coderay (1.1.3)
12
+ diff-lcs (1.4.4)
13
+ method_source (1.0.0)
14
+ pry (0.13.1)
15
+ coderay (~> 1.1)
16
+ method_source (~> 1.0)
17
+ pry-byebug (3.9.0)
18
+ byebug (~> 11.0)
19
+ pry (~> 0.13.0)
20
+ rake (12.3.3)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.2)
26
+ rspec-support (~> 3.9.3)
27
+ rspec-expectations (3.9.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.3)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.17)
40
+ pry-byebug
41
+ rake (~> 12.3)
42
+ rspec_be_type_of_matcher!
43
+
44
+ BUNDLED WITH
45
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Tomohito Ozaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,173 @@
1
+ # RspecBeTypeOfMatcher
2
+
3
+ Rspec matchers for strucural type assertion. Compare values of array to have all expeted_type, hash's key and value are expeted type.
4
+
5
+ You can use this matcher to asert the actual value have expected type like bellow.
6
+
7
+ ```ruby
8
+
9
+ # assert array of Symbol
10
+ expect([:foo, :bar]).to be_type_of([Symbol])
11
+
12
+ # assert hash key and value
13
+ expect({ foo: 1, bar: 2 }).to be_type_of({ Symbol # => String })
14
+ ```
15
+
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'rspec_be_type_of_matcher'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install rspec_be_type_of_matcher
32
+
33
+ ## Usage
34
+
35
+ ### Or pattern
36
+
37
+ ex) assert the value is a String or Symbol
38
+
39
+ ```ruby
40
+ # rspec build-in matcher
41
+ expect(:foo).to be_kind_of(String).or be_kind_of(Symnbol)
42
+
43
+ # ↓
44
+ expect("foo").to be_type_of(String, Symnbol)
45
+ expect(:foo).to be_type_of(String, Symnbol)
46
+ # => ok
47
+
48
+ expect(1).to be_type_of(String, Symnbol)
49
+ # => fali
50
+ ```
51
+
52
+ ### Allow nil value
53
+
54
+ allow to conain nil value in actual collection.
55
+
56
+ ex) assert the value is a String or nil
57
+
58
+ ```ruby
59
+ # rspec built-in matcher
60
+ expect(:foo).to be_nil.or be_kind_of(String)
61
+
62
+ # ↓
63
+ expect("foo").to be_type_of(String).or_nil
64
+ expect(nil).to be_type_of(String).or_nil
65
+ # => ok
66
+ ```
67
+
68
+ ### TrueClass/FalseClass
69
+
70
+ ex) assert the value is a boolean
71
+
72
+ ```ruby
73
+ expect(true).to be_type_of(:boolean)
74
+ # => ok
75
+
76
+ expect(:foo).to be_type_of(:boolean)
77
+ # => fail
78
+ ```
79
+
80
+ ### Array pattern
81
+
82
+ ex) assert the value is a Array of String
83
+
84
+ ```ruby
85
+ # rspec built-in matcher
86
+ expect(["foo", "bar"]).to all(be_type_of(String))
87
+ # => ok
88
+
89
+ # ↓
90
+ expect(["foo", "bar"]).to be_type_of([String])
91
+ # => ok
92
+
93
+ expect(["foo", :bar]).to be_type_of([String])
94
+ # => fail
95
+ ```
96
+
97
+ Array pattern must exactly 1 value
98
+
99
+ ```ruby
100
+ expect(["foo", :bar]).to be_type_of([String, Symbol])
101
+ # => error
102
+ ```
103
+
104
+ ex) assert the value is a Array of (String or Symbol)
105
+
106
+ ```ruby
107
+ # rspec built-in matcher
108
+ expect(["foo", :bar]).to all(be_kind_of(String).or be_kind_of(Symbol))
109
+
110
+ # ↓
111
+ expect(["foo", :bar]).to be_type_of([be_type_of(String, Symbol)])
112
+ # => ok
113
+ ```
114
+
115
+ ### Hash pattern
116
+
117
+ ex) assert the value is a Hash those key is Symbol and value is String
118
+
119
+ ```ruby
120
+ # rspec built-in matcher
121
+ expect({foo: "aaa"}.keys).to all(be_kind_of(Symbol))
122
+ expect({foo: "aaa"}.values).to all(be_kind_of(String))
123
+
124
+ # ↓
125
+ expect({foo: "aaa"}).to be_type_of(Symbol => String)
126
+ # => ok
127
+
128
+ expect({foo: "aaa", bar: :bbb}).to be_type_of(Symbol => String)
129
+ # => fail
130
+ ```
131
+
132
+ Hash pattern must exactly 1 entry
133
+
134
+ ```ruby
135
+ expect({foo: "aaa"}).to be_type_of(Symbol => String, Integer => String)
136
+ # => error
137
+ ```
138
+
139
+ with composit matcher on values
140
+
141
+ ```ruby
142
+ expect({foo: "aaa", bar: 1}).to be_type_of(Symbol => be_type_of(Symbol, Integer))
143
+ # => ok
144
+ ```
145
+
146
+ with composit matcher on key and values
147
+
148
+ ```ruby
149
+ expect({foo: "aaa", "bar" => 1}).to be_type_of(
150
+ be_type_of(
151
+ be_type_of(String, Symbol) => be_type_of(Symbol, Integer)
152
+ )
153
+ )
154
+ # => ok
155
+ ```
156
+
157
+ ## Development
158
+
159
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
160
+
161
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
162
+
163
+ ## Contributing
164
+
165
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec_be_type_of_matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
166
+
167
+ ## License
168
+
169
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
170
+
171
+ ## Code of Conduct
172
+
173
+ Everyone interacting in the RspecBeTypeOfMatcher project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rspec_be_type_of_matcher/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec_be_type_of_matcher"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,218 @@
1
+ #
2
+ # Rspec be_type_of matcher
3
+ #
4
+ # Or pattern
5
+ # # assert the value is a String or Symbol
6
+ # # rspec build-in matcher
7
+ # expect(:foo).to be_kind_of(String).or be_kind_of(Symnbol)
8
+ #
9
+ # # ↓
10
+ # expect("foo").to be_type_of(String, Symnbol)
11
+ # expect(:foo).to be_type_of(String, Symnbol)
12
+ # => ok
13
+ #
14
+ # expect(1).to be_type_of(String, Symnbol)
15
+ # => fali
16
+ #
17
+ # Allow nil value
18
+ # # assert the value is a String or nil
19
+ # # rspec built-in matcher
20
+ # expect(:foo).to be_nil.or be_kind_of(String)
21
+ #
22
+ # # ↓
23
+ # expect("foo").to be_type_of(String).or_nil
24
+ # expect(nil).to be_type_of(String).or_nil
25
+ # => ok
26
+ #
27
+ # TrueClass/FalseClass
28
+ # # assert the value is a boolean
29
+ # expect(true).to be_type_of(:boolean)
30
+ # => ok
31
+ #
32
+ # expect(:foo).to be_type_of(:boolean)
33
+ # => false
34
+ #
35
+ # Array pattern
36
+ #
37
+ # # assert the value is a Array of String
38
+ # # rspec built-in matcher
39
+ # expect(["foo", "bar"]).to all(be_type_of(String))
40
+ # => ok
41
+ #
42
+ # # ↓
43
+ # expect(["foo", :bar]).to be_type_of([String])
44
+ # => fail
45
+ #
46
+ # # Array pattern must exactly 1 value
47
+ # expect(["foo", :bar]).to be_type_of([String, Symbol])
48
+ # => error
49
+ #
50
+ # # assert the value is a Array of (String or Symbol)
51
+ # # rspec built-in matcher
52
+ # expect(["foo", :bar]).to all(be_kind_of(String).or be_kind_of(Symbol))
53
+ #
54
+ # # ↓
55
+ # expect(["foo", :bar]).to be_type_of([be_type_of(String, Symbol)])
56
+ # => ok
57
+ #
58
+ # Hash pattern
59
+ # # assert the value is a Hash those key is Symbol and value is String
60
+ # # rspec built-in matcher
61
+ # expect({foo: "aaa"}.keys).to all(be_kind_of(Symbol))
62
+ # expect({foo: "aaa"}.values).to all(be_kind_of(String))
63
+ #
64
+ # # ↓
65
+ # expect({foo: "aaa"}).to be_type_of(Symbol => String)
66
+ # => ok
67
+ # expect({foo: "aaa", bar: :bbb}).to be_type_of(Symbol => String)
68
+ # => fail
69
+ #
70
+ # # Hash pattern must exactly 1 entry
71
+ # expect({foo: "aaa"}).to be_type_of(Symbol => String, Integer => String)
72
+ # => error
73
+ #
74
+ # # with composit matcher on values
75
+ # expect({foo: "aaa", bar: 1}).to be_type_of(Symbol => be_type_of(Symbol, Integer))
76
+ # => ok
77
+ #
78
+ # # with composit matcher on key and values
79
+ # expect({foo: "aaa", "bar" => 1}).to be_type_of(
80
+ # be_type_of( be_type_of(String, Symbol)=> be_type_of(Symbol, Integer)
81
+ # )
82
+ # => ok
83
+ #
84
+ module BeTypeOfMatcher
85
+ class InvalidTypeDefinitionError < StandardError; end
86
+
87
+ def or_match?(expected_types, actual, or_nil)
88
+ return true if expected_types.any?{|expected_type| match?(expected_type, actual, @or_nil) }
89
+
90
+ expected_types.length > 1 ?
91
+ fail_with(actual, expected_types.join(" or "), or_nil) :
92
+ false
93
+ end
94
+
95
+ def match?(expected_type, actual, or_nil)
96
+ if or_nil && actual.nil?
97
+ return true
98
+ end
99
+
100
+ if expected_type == :boolean
101
+ return boolean_match?(actual)
102
+ end
103
+
104
+ if Hash === expected_type
105
+ return hashes_match?(expected_type, actual, or_nil)
106
+ end
107
+
108
+ if Array === expected_type
109
+ return values_match?(expected_type, actual, or_nil)
110
+ end
111
+
112
+ if RSpec::Matchers.is_a_matcher?(expected_type)
113
+ return matcher_match?(expected_type, actual, or_nil)
114
+ end
115
+
116
+ if expected_type.is_a?(Module)
117
+ return type_match?(expected_type, actual, or_nil)
118
+ end
119
+
120
+ fail_with(actual, expected_type, or_nil)
121
+ end
122
+
123
+ def fail_with_message(message)
124
+ if @failure_message
125
+ message += "\n (#{@failure_message})"
126
+ end
127
+
128
+ @failure_message = message
129
+ false
130
+ end
131
+
132
+ def fail_with(actual, expected_type, or_nil)
133
+ msg = "expected #{actual.inspect} to be type of #{expected_type.inspect}"
134
+ msg += " or nil" if or_nil
135
+ fail_with_message(msg)
136
+ end
137
+
138
+ def is_array_type?(actual)
139
+ Enumerable === actual && !(Struct === actual)
140
+ end
141
+
142
+ def boolean_match?(actual)
143
+ return true if actual.is_a?(TrueClass) || actual.is_a?(FalseClass)
144
+
145
+ fail_with_message("expected #{actual.inspect} to be type of :boolean")
146
+ end
147
+
148
+ def hashes_match?(expected_type, actual, or_nil)
149
+ if expected_type.size > 1
150
+ return fail_with_message("[be_type_of matcher] expcted type of hash must have exactly 1 entry, but given #{expected_type.inspect}")
151
+ end
152
+
153
+ unless actual.is_a?(Hash)
154
+ return fail_with(actual, expected_type, or_nil)
155
+ end
156
+
157
+ key_type, value_type = expected_type.first
158
+ valid = actual.all?{|key, val|
159
+ match?(key_type, key, or_nil) && match?(value_type, val, or_nil)
160
+ }
161
+
162
+ unless valid
163
+ return fail_with(actual, expected_type, or_nil)
164
+ end
165
+
166
+ true
167
+ end
168
+
169
+ def values_match?(expected_type, actual, or_nil)
170
+ if expected_type.size > 1
171
+ return fail_with_message("[be_type_of matcher] expcted type of array must have exactly 1 element, but given #{expected_type.inspect}")
172
+ end
173
+
174
+ unless is_array_type?(actual)
175
+ return fail_with(actual, expected_type, or_nil)
176
+ end
177
+
178
+ value_type = expected_type.first
179
+ unless actual.all?{|val| match?(value_type, val, or_nil) }
180
+ return fail_with(actual, expected_type, or_nil)
181
+ end
182
+
183
+ true
184
+ end
185
+
186
+ def matcher_match?(expected_type, actual, or_nil)
187
+ matcher = expected_type.clone
188
+ return true if matcher.matches?(actual)
189
+
190
+ fail_with_message(matcher.failure_message)
191
+ end
192
+
193
+ def type_match?(expected_type, actual, or_nil)
194
+ return true if actual.is_a?(expected_type)
195
+
196
+ fail_with(actual, expected_type, or_nil)
197
+ end
198
+ end
199
+
200
+ RSpec::Matchers.define(:be_type_of) {|*expected_types|
201
+ include BeTypeOfMatcher
202
+
203
+ match {|actual|
204
+ or_match?(expected_types, actual, @or_nil)
205
+ }
206
+
207
+ chain(:or_nil) {
208
+ @or_nil = true
209
+ }
210
+
211
+ description {
212
+ "be type of #{expected_types.join(" or ") }#{@or_nil ? "or nil" : "" }"
213
+ }
214
+
215
+ failure_message {|_val|
216
+ @failure_message
217
+ }
218
+ }
@@ -0,0 +1,2 @@
1
+ require "version"
2
+ require "be_type_of_matcher"
@@ -0,0 +1,3 @@
1
+ module BeTypeOfMatcher
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec_be_type_of_matcher"
8
+ spec.version = BeTypeOfMatcher::VERSION
9
+ spec.authors = ["Tomohito Ozaki"]
10
+ spec.email = ["ozaki@yuroyoro.com"]
11
+
12
+ spec.summary = %q{Rspec matchers for strucural type assertion.}
13
+ spec.description = %q{Rspec matchers for strucural type assertion. Compare values of array to have all expeted_type, hash's key and value are expeted type}
14
+ spec.homepage = "https://github.com/yuroyoro/rspec_be_type_of_matcher"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "rspec", "~> 3.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 12.3"
29
+ spec.add_development_dependency "pry-byebug"
30
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_be_type_of_matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomohito Ozaki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-10 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: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
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
+ description: Rspec matchers for strucural type assertion. Compare values of array
70
+ to have all expeted_type, hash's key and value are expeted type
71
+ email:
72
+ - ozaki@yuroyoro.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".byebug_history"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/be_type_of_matcher.rb
91
+ - lib/rspec_be_type_of_matcher.rb
92
+ - lib/version.rb
93
+ - rspec_be_type_of_matcher.gemspec
94
+ homepage: https://github.com/yuroyoro/rspec_be_type_of_matcher
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Rspec matchers for strucural type assertion.
117
+ test_files: []