rspec-be_valid_when_matcher 0.2.0 → 0.3.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: 86228876cf3d02d0970138b1f12029189ccb9d0c
4
- data.tar.gz: 9f536b03bfae63f0e9150473b9462d2c47a3cf56
3
+ metadata.gz: bfa5bfc671b2323ea01bdb96e8961cdfd28e9d4e
4
+ data.tar.gz: 000086bef61468b32d52a46e26f1ddb08b0d41bd
5
5
  SHA512:
6
- metadata.gz: 6c71c832bd4e6e75c0d262904a516c618f9fd662776a175a3702cd88eefc1a81df090dca16ef4c87e025944cd87b70b93dd405d2ef1fa430e4d0c8c9b9f11b4f
7
- data.tar.gz: 51ad0846d177728091992445fbf404169b5d155bbf86321578c7c00dceb88ec9cc96713147b26845a40876f2db3e92de44d1917639de310406148d95aed6653d
6
+ metadata.gz: f912c394bfcca9bf3b0c2954ce498cf63c1676915494afc2c1cd7787d7be83d33946d7f0ab468d5b391d5ceef50e720ed219d17df40bc8133eea917d55812921
7
+ data.tar.gz: b10fc3102760625bb6d5c427911889e5a3b22f780b38d9604c133efb939bcf602e969780a12d087a580ddc2e5be03f7e26467f0efe8976f964126a9a47e251f4
data/README.md CHANGED
@@ -118,6 +118,11 @@ be_valid_when(:field).is_float # Defaults to 3.14
118
118
  be_valid_when(:field).is_complex # Defaults to 42+0i
119
119
  be_valid_when(:field).is_rational # Defaults to 42/1
120
120
  be_valid_when(:field).is_bigdecimal # Defaults to 0.42E2
