rspec-be_valid_when_matcher 0.1.3 → 0.2.0

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
  SHA1:
3
- metadata.gz: ab47d9add56592d481664f6e96727661aa0a4527
4
- data.tar.gz: b6bd06a6c889d7c0fb65446dbad909ed97acede9
3
+ metadata.gz: 86228876cf3d02d0970138b1f12029189ccb9d0c
4
+ data.tar.gz: 9f536b03bfae63f0e9150473b9462d2c47a3cf56
5
5
  SHA512:
6
- metadata.gz: 4201ba70381cf1f992d01e518c0155f5cc009f54bca1ff6ab1a8c1475fec1daaa55c534a1163e782763df39d24519649a65dfba5c6d0493cb11343cfbe9e14a3
7
- data.tar.gz: 6a761ae1d4e7facb22d59b339efaa48d48614edbdf6f76ea9bf6961ab26f86e51da2091517d0fd714f22f2dd287a01b214b530854298ceabf42389473e8b043a
6
+ metadata.gz: 6c71c832bd4e6e75c0d262904a516c618f9fd662776a175a3702cd88eefc1a81df090dca16ef4c87e025944cd87b70b93dd405d2ef1fa430e4d0c8c9b9f11b4f
7
+ data.tar.gz: 51ad0846d177728091992445fbf404169b5d155bbf86321578c7c00dceb88ec9cc96713147b26845a40876f2db3e92de44d1917639de310406148d95aed6653d
data/README.md CHANGED
@@ -2,9 +2,18 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rspec-be_valid_when_matcher.svg)]
4
4
  (http://badge.fury.io/rb/rspec-be_valid_when_matcher)
5
+ [![Build Status](https://travis-ci.org/mtuchowski/rspec-be_valid_when_matcher.svg)]
6
+ (https://travis-ci.org/mtuchowski/rspec-be_valid_when_matcher)
5
7
 
6
8
  RSpec matcher for testing ActiveRecord models with a fluent and clear language.
7
9
 
10
+ ```ruby
11
+ expect(person).to be_valid_when(:age).is_number
12
+ ```
13
+
14
+ The matcher will check only the specified field for validation errors, so if there's one buggy
15
+ validator the whole model spec suite won't go red.
16
+
8
17
  ## Install
9
18
 
10
19
  First, add to your `Gemfile` (preferably in the `:test` group):
@@ -37,9 +46,21 @@ end
37
46
 
38
47
  ## Basic usage
39
48
 
40
- Here's an example using rspec-be_valid_when_matcher:
49
+ Here's an example using `be_valid_when` matcher:
41
50
 
42
51
  ```ruby
52
+ require 'active_model'
53
+
54
+ class Person
55
+ include ActiveModel::Validations
56
+
57
+ attr_accessor :name
58
+ attr_accessor :age
59
+
60
+ validates_presence_of :name
61
+ validates_numericality_of :age, greater_than: 0
62
+ end
63
+
43
64
  RSpec.describe Person do
44
65
  subject { Person.new }
45
66
 
@@ -72,27 +93,31 @@ RSpec.describe Person do
72
93
  end
73
94
  ```
74
95
 
75
- ### Built-in checks
96
+ ## Built-in checks
97
+
98
+ In addition to standard matcher declaration interface and the `#is` method, there is also a number
99
+ of helper methods to test common cases.
76
100
 
77
- #### Presence
101
+ ### Presence
78
102
 
79
103
  Test field validity with the `nil` value:
80
104
 
81
105
  ```ruby
82
- be_valid_when(:field).is_not_present # Uses nil value
106
+ be_valid_when(:field).is_not_present
83
107
  ```
84
108
 
85
- #### Type
109
+ ### Type
86
110
 
87
- Test field validity with specific type values:
111
+ Test field validity with specific type values (all methods accept field value argument):
88
112
 
89
113
  ```ruby
90
- be_valid_when(:field).is_number 2 # Defaults to 42
91
- be_valid_when(:field).is_fixnum 2 # Defaults to 42
92
- be_valid_when(:field).is_bignum 1024**32 # Defaults to 42**13
93
- be_valid_when(:field).is_float 0.1 # Defaults to 3.14
94
- be_valid_when(:field).is_complex 2.to_c # Defaults to 42+0i
95
- be_valid_when(:field).is_rational 2.to_r # Defaults to 42/1
114
+ be_valid_when(:field).is_number # Defaults to 42
115
+ be_valid_when(:field).is_fixnum # Defaults to 42
116
+ be_valid_when(:field).is_bignum # Defaults to 42**13
117
+ be_valid_when(:field).is_float # Defaults to 3.14
118
+ be_valid_when(:field).is_complex # Defaults to 42+0i
119
+ be_valid_when(:field).is_rational # Defaults to 42/1
120
+ be_valid_when(:field).is_bigdecimal # Defaults to 0.42E2
96
121
  ```
97
122
 
98
123
  ## MIT Licensed
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  require 'rspec'
3
+ require 'bigdecimal'
3
4
 
4
5
  # RSpec's top level namespace.
5
6
  module RSpec
@@ -130,7 +131,8 @@ module RSpec
130
131
  bignum: { value: 42**13, type: Bignum },
131
132
  float: { value: Math::PI, type: Float },
132
133
  complex: { value: 42.to_c, type: Complex },
133
- rational: { value: 42.to_r, type: Rational } }.each do |name, properties|
134
+ rational: { value: 42.to_r, type: Rational },
135
+ bigdecimal: { value: BigDecimal.new('42'), type: BigDecimal } }.each do |name, properties|
134
136
  define_method "is_#{name}" do |number = properties[:value]|
135
137
  fail ArgumentError, "should be #{name}" unless number.is_a? properties[:type]
136
138
 
@@ -170,7 +172,7 @@ module RSpec
170
172
  end
171
173
 
172
174
  def value_to_string
173
- if [Complex, Rational].any? { |type| @value.is_a? type }
175
+ if [Complex, Rational, BigDecimal].any? { |type| @value.is_a? type }
174
176
  @value.to_s
175
177
  else
176
178
  @value.inspect
data/spec/examples.cache CHANGED
@@ -1,74 +1,82 @@
1
- example_id | status | run_time |
2
- ------------------------------------------------------ | ------ | --------------- |
3
- ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:1:1] | passed | 0.0002 seconds |
4
- ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:1:2] | passed | 0.01275 seconds |
5
- ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:1] | passed | 0.00014 seconds |
6
- ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:2] | passed | 0.01394 seconds |
7
- ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:3] | passed | 0.00021 seconds |
8
- ./spec/rspec/be_valid_when/is_complex_spec.rb[1:1:1] | passed | 0.00047 seconds |
9
- ./spec/rspec/be_valid_when/is_complex_spec.rb[1:1:2] | passed | 0.05202 seconds |
10
- ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:1] | passed | 0.00014 seconds |
11
- ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:2] | passed | 0.01636 seconds |
12
- ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:3] | passed | 0.00144 seconds |
13
- ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:1:1] | passed | 0.00013 seconds |
14
- ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:1:2] | passed | 0.01288 seconds |
15
- ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:1] | passed | 0.00012 seconds |
16
- ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:2] | passed | 0.01389 seconds |
17
- ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:3] | passed | 0.00017 seconds |
18
- ./spec/rspec/be_valid_when/is_float_spec.rb[1:1:1] | passed | 0.00013 seconds |
19
- ./spec/rspec/be_valid_when/is_float_spec.rb[1:1:2] | passed | 0.01217 seconds |
20
- ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:1] | passed | 0.00012 seconds |
21
- ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:2] | passed | 0.01362 seconds |
22
- ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:3] | passed | 0.00024 seconds |
23
- ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:1] | passed | 0.00015 seconds |
24
- ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:2] | passed | 0.01367 seconds |
25
- ./spec/rspec/be_valid_when/is_number_spec.rb[1:1:1] | passed | 0.0001 seconds |
26
- ./spec/rspec/be_valid_when/is_number_spec.rb[1:1:2] | passed | 0.01251 seconds |
27
- ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:1] | passed | 0.00012 seconds |
28
- ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:2] | passed | 0.01285 seconds |
29
- ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:3] | passed | 0.00017 seconds |
30
- ./spec/rspec/be_valid_when/is_rational_spec.rb[1:1:1] | passed | 0.00015 seconds |
31
- ./spec/rspec/be_valid_when/is_rational_spec.rb[1:1:2] | passed | 0.01233 seconds |
32
- ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:1] | passed | 0.00014 seconds |
33
- ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:2] | passed | 0.01475 seconds |
34
- ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:3] | passed | 0.00018 seconds |
35
- ./spec/rspec/be_valid_when/is_spec.rb[1:1] | passed | 0.00011 seconds |
36
- ./spec/rspec/be_valid_when/is_spec.rb[1:2:1] | passed | 0.01223 seconds |
37
- ./spec/rspec/be_valid_when/is_spec.rb[1:3:1] | passed | 0.01304 seconds |
38
- ./spec/rspec/be_valid_when/is_spec.rb[1:3:2] | passed | 0.00452 seconds |
39
- ./spec/rspec/be_valid_when/is_spec.rb[1:4] | passed | 0.00014 seconds |
40
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:1] | passed | 0.00044 seconds |
41
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:2] | passed | 0.00011 seconds |
42
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:3] | passed | 0.00016 seconds |
43
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:4] | passed | 0.00009 seconds |
44
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:5] | passed | 0.00014 seconds |
45
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:6] | passed | 0.00067 seconds |
46
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:7] | passed | 0.00009 seconds |
47
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:8] | passed | 0.00008 seconds |
48
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:9] | passed | 0.00013 seconds |
49
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:10] | passed | 0.00007 seconds |
50
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:1] | passed | 0.00009 seconds |
51
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:2] | passed | 0.00011 seconds |
52
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:1] | passed | 0.00016 seconds |
53
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:2] | passed | 0.00014 seconds |
54
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:3] | passed | 0.00015 seconds |
55
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:4] | passed | 0.0002 seconds |
56
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:5] | passed | 0.00014 seconds |
57
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:1] | passed | 0.00009 seconds |
58
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:2:1] | passed | 0.00293 seconds |
59
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:2:2] | passed | 0.00292 seconds |
60
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:1] | passed | 0.00013 seconds |
61
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:2:1] | passed | 0.00292 seconds |
62
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:2:2] | passed | 0.003 seconds |
63
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:5] | passed | 0.00012 seconds |
64
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:1] | passed | 0.00023 seconds |
65
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:2] | passed | 0.00021 seconds |
66
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:3] | passed | 0.00011 seconds |
67
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:4] | passed | 0.00012 seconds |
68
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:1:1] | passed | 0.00286 seconds |
69
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:1:2] | passed | 0.00627 seconds |
70
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:2:1] | passed | 0.00295 seconds |
71
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:2:2] | passed | 0.01202 seconds |
72
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:8:1] | passed | 0.0047 seconds |
73
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:8:2:1] | passed | 0.00394 seconds |
74
- ./spec/rspec/be_valid_when_matcher_spec.rb[1:9:1] | passed | 0.00011 seconds |
1
+ example_id | status | run_time |
2
+ ------------------------------------------------------- | ------ | --------------- |
3
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:1:1] | passed | 0.00012 seconds |
4
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:1:2] | passed | 0.0149 seconds |
5
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:2:1] | passed | 0.00014 seconds |
6
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:2:2] | passed | 0.01487 seconds |
7
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:2:3] | passed | 0.00014 seconds |
8
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:1:1] | passed | 0.00019 seconds |
9
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:1:2] | passed | 0.01449 seconds |
10
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:1] | passed | 0.0002 seconds |
11
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:2] | passed | 0.0162 seconds |
12
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:3] | passed | 0.0002 seconds |
13
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:1:1] | passed | 0.00017 seconds |
14
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:1:2] | passed | 0.01427 seconds |
15
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:1] | passed | 0.00017 seconds |
16
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:2] | passed | 0.01682 seconds |
17
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:3] | passed | 0.0002 seconds |
18
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:1:1] | passed | 0.00017 seconds |
19
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:1:2] | passed | 0.01927 seconds |
20
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:1] | passed | 0.00012 seconds |
21
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:2] | passed | 0.01536 seconds |
22
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:3] | passed | 0.00016 seconds |
23
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:1:1] | passed | 0.00014 seconds |
24
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:1:2] | passed | 0.01379 seconds |
25
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:1] | passed | 0.00014 seconds |
26
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:2] | passed | 0.01466 seconds |
27
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:3] | passed | 0.00019 seconds |
28
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:1] | passed | 0.00012 seconds |
29
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:2] | passed | 0.01479 seconds |
30
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:1:1] | passed | 0.00045 seconds |
31
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:1:2] | passed | 0.05618 seconds |
32
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:1] | passed | 0.00015 seconds |
33
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:2] | passed | 0.01527 seconds |
34
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:3] | passed | 0.00106 seconds |
35
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:1:1] | passed | 0.00015 seconds |
36
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:1:2] | passed | 0.01414 seconds |
37
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:1] | passed | 0.00011 seconds |
38
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:2] | passed | 0.01516 seconds |
39
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:3] | passed | 0.00022 seconds |
40
+ ./spec/rspec/be_valid_when/is_spec.rb[1:1] | passed | 0.00011 seconds |
41
+ ./spec/rspec/be_valid_when/is_spec.rb[1:2:1] | passed | 0.01265 seconds |
42
+ ./spec/rspec/be_valid_when/is_spec.rb[1:3:1] | passed | 0.01573 seconds |
43
+ ./spec/rspec/be_valid_when/is_spec.rb[1:3:2] | passed | 0.00344 seconds |
44
+ ./spec/rspec/be_valid_when/is_spec.rb[1:4] | passed | 0.00016 seconds |
45
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1] | passed | 0.00024 seconds |
46
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2] | passed | 0.00076 seconds |
47
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3] | failed | 0.01192 seconds |
48
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:1] | passed | 0.00035 seconds |
49
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:2] | passed | 0.00057 seconds |
50
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:3] | passed | 0.0001 seconds |
51
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:4] | passed | 0.00008 seconds |
52
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:5] | passed | 0.00012 seconds |
53
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:6] | passed | 0.00008 seconds |
54
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:7] | passed | 0.00011 seconds |
55
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:8] | passed | 0.00008 seconds |
56
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:9] | passed | 0.0001 seconds |
57
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:1:10] | passed | 0.00007 seconds |
58
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:1] | passed | 0.00009 seconds |
59
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:2] | passed | 0.0001 seconds |
60
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:3:1] | passed | 0.00012 seconds |
61
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:3:2] | passed | 0.00009 seconds |
62
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:3:3] | passed | 0.00014 seconds |
63
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:3:4] | passed | 0.00011 seconds |
64
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:2:3:5] | passed | 0.0001 seconds |
65
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:3:1] | passed | 0.00012 seconds |
66
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:3:2:1] | passed | 0.0038 seconds |
67
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:3:2:2] | passed | 0.0037 seconds |
68
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:4:1] | passed | 0.0001 seconds |
69
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:4:2:1] | passed | 0.00359 seconds |
70
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:4:2:2] | passed | 0.0036 seconds |
71
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:5] | passed | 0.00015 seconds |
72
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:6:1] | passed | 0.00017 seconds |
73
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:6:2] | passed | 0.00015 seconds |
74
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:6:3] | passed | 0.00009 seconds |
75
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:6:4] | passed | 0.0001 seconds |
76
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:7:1:1] | passed | 0.00363 seconds |
77
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:7:1:2] | passed | 0.00886 seconds |
78
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:7:2:1] | passed | 0.00385 seconds |
79
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:7:2:2] | passed | 0.00826 seconds |
80
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:8:1] | passed | 0.00374 seconds |
81
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:8:2:1] | passed | 0.00484 seconds |
82
+ ./spec/rspec/be_valid_when_matcher_spec.rb[2:9:1] | passed | 0.00012 seconds |
@@ -0,0 +1,68 @@
1
+ require 'active_model'
2
+ require 'bigdecimal'
3
+
4
+ # @private
5
+ class FakeModel
6
+ include ActiveModel::Validations
7
+
8
+ attr_accessor :bigdecimal_field
9
+ attr_accessor :not_bigdec_field
10
+
11
+ validates_numericality_of :bigdecimal_field, greater_than: 40
12
+ validate :not_bigdec_field_cannot_be_bigdecimal
13
+
14
+ private
15
+
16
+ def not_bigdec_field_cannot_be_bigdecimal
17
+ errors.add(:not_bigdec_field, "can't be bigdecimal") if not_bigdec_field.is_a? BigDecimal
18
+ end
19
+ end
20
+
21
+ describe 'be_valid_when#is_bigdecimal' do
22
+ let(:model) { FakeModel.new }
23
+
24
+ context 'with no arguments' do
25
+ let(:description) { /^be valid when #bigdecimal_field is a bigdecimal \(0.42E2\)$/ }
26
+
27
+ let(:passing_matcher) { be_valid_when(:bigdecimal_field).is_bigdecimal }
28
+ let(:failing_matcher) { be_valid_when(:not_bigdec_field).is_bigdecimal }
29
+
30
+ it 'has the correct description' do
31
+ expect(passing_matcher.description).to match description
32
+ end
33
+
34
+ it 'returns proper result' do
35
+ expect(passing_matcher.matches? model).to eq true
36
+ expect(passing_matcher.does_not_match? model).to eq false
37
+ expect(failing_matcher.matches? model).to eq false
38
+ expect(failing_matcher.does_not_match? model).to eq true
39
+ end
40
+ end
41
+
42
+ context 'with one argument' do
43
+ let(:description) { /^be valid when #bigdecimal_field is a bigdecimal \(0.5E2\)$/ }
44
+
45
+ let(:passing_matcher) { be_valid_when(:bigdecimal_field).is_bigdecimal BigDecimal.new('50') }
46
+ let(:failing_matcher) { be_valid_when(:bigdecimal_field).is_bigdecimal BigDecimal.new('30') }
47
+
48
+ it 'has the correct description' do
49
+ expect(passing_matcher.description).to match description
50
+ end
51
+
52
+ it 'returns proper result' do
53
+ expect(passing_matcher.matches? model).to eq true
54
+ expect(passing_matcher.does_not_match? model).to eq false
55
+ expect(failing_matcher.matches? model).to eq false
56
+ expect(failing_matcher.does_not_match? model).to eq true
57
+ end
58
+
59
+ it 'should fail if passed non bigdecimal' do
60
+ expect do
61
+ be_valid_when(:bigdecimal_field).is_bigdecimal 'value'
62
+ end.to raise_error ArgumentError
63
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal '42' }.to raise_error ArgumentError
64
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal 3.14 }.to raise_error ArgumentError
65
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal :value }.to raise_error ArgumentError
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-be_valid_when_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Tuchowski
@@ -50,6 +50,7 @@ files:
50
50
  - README.md
51
51
  - lib/rspec/be_valid_when_matcher.rb
52
52
  - spec/examples.cache
53
+ - spec/rspec/be_valid_when/is_bigdecimal_spec.rb
53
54
  - spec/rspec/be_valid_when/is_bignum_spec.rb
54
55
  - spec/rspec/be_valid_when/is_complex_spec.rb
55
56
  - spec/rspec/be_valid_when/is_fixnum_spec.rb
@@ -96,6 +97,7 @@ test_files:
96
97
  - spec/rspec/be_valid_when/is_spec.rb
97
98
  - spec/rspec/be_valid_when/is_not_present_spec.rb
98
99
  - spec/rspec/be_valid_when/is_fixnum_spec.rb
100
+ - spec/rspec/be_valid_when/is_bigdecimal_spec.rb
99
101
  - spec/rspec/be_valid_when/is_complex_spec.rb
100
102
  - spec/examples.cache
101
103
  has_rdoc: