rspec_typeof 0.1 → 0.2

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: 8cbffd9c82697572f78a5d030baded69a49b11aa
4
- data.tar.gz: ebdba4717f5e937e37d60bf25126c843eb8326e7
3
+ metadata.gz: ebf87ae90bd0f19cb873f39e560c9d63bb4c40d5
4
+ data.tar.gz: e674c5cc1e89f847cd80572666358483b7121e35
5
5
  SHA512:
6
- metadata.gz: cee2aab648915d0f62c8fd0ee4a6c1594dca8b59baf59ecfa96e828a292f1f6c2d3bc0934e8bbcd2685a8eed0b68f53786ab5aac55e640bd536cc449df84f06b
7
- data.tar.gz: d4e60e2796b8079099100d81ef940f1854ba71caaa93f0357d93351b26beffc876d57b7c8c41b714fc15c5fbb6b8127be5c649ca656dced4c628ac5cb14ca36e
6
+ metadata.gz: ff3523ed965ccb3bd984c31a8f1a69a9626f884ee572666326d336f0bed7b095bce8d33e109a99c118aec42fe0919bb8a55c305b974929f8898944ce1b37570f
7
+ data.tar.gz: aee39aabcf8c554cf4a1b94100d5db674850efa6f940edb0af124af152c2a692c285998f97eb1e6139f057b350f4f9497f4744d006a11adcc35de22b5f4098db
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/Somiel/rspec_typeof.svg?branch=master)](https://travis-ci.org/Somiel/rspec_typeof)
1
2
  # RspecTypeof
2
3
 
3
- Welcome to rspec_typeof, with this gem you can use "typeof" expectation to your tests
4
+ Welcome to rspec_typeof, with this gem you can use "typeof" expectation to your tests for comfortable data format matching
4
5
 
5
6
 
6
7
  ## Installation
@@ -15,12 +16,16 @@ And then execute:
15
16
 
16
17
  $ bundle
17
18
 
18
- ## Usage
19
+ ## Usage examples
19
20
 
20
21
 
21
22
  ```ruby
22
23
  expect(true).to typeof(:string_or_nil_or_true)
23
24
  ```
25
+ ### Or
26
+ ```ruby
27
+ expect(true).to typeof(:nil_or_boolean)
28
+ ```
24
29
 
25
30
  ## Contributing
26
31
  Send improvement propositions, bug reports and pull requests on GitHub at https://github.com/Somiel/rspec_typeof.
@@ -1,7 +1,19 @@
1
1
  require "rspec"
2
+
2
3
  RSpec::Matchers.define :typeof do |expected_types|
3
- matching_map = { 'nil' => 'NilClass', 'false' => 'FalseClass', 'true' => 'TrueClass' }
4
- types = expected_types.to_s.split('_or_').uniq.map{ |v| matching_map.include?(v) ? matching_map[v] : v.capitalize }
4
+ matching_map = {
5
+ 'nil' => 'NilClass',
6
+ 'false' => 'FalseClass',
7
+ 'true' => 'TrueClass',
8
+ 'boolean' => ['TrueClass', 'FalseClass']
9
+ }
10
+ types = expected_types
11
+ .to_s
12
+ .split('_or_')
13
+ .uniq
14
+ .map{ |v| matching_map.include?(v) ? matching_map[v] : v.camelize }
15
+ .flatten
16
+ .uniq
5
17
 
6
18
  match do |actual|
7
19
  expect(actual).to satisfy do |x|
@@ -10,6 +22,6 @@ RSpec::Matchers.define :typeof do |expected_types|
10
22
  end
11
23
 
12
24
  failure_message do |actual|
13
- "expected that #{actual} would be an instance of"
25
+ "expected that #{actual} would be an instance of #{types.join(' or ')}"
14
26
  end
15
27
  end
@@ -1,3 +1,3 @@
1
1
  module RspecTypeof
2
- VERSION = '0.1'
2
+ VERSION = '0.2'
3
3
  end
data/lib/rspec_typeof.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rspec_typeof/version"
2
2
  require "rspec_typeof/typeof"
3
+ require "utils/string"
3
4
 
4
5
  module RspecTypeof
5
6
  end
@@ -0,0 +1,12 @@
1
+ class String
2
+ # Defined for matching camelcase class names
3
+ def camelize(uppercase_first_letter = true)
4
+ string = self
5
+ if uppercase_first_letter
6
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
7
+ else
8
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
9
+ end
10
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
11
+ end
12
+ end
data/rspec_typeof.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Vovchuk Max"]
10
10
  spec.email = ["vovchuk.max@gmail.com"]
11
11
 
12
- spec.summary = %q{Add be_typeof to Rspec}
13
- spec.description = %q{Add be_typeof to Rspec}
12
+ spec.summary = %q{Add typeof matcher to Rspec}
13
+ spec.description = %q{Add typeof matcher to Rspec}
14
14
  spec.homepage = "https://github.com/Somiel/rspec_typeof"
15
15
 
16
16
 
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.1'
4
+ version: '0.2'
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-07 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '11.2'
55
- description: Add be_typeof to Rspec
55
+ description: Add typeof matcher to Rspec
56
56
  email:
57
57
  - vovchuk.max@gmail.com
58
58
  executables: []
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".travis.yml"
64
65
  - Gemfile
65
66
  - README.md
66
67
  - Rakefile
@@ -69,6 +70,7 @@ files:
69
70
  - lib/rspec_typeof.rb
70
71
  - lib/rspec_typeof/typeof.rb
71
72
  - lib/rspec_typeof/version.rb
73
+ - lib/utils/string.rb
72
74
  - rspec_typeof.gemspec
73
75
  homepage: https://github.com/Somiel/rspec_typeof
74
76
  licenses: []
@@ -92,5 +94,5 @@ rubyforge_project:
92
94
  rubygems_version: 2.5.1
93
95
  signing_key:
94
96
  specification_version: 4
95
- summary: Add be_typeof to Rspec
97
+ summary: Add typeof matcher to Rspec
96
98
  test_files: []