121
+ be_valid_when(:field).is_string # Defaults to 'value'
122
+ be_valid_when(:field).is_regexp # Defaults to /^value$/
123
+ be_valid_when(:field).is_array # Defaults to [42]
124
+ be_valid_when(:field).is_hash # Defaults to { value: 42 }
125
+ be_valid_when(:field).is_symbol # Defaults to :value
121
126
  ```
122
127
 
123
128
  ## MIT Licensed
@@ -125,18 +125,23 @@ module RSpec
125
125
  is(nil, 'not present')
126
126
  end
127
127
 
128
- # Generate #is_* numeric methods.
128
+ # Generate #is_*(type) methods.
129
129
  { number: { value: 42, type: Numeric },
130
130
  fixnum: { value: 42, type: Fixnum },
131
131
  bignum: { value: 42**13, type: Bignum },
132
132
  float: { value: Math::PI, type: Float },
133
133
  complex: { value: 42.to_c, type: Complex },
134
134
  rational: { value: 42.to_r, type: Rational },
135
- bigdecimal: { value: BigDecimal.new('42'), type: BigDecimal } }.each do |name, properties|
136
- define_method "is_#{name}" do |number = properties[:value]|
137
- fail ArgumentError, "should be #{name}" unless number.is_a? properties[:type]
138
-
139
- is(number, "a #{name}")
135
+ bigdecimal: { value: BigDecimal.new('42'), type: BigDecimal },
136
+ string: { value: 'value', type: String },
137
+ regexp: { value: /^value$/, type: Regexp },
138
+ array: { value: [42], type: Array },
139
+ hash: { value: { value: 42 }, type: Hash },
140
+ symbol: { value: :value, type: Symbol } }.each do |name, properties|
141
+ define_method "is_#{name}" do |value = properties[:value]|
142
+ fail ArgumentError, "should be #{name}" unless value.is_a? properties[:type]
143
+
144
+ is(value, "a #{name}")
140
145
  end
141
146
  end
142
147
 
data/spec/examples.cache CHANGED
@@ -1,82 +1,105 @@
1
1
  example_id | status | run_time |
2
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 |
3
+ ./spec/rspec/be_valid_when/is_array_spec.rb[1:1:1] | passed | 0.00015 seconds |
4
+ ./spec/rspec/be_valid_when/is_array_spec.rb[1:1:2] | passed | 0.02028 seconds |
5
+ ./spec/rspec/be_valid_when/is_array_spec.rb[1:2:1] | passed | 0.00018 seconds |
6
+ ./spec/rspec/be_valid_when/is_array_spec.rb[1:2:2] | passed | 0.01674 seconds |
7
+ ./spec/rspec/be_valid_when/is_array_spec.rb[1:2:3] | passed | 0.00063 seconds |
8
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:1:1] | passed | 0.00014 seconds |
9
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:1:2] | passed | 0.01514 seconds |
5
10
  ./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 |
11
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:2:2] | passed | 0.01668 seconds |
12
+ ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:2:3] | passed | 0.00038 seconds |
8
13
  ./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 |
14
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:1:2] | passed | 0.0274 seconds |
15
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:1] | passed | 0.00014 seconds |
16
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:2] | passed | 0.01933 seconds |
17
+ ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:2:3] | passed | 0.00042 seconds |
18
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:1:1] | passed | 0.00015 seconds |
19
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:1:2] | passed | 0.01652 seconds |
20
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:1] | passed | 0.00014 seconds |
21
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:2] | passed | 0.01823 seconds |
22
+ ./spec/rspec/be_valid_when/is_complex_spec.rb[1:2:3] | passed | 0.00033 seconds |
23
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:1:1] | passed | 0.00014 seconds |
24
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:1:2] | passed | 0.01832 seconds |
25
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:1] | passed | 0.00014 seconds |
26
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:2] | passed | 0.01675 seconds |
27
+ ./spec/rspec/be_valid_when/is_fixnum_spec.rb[1:2:3] | passed | 0.0003 seconds |
28
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:1:1] | passed | 0.00016 seconds |
29
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:1:2] | passed | 0.01634 seconds |
30
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:1] | passed | 0.00016 seconds |
31
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:2] | passed | 0.01804 seconds |
32
+ ./spec/rspec/be_valid_when/is_float_spec.rb[1:2:3] | passed | 0.00129 seconds |
33
+ ./spec/rspec/be_valid_when/is_hash_spec.rb[1:1:1] | passed | 0.00012 seconds |
34
+ ./spec/rspec/be_valid_when/is_hash_spec.rb[1:1:2] | passed | 0.02788 seconds |
35
+ ./spec/rspec/be_valid_when/is_hash_spec.rb[1:2:1] | passed | 0.00016 seconds |
36
+ ./spec/rspec/be_valid_when/is_hash_spec.rb[1:2:2] | passed | 0.01855 seconds |
37
+ ./spec/rspec/be_valid_when/is_hash_spec.rb[1:2:3] | passed | 0.00028 seconds |
38
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:1] | passed | 0.00013 seconds |
39
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:2] | passed | 0.01722 seconds |
40
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:3] | passed | 0.00016 seconds |
41
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:1:1] | passed | 0.00035 seconds |
42
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:1:2] | passed | 0.02018 seconds |
43
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:1] | passed | 0.00035 seconds |
44
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:2] | passed | 0.02383 seconds |
45
+ ./spec/rspec/be_valid_when/is_number_spec.rb[1:2:3] | passed | 0.00027 seconds |
46
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:1:1] | passed | 0.00012 seconds |
47
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:1:2] | passed | 0.0147 seconds |
48
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:1] | passed | 0.00013 seconds |
49
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:2] | passed | 0.01734 seconds |
50
+ ./spec/rspec/be_valid_when/is_rational_spec.rb[1:2:3] | passed | 0.00028 seconds |
51
+ ./spec/rspec/be_valid_when/is_regex_spec.rb[1:1:1] | passed | 0.00011 seconds |
52
+ ./spec/rspec/be_valid_when/is_regex_spec.rb[1:1:2] | passed | 0.01755 seconds |
53
+ ./spec/rspec/be_valid_when/is_regex_spec.rb[1:2:1] | passed | 0.00015 seconds |
54
+ ./spec/rspec/be_valid_when/is_regex_spec.rb[1:2:2] | passed | 0.01728 seconds |
55
+ ./spec/rspec/be_valid_when/is_regex_spec.rb[1:2:3] | passed | 0.00031 seconds |
56
+ ./spec/rspec/be_valid_when/is_spec.rb[1:1] | passed | 0.00012 seconds |
57
+ ./spec/rspec/be_valid_when/is_spec.rb[1:2:1] | passed | 0.01421 seconds |
58
+ ./spec/rspec/be_valid_when/is_spec.rb[1:3:1] | passed | 0.01404 seconds |
59
+ ./spec/rspec/be_valid_when/is_spec.rb[1:3:2] | passed | 0.00399 seconds |
60
+ ./spec/rspec/be_valid_when/is_spec.rb[1:4] | passed | 0.0001 seconds |
61
+ ./spec/rspec/be_valid_when/is_string_spec.rb[1:1:1] | passed | 0.00012 seconds |
62
+ ./spec/rspec/be_valid_when/is_string_spec.rb[1:1:2] | passed | 0.01625 seconds |
63
+ ./spec/rspec/be_valid_when/is_string_spec.rb[1:2:1] | passed | 0.00012 seconds |
64
+ ./spec/rspec/be_valid_when/is_string_spec.rb[1:2:2] | passed | 0.01559 seconds |
65
+ ./spec/rspec/be_valid_when/is_string_spec.rb[1:2:3] | passed | 0.00025 seconds |
66
+ ./spec/rspec/be_valid_when/is_symbol_spec.rb[1:1:1] | passed | 0.00014 seconds |
67
+ ./spec/rspec/be_valid_when/is_symbol_spec.rb[1:1:2] | passed | 0.01691 seconds |
68
+ ./spec/rspec/be_valid_when/is_symbol_spec.rb[1:2:1] | passed | 0.00044 seconds |
69
+ ./spec/rspec/be_valid_when/is_symbol_spec.rb[1:2:2] | passed | 0.05517 seconds |
70
+ ./spec/rspec/be_valid_when/is_symbol_spec.rb[1:2:3] | passed | 0.0011 seconds |
71
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:1] | passed | 0.00034 seconds |
72
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:2] | passed | 0.00067 seconds |
73
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:3] | passed | 0.00011 seconds |
74
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:4] | passed | 0.00011 seconds |
75
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:5] | passed | 0.00009 seconds |
76
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:6] | passed | 0.0001 seconds |
77
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:7] | passed | 0.00009 seconds |
78
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:8] | passed | 0.00011 seconds |
79
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:9] | passed | 0.0001 seconds |
80
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:10] | passed | 0.00011 seconds |
81
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:1] | passed | 0.00013 seconds |
82
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:2] | passed | 0.00014 seconds |
83
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:1] | passed | 0.00013 seconds |
84
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:2] | passed | 0.00012 seconds |
85
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:3] | passed | 0.00014 seconds |
86
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:4] | passed | 0.00013 seconds |
87
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:5] | passed | 0.00012 seconds |
88
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:1] | passed | 0.00011 seconds |
89
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:2:1] | passed | 0.004 seconds |
90
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:2:2] | passed | 0.0039 seconds |
91
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:1] | passed | 0.0001 seconds |
92
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:2:1] | passed | 0.00376 seconds |
93
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:2:2] | passed | 0.00394 seconds |
94
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:5] | passed | 0.00016 seconds |
95
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:1] | passed | 0.00019 seconds |
96
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:2] | passed | 0.00017 seconds |
97
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:3] | passed | 0.00013 seconds |
98
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:4] | passed | 0.00013 seconds |
99
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:1:1] | passed | 0.00408 seconds |
100
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:1:2] | passed | 0.00794 seconds |
101
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:2:1] | passed | 0.00383 seconds |
102
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:2:2] | passed | 0.00828 seconds |
103
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:8:1] | passed | 0.0039 seconds |
104
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:8:2:1] | passed | 0.00385 seconds |
105
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:9:1] | passed | 0.00012 seconds |
@@ -0,0 +1,80 @@
1
+ require 'active_model'
2
+
3
+ # @private
4
+ class FakeModel
5
+ include ActiveModel::Validations
6
+
7
+ attr_accessor :array_field
8
+ attr_accessor :not_array_field
9
+
10
+ validate :array_field_should_be_array,
11
+ :array_field_cannot_be_empty,
12
+ :not_array_field_cannot_be_array
13
+
14
+ private
15
+
16
+ def array_field_should_be_array
17
+ errors.add(:array_field, 'should be array') unless array_field.is_a? Array
18
+ end
19
+
20
+ def array_field_cannot_be_empty
21
+ errors.add(:array_field, "can't be empty") if !array_field.nil? && array_field.length == 0
22
+ end
23
+
24
+ def not_array_field_cannot_be_array
25
+ errors.add(:not_array_field, "can't be array") if not_array_field.is_a? Array
26
+ end
27
+ end
28
+
29
+ describe 'be_valid_when#is_array' do
30
+ let(:model) { FakeModel.new }
31
+
32
+ context 'with no arguments' do
33
+ let(:description) { /^be valid when #array_field is a array \(\[42\]\)$/ }
34
+
35
+ let(:passing_matcher) { be_valid_when(:array_field).is_array }
36
+ let(:failing_matcher) { be_valid_when(:not_array_field).is_array }
37
+
38
+ it 'has the correct description' do
39
+ expect(passing_matcher.description).to match description
40
+ end
41
+
42
+ it 'returns proper result' do
43
+ expect(passing_matcher.matches? model).to eq true
44
+ expect(passing_matcher.does_not_match? model).to eq false
45
+ expect(failing_matcher.matches? model).to eq false
46
+ expect(failing_matcher.does_not_match? model).to eq true
47
+ end
48
+ end
49
+
50
+ context 'with one argument' do
51
+ let(:description) { /^be valid when #array_field is a array \(\[1, 2\]\)$/ }
52
+
53
+ let(:passing_matcher) { be_valid_when(:array_field).is_array [1, 2] }
54
+ let(:failing_matcher) { be_valid_when(:array_field).is_array [] }
55
+
56
+ it 'has the correct description' do
57
+ expect(passing_matcher.description).to match description
58
+ end
59
+
60
+ it 'returns proper result' do
61
+ expect(passing_matcher.matches? model).to eq true
62
+ expect(passing_matcher.does_not_match? model).to eq false
63
+ expect(failing_matcher.matches? model).to eq false
64
+ expect(failing_matcher.does_not_match? model).to eq true
65
+ end
66
+
67
+ it 'should fail if passed non array' do
68
+ expect { be_valid_when(:array_field).is_array 42 }.to raise_error ArgumentError
69
+ expect { be_valid_when(:array_field).is_array 42**42 }.to raise_error ArgumentError
70
+ expect { be_valid_when(:array_field).is_array 3.14 }.to raise_error ArgumentError
71
+ expect { be_valid_when(:array_field).is_array 42.to_c }.to raise_error ArgumentError
72
+ expect { be_valid_when(:array_field).is_array 42.to_r }.to raise_error ArgumentError
73
+ expect { be_valid_when(:array_field).is_array 'value' }.to raise_error ArgumentError
74
+ expect { be_valid_when(:array_field).is_array '42' }.to raise_error ArgumentError
75
+ expect { be_valid_when(:array_field).is_array(/^value$/) }.to raise_error ArgumentError
76
+ expect { be_valid_when(:array_field).is_array({}) }.to raise_error ArgumentError
77
+ expect { be_valid_when(:array_field).is_array :value }.to raise_error ArgumentError
78
+ end
79
+ end
80
+ end
@@ -57,11 +57,24 @@ describe 'be_valid_when#is_bigdecimal' do
57
57
  end
58
58
 
59
59
  it 'should fail if passed non bigdecimal' do
60
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal 42 }.to raise_error ArgumentError
61
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal 42**42 }.to raise_error ArgumentError
62
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal 3.14 }.to raise_error ArgumentError
63
+ expect do
64
+ be_valid_when(:bigdecimal_field).is_bigdecimal 42.to_c
65
+ end.to raise_error ArgumentError
66
+ expect do
67
+ be_valid_when(:bigdecimal_field).is_bigdecimal 42.to_r
68
+ end.to raise_error ArgumentError
60
69
  expect do
61
70
  be_valid_when(:bigdecimal_field).is_bigdecimal 'value'
62
71
  end.to raise_error ArgumentError
63
72
  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
73
+ expect do
74
+ be_valid_when(:bigdecimal_field).is_bigdecimal(/^value$/)
75
+ end.to raise_error ArgumentError
76
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal [1, 2] }.to raise_error ArgumentError
77
+ expect { be_valid_when(:bigdecimal_field).is_bigdecimal({}) }.to raise_error ArgumentError
65
78
  expect { be_valid_when(:bigdecimal_field).is_bigdecimal :value }.to raise_error ArgumentError
66
79
  end
67
80
  end
@@ -56,10 +56,16 @@ describe 'be_valid_when#is_bignum' do
56
56
  end
57
57
 
58
58
  it 'should fail if passed non bignum' do
59
- expect { be_valid_when(:bignum_field).is_bignum 'value' }.to raise_error ArgumentError
60
- expect { be_valid_when(:bignum_field).is_bignum '42' }.to raise_error ArgumentError
61
59
  expect { be_valid_when(:bignum_field).is_bignum 42 }.to raise_error ArgumentError
62
60
  expect { be_valid_when(:bignum_field).is_bignum 3.14 }.to raise_error ArgumentError
61
+ expect { be_valid_when(:bignum_field).is_bignum 42.to_c }.to raise_error ArgumentError
62
+ expect { be_valid_when(:bignum_field).is_bignum 42.to_r }.to raise_error ArgumentError
63
+ expect { be_valid_when(:bignum_field).is_bignum BigDecimal.new }.to raise_error ArgumentError
64
+ expect { be_valid_when(:bignum_field).is_bignum 'value' }.to raise_error ArgumentError
65
+ expect { be_valid_when(:bignum_field).is_bignum '42' }.to raise_error ArgumentError
66
+ expect { be_valid_when(:bignum_field).is_bignum(/^value$/) }.to raise_error ArgumentError
67
+ expect { be_valid_when(:bignum_field).is_bignum [1, 2] }.to raise_error ArgumentError
68
+ expect { be_valid_when(:bignum_field).is_bignum({}) }.to raise_error ArgumentError
63
69
  expect { be_valid_when(:bignum_field).is_bignum :value }.to raise_error ArgumentError
64
70
  end
65
71
  end
@@ -56,11 +56,18 @@ describe 'be_valid_when#is_complex' do
56
56
  end
57
57
 
58
58
  it 'should fail if passed non complex' do
59
- expect { be_valid_when(:complex_field).is_complex 'value' }.to raise_error ArgumentError
60
- expect { be_valid_when(:complex_field).is_complex '42' }.to raise_error ArgumentError
61
59
  expect { be_valid_when(:complex_field).is_complex 42 }.to raise_error ArgumentError
62
60
  expect { be_valid_when(:complex_field).is_complex 42**42 }.to raise_error ArgumentError
63
61
  expect { be_valid_when(:complex_field).is_complex 3.14 }.to raise_error ArgumentError
62
+ expect { be_valid_when(:complex_field).is_complex 42.to_r }.to raise_error ArgumentError
63
+ expect do
64
+ be_valid_when(:complex_field).is_complex BigDecimal.new
65
+ end.to raise_error ArgumentError
66
+ expect { be_valid_when(:complex_field).is_complex 'value' }.to raise_error ArgumentError
67
+ expect { be_valid_when(:complex_field).is_complex '42' }.to raise_error ArgumentError
68
+ expect { be_valid_when(:complex_field).is_complex(/^value$/) }.to raise_error ArgumentError
69
+ expect { be_valid_when(:complex_field).is_complex [1, 2] }.to raise_error ArgumentError
70
+ expect { be_valid_when(:complex_field).is_complex({}) }.to raise_error ArgumentError
64
71
  expect { be_valid_when(:complex_field).is_complex :value }.to raise_error ArgumentError
65
72
  end
66
73
  end
@@ -56,9 +56,16 @@ describe 'be_valid_when#is_fixnum' do
56
56
  end
57
57
 
58
58
  it 'should fail if passed non fixnum' do
59
+ expect { be_valid_when(:fixnum_field).is_fixnum 42**42 }.to raise_error ArgumentError
60
+ expect { be_valid_when(:fixnum_field).is_fixnum 3.14 }.to raise_error ArgumentError
61
+ expect { be_valid_when(:fixnum_field).is_fixnum 42.to_c }.to raise_error ArgumentError
62
+ expect { be_valid_when(:fixnum_field).is_fixnum 42.to_r }.to raise_error ArgumentError
63
+ expect { be_valid_when(:fixnum_field).is_fixnum BigDecimal.new }.to raise_error ArgumentError
59
64
  expect { be_valid_when(:fixnum_field).is_fixnum 'value' }.to raise_error ArgumentError
60
65
  expect { be_valid_when(:fixnum_field).is_fixnum '42' }.to raise_error ArgumentError
61
- expect { be_valid_when(:fixnum_field).is_fixnum 3.14 }.to raise_error ArgumentError
66
+ expect { be_valid_when(:fixnum_field).is_fixnum(/^value$/) }.to raise_error ArgumentError
67
+ expect { be_valid_when(:fixnum_field).is_fixnum [1, 2] }.to raise_error ArgumentError
68
+ expect { be_valid_when(:fixnum_field).is_fixnum({}) }.to raise_error ArgumentError
62
69
  expect { be_valid_when(:fixnum_field).is_fixnum :value }.to raise_error ArgumentError
63
70
  end
64
71
  end
@@ -56,10 +56,16 @@ describe 'be_valid_when#is_float' do
56
56
  end
57
57
 
58
58
  it 'should fail if passed non float' do
59
- expect { be_valid_when(:float_field).is_float 'value' }.to raise_error ArgumentError
60
- expect { be_valid_when(:float_field).is_float '42' }.to raise_error ArgumentError
61
59
  expect { be_valid_when(:float_field).is_float 42 }.to raise_error ArgumentError
62
60
  expect { be_valid_when(:float_field).is_float 42**42 }.to raise_error ArgumentError
61
+ expect { be_valid_when(:float_field).is_float 42.to_c }.to raise_error ArgumentError
62
+ expect { be_valid_when(:float_field).is_float 42.to_r }.to raise_error ArgumentError
63
+ expect { be_valid_when(:float_field).is_float BigDecimal.new }.to raise_error ArgumentError
64
+ expect { be_valid_when(:float_field).is_float 'value' }.to raise_error ArgumentError
65
+ expect { be_valid_when(:float_field).is_float '42' }.to raise_error ArgumentError
66
+ expect { be_valid_when(:float_field).is_float(/^value$/) }.to raise_error ArgumentError
67
+ expect { be_valid_when(:float_field).is_float [1, 2] }.to raise_error ArgumentError
68
+ expect { be_valid_when(:float_field).is_float({}) }.to raise_error ArgumentError
63
69
  expect { be_valid_when(:float_field).is_float :value }.to raise_error ArgumentError
64
70
  end
65
71
  end
@@ -0,0 +1,80 @@
1
+ require 'active_model'
2
+
3
+ # @private
4
+ class FakeModel
5
+ include ActiveModel::Validations
6
+
7
+ attr_accessor :hash_field
8
+ attr_accessor :not_hash_field
9
+
10
+ validate :hash_field_should_be_hash,
11
+ :hash_field_cannot_be_empty,
12
+ :not_hash_field_cannot_be_hash
13
+
14
+ private
15
+
16
+ def hash_field_should_be_hash
17
+ errors.add(:hash_field, 'should be hash') unless hash_field.is_a? Hash
18
+ end
19
+
20
+ def hash_field_cannot_be_empty
21
+ errors.add(:hash_field, "can't be empty") if !hash_field.nil? && hash_field.keys.length == 0
22
+ end
23
+
24
+ def not_hash_field_cannot_be_hash
25
+ errors.add(:not_hash_field, "can't be hash") if not_hash_field.is_a? Hash
26
+ end
27
+ end
28
+
29
+ describe 'be_valid_when#is_hash' do
30
+ let(:model) { FakeModel.new }
31
+
32
+ context 'with no arguments' do
33
+ let(:description) { /^be valid when #hash_field is a hash \(\{:value=>42\}\)$/ }
34
+
35
+ let(:passing_matcher) { be_valid_when(:hash_field).is_hash }
36
+ let(:failing_matcher) { be_valid_when(:not_hash_field).is_hash }
37
+
38
+ it 'has the correct description' do
39
+ expect(passing_matcher.description).to match description
40
+ end
41
+
42
+ it 'returns proper result' do
43
+ expect(passing_matcher.matches? model).to eq true
44
+ expect(passing_matcher.does_not_match? model).to eq false
45
+ expect(failing_matcher.matches? model).to eq false
46
+ expect(failing_matcher.does_not_match? model).to eq true
47
+ end
48
+ end
49
+
50
+ context 'with one argument' do
51
+ let(:description) { /^be valid when #hash_field is a hash \({:a=>1\}\)$/ }
52
+
53
+ let(:passing_matcher) { be_valid_when(:hash_field).is_hash(a: 1) }
54
+ let(:failing_matcher) { be_valid_when(:hash_field).is_hash({}) }
55
+
56
+ it 'has the correct description' do
57
+ expect(passing_matcher.description).to match description
58
+ end
59
+
60
+ it 'returns proper result' do
61
+ expect(passing_matcher.matches? model).to eq true
62
+ expect(passing_matcher.does_not_match? model).to eq false
63
+ expect(failing_matcher.matches? model).to eq false
64
+ expect(failing_matcher.does_not_match? model).to eq true
65
+ end
66
+
67
+ it 'should fail if passed non hash' do
68
+ expect { be_valid_when(:hash_field).is_hash 42 }.to raise_error ArgumentError
69
+ expect { be_valid_when(:hash_field).is_hash 42**42 }.to raise_error ArgumentError
70
+ expect { be_valid_when(:hash_field).is_hash 3.14 }.to raise_error ArgumentError
71
+ expect { be_valid_when(:hash_field).is_hash 42.to_c }.to raise_error ArgumentError
72
+ expect { be_valid_when(:hash_field).is_hash 42.to_r }.to raise_error ArgumentError
73
+ expect { be_valid_when(:hash_field).is_hash 'value' }.to raise_error ArgumentError
74
+ expect { be_valid_when(:hash_field).is_hash '42' }.to raise_error ArgumentError
75
+ expect { be_valid_when(:hash_field).is_hash(/^value$/) }.to raise_error ArgumentError
76
+ expect { be_valid_when(:hash_field).is_hash [1, 2] }.to raise_error ArgumentError
77
+ expect { be_valid_when(:hash_field).is_hash :value }.to raise_error ArgumentError
78
+ end
79
+ end
80
+ end
@@ -29,4 +29,8 @@ describe 'be_valid_when#is_not_present' do
29
29
  expect(failing_matcher.matches? model).to eq false
30
30
  expect(failing_matcher.does_not_match? model).to eq true
31
31
  end
32
+
33
+ it 'does not accept any arguments' do
34
+ expect { be_valid_when(:field).is_not_present 'value' }.to raise_error ArgumentError
35
+ end
32
36
  end
@@ -52,6 +52,9 @@ describe 'be_valid_when#is_number' do
52
52
  it 'should fail if passed non number' do
53
53
  expect { be_valid_when(:number_field).is_number 'value' }.to raise_error ArgumentError
54
54
  expect { be_valid_when(:number_field).is_number '42' }.to raise_error ArgumentError
55
+ expect { be_valid_when(:number_field).is_number(/^value$/) }.to raise_error ArgumentError
56
+ expect { be_valid_when(:number_field).is_number [1, 2] }.to raise_error ArgumentError
57
+ expect { be_valid_when(:number_field).is_number({}) }.to raise_error ArgumentError
55
58
  expect { be_valid_when(:number_field).is_number :value }.to raise_error ArgumentError
56
59
  end
57
60
  end
@@ -56,11 +56,18 @@ describe 'be_valid_when#is_rational' do
56
56
  end
57
57
 
58
58
  it 'should fail if passed non rational' do
59
- expect { be_valid_when(:rational_field).is_rational 'value' }.to raise_error ArgumentError
60
- expect { be_valid_when(:rational_field).is_rational '42' }.to raise_error ArgumentError
61
- expect { be_valid_when(:rational_field).is_rational 3.14 }.to raise_error ArgumentError
59
+ expect { be_valid_when(:rational_field).is_rational 42 }.to raise_error ArgumentError
62
60
  expect { be_valid_when(:rational_field).is_rational 42**42 }.to raise_error ArgumentError
61
+ expect { be_valid_when(:rational_field).is_rational 3.14 }.to raise_error ArgumentError
63
62
  expect { be_valid_when(:rational_field).is_rational 42.to_c }.to raise_error ArgumentError
63
+ expect do
64
+ be_valid_when(:rational_field).is_rational BigDecimal.new
65
+ end.to raise_error ArgumentError
66
+ expect { be_valid_when(:rational_field).is_rational 'value' }.to raise_error ArgumentError
67
+ expect { be_valid_when(:rational_field).is_rational '42' }.to raise_error ArgumentError
68
+ expect { be_valid_when(:rational_field).is_rational(/^value$/) }.to raise_error ArgumentError
69
+ expect { be_valid_when(:rational_field).is_rational [1, 2] }.to raise_error ArgumentError
70
+ expect { be_valid_when(:rational_field).is_rational({}) }.to raise_error ArgumentError
64
71
  expect { be_valid_when(:rational_field).is_rational :value }.to raise_error ArgumentError
65
72
  end
66
73
  end
@@ -0,0 +1,80 @@
1
+ require 'active_model'
2
+
3
+ # @private
4
+ class FakeModel
5
+ include ActiveModel::Validations
6
+
7
+ attr_accessor :regexp_field
8
+ attr_accessor :not_regexp_field
9
+
10
+ validate :regexp_field_should_be_regexp,
11
+ :regexp_field_cannot_be_empty,
12
+ :not_regexp_field_cannot_be_regexp
13
+
14
+ private
15
+
16
+ def regexp_field_should_be_regexp
17
+ errors.add(:regexp_field, 'should be regexp') unless regexp_field.is_a? Regexp
18
+ end
19
+
20
+ def regexp_field_cannot_be_empty
21
+ errors.add(:regexp_field, "can't be empty") if regexp_field.inspect.length < 3
22
+ end
23
+
24
+ def not_regexp_field_cannot_be_regexp
25
+ errors.add(:not_regexp_field, "can't be regexp") if not_regexp_field.is_a? Regexp
26
+ end
27
+ end
28
+
29
+ describe 'be_valid_when#is_regexp' do
30
+ let(:model) { FakeModel.new }
31
+
32
+ context 'with no arguments' do
33
+ let(:description) { %r{^be valid when #regexp_field is a regexp \(/\^value\$/\)$} }
34
+
35
+ let(:passing_matcher) { be_valid_when(:regexp_field).is_regexp }
36
+ let(:failing_matcher) { be_valid_when(:not_regexp_field).is_regexp }
37
+
38
+ it 'has the correct description' do
39
+ expect(passing_matcher.description).to match description
40
+ end
41
+
42
+ it 'returns proper result' do
43
+ expect(passing_matcher.matches? model).to eq true
44
+ expect(passing_matcher.does_not_match? model).to eq false
45
+ expect(failing_matcher.matches? model).to eq false
46
+ expect(failing_matcher.does_not_match? model).to eq true
47
+ end
48
+ end
49
+
50
+ context 'with one argument' do
51
+ let(:description) { %r{^be valid when #regexp_field is a regexp \(/some regexp/\)$} }
52
+
53
+ let(:passing_matcher) { be_valid_when(:regexp_field).is_regexp(/some regexp/) }
54
+ let(:failing_matcher) { be_valid_when(:regexp_field).is_regexp(//) }
55
+
56
+ it 'has the correct description' do
57
+ expect(passing_matcher.description).to match description
58
+ end
59
+
60
+ it 'returns proper result' do
61
+ expect(passing_matcher.matches? model).to eq true
62
+ expect(passing_matcher.does_not_match? model).to eq false
63
+ expect(failing_matcher.matches? model).to eq false
64
+ expect(failing_matcher.does_not_match? model).to eq true
65
+ end
66
+
67
+ it 'should fail if passed non regexp' do
68
+ expect { be_valid_when(:regexp_field).is_regexp 42 }.to raise_error ArgumentError
69
+ expect { be_valid_when(:regexp_field).is_regexp 42**42 }.to raise_error ArgumentError
70
+ expect { be_valid_when(:regexp_field).is_regexp 3.14 }.to raise_error ArgumentError
71
+ expect { be_valid_when(:regexp_field).is_regexp 42.to_c }.to raise_error ArgumentError
72
+ expect { be_valid_when(:regexp_field).is_regexp 42.to_r }.to raise_error ArgumentError
73
+ expect { be_valid_when(:regexp_field).is_regexp 'value' }.to raise_error ArgumentError
74
+ expect { be_valid_when(:regexp_field).is_regexp '42' }.to raise_error ArgumentError
75
+ expect { be_valid_when(:regexp_field).is_regexp [1, 2] }.to raise_error ArgumentError
76
+ expect { be_valid_when(:regexp_field).is_regexp({}) }.to raise_error ArgumentError
77
+ expect { be_valid_when(:regexp_field).is_regexp :value }.to raise_error ArgumentError
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,70 @@
1
+ require 'active_model'
2
+
3
+ # @private
4
+ class FakeModel
5
+ include ActiveModel::Validations
6
+
7
+ attr_accessor :string_field
8
+ attr_accessor :not_string_field
9
+
10
+ validates_length_of :string_field, minimum: 4
11
+ validate :not_string_field_cannot_be_string
12
+
13
+ private
14
+
15
+ def not_string_field_cannot_be_string
16
+ errors.add(:not_string_field, "can't be string") if not_string_field.is_a? String
17
+ end
18
+ end
19
+
20
+ describe 'be_valid_when#is_string' do
21
+ let(:model) { FakeModel.new }
22
+
23
+ context 'with no arguments' do
24
+ let(:description) { /^be valid when #string_field is a string \("value"\)$/ }
25
+
26
+ let(:passing_matcher) { be_valid_when(:string_field).is_string }
27
+ let(:failing_matcher) { be_valid_when(:not_string_field).is_string }
28
+
29
+ it 'has the correct description' do
30
+ expect(passing_matcher.description).to match description
31
+ end
32
+
33
+ it 'returns proper result' do
34
+ expect(passing_matcher.matches? model).to eq true
35
+ expect(passing_matcher.does_not_match? model).to eq false
36
+ expect(failing_matcher.matches? model).to eq false
37
+ expect(failing_matcher.does_not_match? model).to eq true
38
+ end
39
+ end
40
+
41
+ context 'with one argument' do
42
+ let(:description) { /^be valid when #string_field is a string \("some string"\)$/ }
43
+
44
+ let(:passing_matcher) { be_valid_when(:string_field).is_string 'some string' }
45
+ let(:failing_matcher) { be_valid_when(:string_field).is_string 'a' }
46
+
47
+ it 'has the correct description' do
48
+ expect(passing_matcher.description).to match description
49
+ end
50
+
51
+ it 'returns proper result' do
52
+ expect(passing_matcher.matches? model).to eq true
53
+ expect(passing_matcher.does_not_match? model).to eq false
54
+ expect(failing_matcher.matches? model).to eq false
55
+ expect(failing_matcher.does_not_match? model).to eq true
56
+ end
57
+
58
+ it 'should fail if passed non string' do
59
+ expect { be_valid_when(:string_field).is_string 42 }.to raise_error ArgumentError
60
+ expect { be_valid_when(:string_field).is_string 42**42 }.to raise_error ArgumentError
61
+ expect { be_valid_when(:string_field).is_string 3.14 }.to raise_error ArgumentError
62
+ expect { be_valid_when(:string_field).is_string 42.to_c }.to raise_error ArgumentError
63
+ expect { be_valid_when(:string_field).is_string 42.to_r }.to raise_error ArgumentError
64
+ expect { be_valid_when(:string_field).is_string(/^value$/) }.to raise_error ArgumentError
65
+ expect { be_valid_when(:string_field).is_string [1, 2] }.to raise_error ArgumentError
66
+ expect { be_valid_when(:string_field).is_string({}) }.to raise_error ArgumentError
67
+ expect { be_valid_when(:string_field).is_string :value }.to raise_error ArgumentError
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,80 @@
1
+ require 'active_model'
2
+
3
+ # @private
4
+ class FakeModel
5
+ include ActiveModel::Validations
6
+
7
+ attr_accessor :symbol_field
8
+ attr_accessor :not_symbol_field
9
+
10
+ validate :symbol_field_should_be_symbol,
11
+ :symbol_field_cannot_be_short,
12
+ :not_symbol_field_cannot_be_symbol
13
+
14
+ private
15
+
16
+ def symbol_field_should_be_symbol
17
+ errors.add(:symbol_field, 'should be symbol') unless symbol_field.is_a? Symbol
18
+ end
19
+
20
+ def symbol_field_cannot_be_short
21
+ errors.add(:symbol_field, "can't be short") if !symbol_field.nil? && symbol_field.length < 2
22
+ end
23
+
24
+ def not_symbol_field_cannot_be_symbol
25
+ errors.add(:not_symbol_field, "can't be symbol") if not_symbol_field.is_a? Symbol
26
+ end
27
+ end
28
+
29
+ describe 'be_valid_when#is_symbol' do
30
+ let(:model) { FakeModel.new }
31
+
32
+ context 'with no arguments' do
33
+ let(:description) { /^be valid when #symbol_field is a symbol \(:value\)$/ }
34
+
35
+ let(:passing_matcher) { be_valid_when(:symbol_field).is_symbol }
36
+ let(:failing_matcher) { be_valid_when(:not_symbol_field).is_symbol }
37
+
38
+ it 'has the correct description' do
39
+ expect(passing_matcher.description).to match description
40
+ end
41
+
42
+ it 'returns proper result' do
43
+ expect(passing_matcher.matches? model).to eq true
44
+ expect(passing_matcher.does_not_match? model).to eq false
45
+ expect(failing_matcher.matches? model).to eq false
46
+ expect(failing_matcher.does_not_match? model).to eq true
47
+ end
48
+ end
49
+
50
+ context 'with one argument' do
51
+ let(:description) { /^be valid when #symbol_field is a symbol \(:some_symbol\)$/ }
52
+
53
+ let(:passing_matcher) { be_valid_when(:symbol_field).is_symbol :some_symbol }
54
+ let(:failing_matcher) { be_valid_when(:symbol_field).is_symbol :a }
55
+
56
+ it 'has the correct description' do
57
+ expect(passing_matcher.description).to match description
58
+ end
59
+
60
+ it 'returns proper result' do
61
+ expect(passing_matcher.matches? model).to eq true
62
+ expect(passing_matcher.does_not_match? model).to eq false
63
+ expect(failing_matcher.matches? model).to eq false
64
+ expect(failing_matcher.does_not_match? model).to eq true
65
+ end
66
+
67
+ it 'should fail if passed non symbol' do
68
+ expect { be_valid_when(:symbol_field).is_symbol 42 }.to raise_error ArgumentError
69
+ expect { be_valid_when(:symbol_field).is_symbol 42**42 }.to raise_error ArgumentError
70
+ expect { be_valid_when(:symbol_field).is_symbol 3.14 }.to raise_error ArgumentError
71
+ expect { be_valid_when(:symbol_field).is_symbol 42.to_c }.to raise_error ArgumentError
72
+ expect { be_valid_when(:symbol_field).is_symbol 42.to_r }.to raise_error ArgumentError
73
+ expect { be_valid_when(:symbol_field).is_symbol 'value' }.to raise_error ArgumentError
74
+ expect { be_valid_when(:symbol_field).is_symbol '42' }.to raise_error ArgumentError
75
+ expect { be_valid_when(:symbol_field).is_symbol(/^value$/) }.to raise_error ArgumentError
76
+ expect { be_valid_when(:symbol_field).is_symbol [1, 2] }.to raise_error ArgumentError
77
+ expect { be_valid_when(:symbol_field).is_symbol({}) }.to raise_error ArgumentError
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-be_valid_when_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Tuchowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -50,15 +50,20 @@ 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_array_spec.rb
53
54
  - spec/rspec/be_valid_when/is_bigdecimal_spec.rb
54
55
  - spec/rspec/be_valid_when/is_bignum_spec.rb
55
56
  - spec/rspec/be_valid_when/is_complex_spec.rb
56
57
  - spec/rspec/be_valid_when/is_fixnum_spec.rb
57
58
  - spec/rspec/be_valid_when/is_float_spec.rb
59
+ - spec/rspec/be_valid_when/is_hash_spec.rb
58
60
  - spec/rspec/be_valid_when/is_not_present_spec.rb
59
61
  - spec/rspec/be_valid_when/is_number_spec.rb
60
62
  - spec/rspec/be_valid_when/is_rational_spec.rb
63
+ - spec/rspec/be_valid_when/is_regex_spec.rb
61
64
  - spec/rspec/be_valid_when/is_spec.rb
65
+ - spec/rspec/be_valid_when/is_string_spec.rb
66
+ - spec/rspec/be_valid_when/is_symbol_spec.rb
62
67
  - spec/rspec/be_valid_when_matcher_spec.rb
63
68
  - spec/spec_helper.rb
64
69
  homepage: https://github.com/mtuchowski/rspec-be_valid_when_matcher
@@ -90,6 +95,7 @@ summary: RSpec be_valid_when matcher for ActiveRecord models.
90
95
  test_files:
91
96
  - spec/spec_helper.rb
92
97
  - spec/rspec/be_valid_when_matcher_spec.rb
98
+ - spec/rspec/be_valid_when/is_symbol_spec.rb
93
99
  - spec/rspec/be_valid_when/is_number_spec.rb
94
100
  - spec/rspec/be_valid_when/is_float_spec.rb
95
101
  - spec/rspec/be_valid_when/is_rational_spec.rb
@@ -97,7 +103,11 @@ test_files:
97
103
  - spec/rspec/be_valid_when/is_spec.rb
98
104
  - spec/rspec/be_valid_when/is_not_present_spec.rb
99
105
  - spec/rspec/be_valid_when/is_fixnum_spec.rb
106
+ - spec/rspec/be_valid_when/is_array_spec.rb
100
107
  - spec/rspec/be_valid_when/is_bigdecimal_spec.rb
101
108
  - spec/rspec/be_valid_when/is_complex_spec.rb
109
+ - spec/rspec/be_valid_when/is_string_spec.rb
110
+ - spec/rspec/be_valid_when/is_regex_spec.rb
111
+ - spec/rspec/be_valid_when/is_hash_spec.rb
102
112
  - spec/examples.cache
103
113
  has_rdoc: