rspec-dry-types 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cae481ae202a06c1d6e129a5f62ca6a5ed66aa6f74822b785296118da40374a9
4
- data.tar.gz: 4d57d5c70686016b96b67e424fd5734af34ba9ced7a365baf1247b415f417a16
3
+ metadata.gz: 86fca0bb16df69d550af305359f8232afab4ec61b653a17bad89a39cd4fcae0d
4
+ data.tar.gz: 5d0833b3da286695adc15326f8158f2d05d7ca905dd3ee478c1d24fc56fac0b5
5
5
  SHA512:
6
- metadata.gz: c11eb9ae4fd5859428e67ab1e970e8457bf31fd249192245a55016e91f01ee0d32ca07eb48e0effdba5f695cf8f0c67dcb5c14f5b821883c0092123c84e11f5c
7
- data.tar.gz: 45fc113c76239eb402ef1fbf3b557404623f3ea77aa5033f88d2b1f149d09a30f2f66cb97d6e7cf24dbf82f9a99a7c1a9b6bd1a9f6421639ef131a6b983841ae
6
+ metadata.gz: 72e1925c5e6bb7d242eea4a9751e3a0c0bbaeb14074d15fdcaf51c3171d1219c4db85c0df1126b698fac490997d9bee709733b53b64dc727cc2b529023f46514
7
+ data.tar.gz: 9ec4072143621ca047d8c67c5c918fb53e9f6a598b1381fcb10e73a9aaae58d3563a23fc7397652d1a3fea75ffa6dd52553b13ef1ad10ed5caac2dcc3638639f
data/README.md CHANGED
@@ -1,78 +1,97 @@
1
1
  [![CircleCI](https://circleci.com/gh/patrickclery/rspec-dry-types.svg?style=svg)](https://circleci.com/gh/patrickclery/rspec-dry-types)
2
2
 
3
- # Dry::Types for RSpec
4
-
5
- `rspec-dry-types` makes type-checking in Test-Driven Development easier by replacing RSpec's default type checkers with ones that check values using the [dry-types gem](http://dry-rb.org/gems/dry-types/).
6
-
7
- This:
8
-
9
- ```ruby
10
- expect(subject).to be_a(String)
11
- ```
3
+ > Speed up test-driven development with looser or stronger type-checking in your RSpec tests
12
4
 
13
- Becomes this:
5
+ [rspec-dry-types](https://github.com/patrickclery/rspec-dry-types) connects RSpec to [dry-types](https://dry-rb.org/gems/dry-types/1.2/built-in-types/) so you have access to extra type-checking helpers.
14
6
 
15
- ```ruby
16
- expect(subject).to be_a(Dry::Types['strict.string'])
17
- ```
18
-
19
- ## Usage:
7
+ ## Usage
8
+
9
+ The best way to describe it, is to look at the actual RSpec tests used for this gem:
20
10
 
21
11
  ```ruby
12
+ require 'rspec'
13
+ require 'rspec/matchers/be_of_type'
14
+
22
15
  RSpec.describe "check types using be_of_type" do
23
16
  include RSpec::Matchers::DryTypes
24
17
 
25
- it 'can use a symbol to expect a dry-type' do
18
+ it 'can expect a dry-type (by symbol)' do
26
19
  expect('a string').to be_of_type(:string)
27
20
  expect(123).to be_of_type(:integer)
28
21
  expect(0.123).to be_of_type(:float)
29
- expect("123").to be_of_type(:integer, strict: false)
30
- expect(nil).to be_of_type(:string, strict: false)
31
22
  expect(nil).to be_of_type(:nil)
23
+ expect({}).to be_of_type(:hash)
24
+ expect([]).to be_of_type(:array)
25
+ expect(true).to be_of_type(:bool)
26
+ expect(false).to be_of_type(:bool)
27
+ expect(Date.new(2001, 2, 3)).to be_of_type(:date)
28
+ expect(Time.new(2001, 2, 3, 4, 5, 6)).to be_of_type(:time)
29
+ expect(DateTime.new(2001, 2, 3, 4, 5, 6)).to be_of_type(:date_time)
30
+ expect(:abc).to be_of_type(:symbol)
31
+ end
32
+
33
+ it 'can expect any type' do
34
+ # Any type
35
+ expect('a string').to be_of_type(:any)
36
+ expect(123).to be_of_type(:any)
37
+ expect(0.123).to be_of_type(:any)
38
+ expect(nil).to be_of_type(:any)
39
+ expect({}).to be_of_type(:any)
40
+ expect([]).to be_of_type(:any)
41
+ expect(true).to be_of_type(:any)
42
+ expect(false).to be_of_type(:any)
43
+ expect(Date.new(2001, 2, 3)).to be_of_type(:any)
44
+ expect(Time.new(2001, 2, 3, 4, 5, 6)).to be_of_type(:any)
45
+ expect(DateTime.new(2001, 2, 3, 4, 5, 6)).to be_of_type(:any)
46
+ expect(:abc).to be_of_type(:any)
47
+ expect(0.1).to be_of_type(:any)
48
+ end
49
+
50
+ it 'can expect a value to be coercible into a type' do
51
+ # actual.to_s
52
+ expect(nil).to be_of_type(:string, strict: false)
53
+ expect(123).to be_of_type(:string, strict: false) # 123.to_s == "123"
54
+ expect(123).to be_of_type("coercible.string")
55
+
56
+ # actual.to_i
57
+ expect("123").to be_of_type(:integer, strict: false)
58
+ expect(0.123).not_to be_of_type(:integer)
59
+ expect(0.123).to be_of_type(:integer, strict: false)
32
60
  end
33
61
 
34
62
  # Strings must reference the dry-types docs
35
- it 'can use string to expect a dry-type' do
36
- expect('a string').to be_of_type('string')
63
+ it 'can expect a dry-type (by string)' do
64
+ expect('a string').to be_of_type('strict.string')
65
+ expect("123").to be_of_type('coercible.integer')
37
66
  expect('a string').to be_of_type('strict.string')
38
- expect(123).to be_of_type('integer')
39
67
  expect(123).to be_of_type('strict.integer')
40
- expect(0.123).to be_of_type('float')
41
- expect(0.123).to be_of_type('coercible.integer')
68
+ expect(0.123).to be_of_type('strict.float')
69
+ expect(nil).to be_of_type('strict.nil')
70
+ expect({}).to be_of_type('strict.hash')
71
+ expect([]).to be_of_type('strict.array')
72
+ expect(true).to be_of_type('strict.bool')
73
+ expect(false).to be_of_type('strict.bool')
74
+ expect(Date.new(2001, 2, 3)).to be_of_type('strict.date')
75
+ expect(Time.new(2001, 2, 3, 4, 5, 6)).to be_of_type('strict.time')
76
+ expect(DateTime.new(2001, 2, 3, 4, 5, 6)).to be_of_type('strict.date_time')
77
+ expect(:abc).to be_of_type('strict.symbol')
78
+
79
+ # with an optional flag
80
+ expect(123).to be_of_type('integer', strict: true)
42
81
  expect("123").to be_of_type('integer', strict: false)
43
- expect(nil).to be_of_type('string', strict: false)
44
- expect(nil).to be_of_type('nil')
45
- end
46
-
47
- # Strings must reference the dry-types docs
48
- it 'is backwards compat with be_a' do
49
- expect('a string').to be_a(String)
50
- expect('a string').to be_a_kind_of('strict.string')
51
- expect(123).to be_an(Integer)
52
- expect(123).to be_an('integer')
53
82
  end
54
83
 
55
- it 'can use a class to check if its a type' do
56
- # Check inheritance
84
+ # Note: there is no 'object' type for `dry-types`
85
+ it 'can expect class inheritance of a type' do
86
+ # String/Integer inherit from Object
57
87
  expect(String).to be_of_type(Object)
58
- expect('a string').to be_of_type(Object)
59
-
60
- # Check coercion
61
- expect(123).to be_of_type(String, strict: false)
62
- expect(0.123).not_to be_of_type(Integer)
63
- expect(0.123).to be_of_type(Integer, strict: false)
64
-
65
- expect(123).to be_of_type(Object)
66
88
  expect(123).to be_of_type(Object)
89
+ expect('a string').to be_of_type(Object)
67
90
  end
68
91
 
69
92
  end
70
93
  ```
71
94
 
72
- ## Contributing
73
-
74
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-dry-types. 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.
75
-
76
- ## Code of Conduct
95
+ > For a full list of types, checkout the [dry-types documentation](https://dry-rb.org/gems/dry-types/1.2/built-in-types/)
77
96
 
78
- Everyone interacting in the Rspec::Dry::Types project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rspec-dry-types/blob/master/CODE_OF_CONDUCT.md).
97
+ If this project helps you,
@@ -1,7 +1,7 @@
1
1
  module Rspec
2
2
  module Dry
3
3
  module Types
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-dry-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - patrickclery
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler