rspec_typeof 0.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebf87ae90bd0f19cb873f39e560c9d63bb4c40d5
4
- data.tar.gz: e674c5cc1e89f847cd80572666358483b7121e35
3
+ metadata.gz: 1426d0b05757a0ef41ef3e543da0af2ea550dedb
4
+ data.tar.gz: 7beaef04dab242ac6a7fbb85572de28df5457e85
5
5
  SHA512:
6
- metadata.gz: ff3523ed965ccb3bd984c31a8f1a69a9626f884ee572666326d336f0bed7b095bce8d33e109a99c118aec42fe0919bb8a55c305b974929f8898944ce1b37570f
7
- data.tar.gz: aee39aabcf8c554cf4a1b94100d5db674850efa6f940edb0af124af152c2a692c285998f97eb1e6139f057b350f4f9497f4744d006a11adcc35de22b5f4098db
6
+ metadata.gz: d219dc5ffe5730cbc835701d426098a89e2570d7daff351f04533dcdd0993b0fd0d4284c773cfce42a75d6b7107f15b2dcea124b79f6732125739ba2d0863146
7
+ data.tar.gz: af4ad29d3e98b935812cea14b461fc71a52cc70d23d8e90633be60a105295cb6e7a53f8e3d236300a70fc174fc67ed8ca007100ef5fcd8dbcf97dd60f03c79c9
data/LICENSE.txt ADDED
@@ -0,0 +1,16 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Somiel
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8
+ and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
13
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://travis-ci.org/Somiel/rspec_typeof.svg?branch=master)](https://travis-ci.org/Somiel/rspec_typeof)
2
1
  # RspecTypeof
2
+ [![Build Status](https://travis-ci.org/Somiel/rspec_typeof.svg?branch=master)](https://travis-ci.org/Somiel/rspec_typeof)
3
3
 
4
4
  Welcome to rspec_typeof, with this gem you can use "typeof" expectation to your tests for comfortable data format matching
5
5
 
@@ -21,10 +21,18 @@ And then execute:
21
21
 
22
22
  ```ruby
23
23
  expect(true).to typeof(:string_or_nil_or_true)
24
- ```
25
- ### Or
26
- ```ruby
27
- expect(true).to typeof(:nil_or_boolean)
24
+
25
+ expect({ string: 'string', fixnum: 2, hash: {}, array: [], custom_class: CustomClass}).to match(
26
+ string: typeof(:string_or_nil),
27
+ fixnum: typeof(:fixnum_or_nil),
28
+ hash: typeof(:hash_or_nil_or_string),
29
+ array: typeof(:array_class_or_nil),
30
+ custom_class: typeof(:custom_class_or_nil_or_array)
31
+ )
32
+
33
+ expect(['a', 'b', 'c']).to typeof(:array_of_string)
34
+
35
+ expect(['a', 'b', 1]).to typeof(:array_of_string_or_fixnum)
28
36
  ```
29
37
 
30
38
  ## Contributing
@@ -6,20 +6,29 @@ RSpec::Matchers.define :typeof do |expected_types|
6
6
  'false' => 'FalseClass',
7
7
  'true' => 'TrueClass',
8
8
  'boolean' => ['TrueClass', 'FalseClass']
9
- }
9
+ }.freeze
10
+
11
+ array_matching = false
10
12
  types = expected_types
11
13
  .to_s
14
+ .gsub(/^array_of_/, '')
12
15
  .split('_or_')
13
16
  .uniq
14
17
  .map{ |v| matching_map.include?(v) ? matching_map[v] : v.camelize }
15
18
  .flatten
16
19
  .uniq
17
20
 
18
- match do |actual|
19
- expect(actual).to satisfy do |x|
20
- types.include?(x.class.name)
21
+ match do |actual|
22
+ expect(actual).to satisfy do |x|
23
+ if expected_types.to_s.scan(/^array_of_\w+/).length > 0
24
+ x.all? { |el| types.include?(el.class.name) }
25
+ else
26
+ types.include?(x.class.name)
27
+ end
28
+ end
21
29
  end
22
- end
30
+
31
+
23
32
 
24
33
  failure_message do |actual|
25
34
  "expected that #{actual} would be an instance of #{types.join(' or ')}"
@@ -1,3 +1,3 @@
1
1
  module RspecTypeof
2
- VERSION = '0.2'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_typeof
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vovchuk Max
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-09 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -63,6 +63,7 @@ files:
63
63
  - ".rspec"
64
64
  - ".travis.yml"
65
65
  - Gemfile
66
+ - LICENSE.txt
66
67
  - README.md
67
68
  - Rakefile
68
69
  - bin/console