rspec-be_valid_when_matcher 0.3.0 → 1.0.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: bfa5bfc671b2323ea01bdb96e8961cdfd28e9d4e
4
- data.tar.gz: 000086bef61468b32d52a46e26f1ddb08b0d41bd
3
+ metadata.gz: 13cf6df391015ff30c249f2712a745dcee089f4e
4
+ data.tar.gz: 898eadd1e2b5a56c6a22bb49112725d28de32a6b
5
5
  SHA512:
6
- metadata.gz: f912c394bfcca9bf3b0c2954ce498cf63c1676915494afc2c1cd7787d7be83d33946d7f0ab468d5b391d5ceef50e720ed219d17df40bc8133eea917d55812921
7
- data.tar.gz: b10fc3102760625bb6d5c427911889e5a3b22f780b38d9604c133efb939bcf602e969780a12d087a580ddc2e5be03f7e26467f0efe8976f964126a9a47e251f4
6
+ metadata.gz: f49b94989edc31bef1f44bf8e045447eb5f8c845b3840959681b11e2ff20a697390e691b5102de06e099316ab60a6f15d6cb8a2585c769c39b1969a54276942a
7
+ data.tar.gz: 05350d0b199501706dda7fc640c03f3c51c319070344f17d7cd226c52ea38dab6659dcdefa679310761d38102f64fe4babb939a2a0ad26a4ca11f713388901af
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  RSpec matcher for testing ActiveRecord models with a fluent and clear language.
9
9
 
10
10
  ```ruby
11
- expect(person).to be_valid_when(:age).is_number
11
+ expect(person).to be_valid_when(:age).is_numeric
12
12
  ```
13
13
 
14
14
  The matcher will check only the specified field for validation errors, so if there's one buggy
@@ -111,7 +111,8 @@ be_valid_when(:field).is_not_present
111
111
  Test field validity with specific type values (all methods accept field value argument):
112
112
 
113
113
  ```ruby
114
- be_valid_when(:field).is_number # Defaults to 42
114
+ be_valid_when(:field).is_numeric # Defaults to 42
115
+ be_valid_when(:field).is_integer # Defaults to 42
115
116
  be_valid_when(:field).is_fixnum # Defaults to 42
116
117
  be_valid_when(:field).is_bignum # Defaults to 42**13
117
118
  be_valid_when(:field).is_float # Defaults to 3.14
@@ -126,18 +126,19 @@ module RSpec
126
126
  end
127
127
 
128
128
  # Generate #is_*(type) methods.
129
- { number: { value: 42, type: Numeric },
130
- fixnum: { value: 42, type: Fixnum },
131
- bignum: { value: 42**13, type: Bignum },
132
- float: { value: Math::PI, type: Float },
133
- complex: { value: 42.to_c, type: Complex },
134
- rational: { value: 42.to_r, type: Rational },
129
+ { numeric: { value: 42, type: Numeric },
130
+ integer: { value: 42, type: Integer },
131
+ fixnum: { value: 42, type: Fixnum },
132
+ bignum: { value: 42**13, type: Bignum },
133
+ float: { value: Math::PI, type: Float },
134
+ complex: { value: 42.to_c, type: Complex },
135
+ rational: { value: 42.to_r, type: Rational },
135
136
  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|
137
+ string: { value: 'value', type: String },
138
+ regexp: { value: /^value$/, type: Regexp },
139
+ array: { value: [42], type: Array },
140
+ hash: { value: { value: 42 }, type: Hash },
141
+ symbol: { value: :value, type: Symbol } }.each do |name, properties|
141
142
  define_method "is_#{name}" do |value = properties[:value]|
142
143
  fail ArgumentError, "should be #{name}" unless value.is_a? properties[:type]
143
144
 
data/spec/examples.cache CHANGED
@@ -1,105 +1,110 @@
1
- example_id | status | run_time |
2
- ------------------------------------------------------- | ------ | --------------- |
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 |
10
- ./spec/rspec/be_valid_when/is_bigdecimal_spec.rb[1:2:1] | 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 |
13
- ./spec/rspec/be_valid_when/is_bignum_spec.rb[1:1:1] | passed | 0.00019 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 |
1
+ example_id | status | run_time |
2
+ ------------------------------------------------------ | ------ | --------------- |
3
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:1] | passed | 0.00621 seconds |
4
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:2] | passed | 0.00013 seconds |
5
+ ./spec/rspec/be_valid_when/is_not_present_spec.rb[1:3] | passed | 0.00028 seconds |
6
+ ./spec/rspec/be_valid_when/is_spec.rb[1:1] | passed | 0.00108 seconds |
7
+ ./spec/rspec/be_valid_when/is_spec.rb[1:2:1] | passed | 0.0404 seconds |
8
+ ./spec/rspec/be_valid_when/is_spec.rb[1:3:1] | passed | 0.00634 seconds |
9
+ ./spec/rspec/be_valid_when/is_spec.rb[1:3:2] | passed | 0.00134 seconds |
10
+ ./spec/rspec/be_valid_when/is_spec.rb[1:4] | passed | 0.0001 seconds |
11
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:2:1:1] | passed | 0.01153 seconds |
12
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:2:1:2] | passed | 0.00012 seconds |
13
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:2:2:1] | passed | 0.01104 seconds |
14
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:2:2:2] | passed | 0.00013 seconds |
15
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:2:2:3] | passed | 0.00022 seconds |
16
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:3:1:1] | passed | 0.01155 seconds |
17
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:3:1:2] | passed | 0.00016 seconds |
18
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:3:2:1] | passed | 0.01095 seconds |
19
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:3:2:2] | passed | 0.00013 seconds |
20
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:3:2:3] | passed | 0.00026 seconds |
21
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:4:1:1] | passed | 0.01196 seconds |
22
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:4:1:2] | passed | 0.00015 seconds |
23
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:4:2:1] | passed | 0.01168 seconds |
24
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:4:2:2] | passed | 0.00016 seconds |
25
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:4:2:3] | passed | 0.00034 seconds |
26
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:5:1:1] | passed | 0.01141 seconds |
27
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:5:1:2] | passed | 0.00015 seconds |
28
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:5:2:1] | passed | 0.01118 seconds |
29
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:5:2:2] | passed | 0.00013 seconds |
30
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:5:2:3] | passed | 0.0003 seconds |
31
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:6:1:1] | passed | 0.01036 seconds |
32
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:6:1:2] | passed | 0.00015 seconds |
33
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:6:2:1] | passed | 0.01252 seconds |
34
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:6:2:2] | passed | 0.00013 seconds |
35
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:6:2:3] | passed | 0.00031 seconds |
36
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:7:1:1] | passed | 0.0106 seconds |
37
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:7:1:2] | passed | 0.00014 seconds |
38
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:7:2:1] | passed | 0.01111 seconds |
39
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:7:2:2] | passed | 0.00016 seconds |
40
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:7:2:3] | passed | 0.0003 seconds |
41
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:8:1:1] | passed | 0.0105 seconds |
42
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:8:1:2] | passed | 0.00011 seconds |
43
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:8:2:1] | passed | 0.01271 seconds |
44
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:8:2:2] | passed | 0.00014 seconds |
45
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:8:2:3] | passed | 0.0003 seconds |
46
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:9:1:1] | passed | 0.01178 seconds |
47
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:9:1:2] | passed | 0.00015 seconds |
48
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:9:2:1] | passed | 0.01151 seconds |
49
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:9:2:2] | passed | 0.00015 seconds |
50
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:9:2:3] | passed | 0.00026 seconds |
51
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:10:1:1] | passed | 0.0101 seconds |
52
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:10:1:2] | passed | 0.00015 seconds |
53
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:10:2:1] | passed | 0.0108 seconds |
54
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:10:2:2] | passed | 0.00013 seconds |
55
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:10:2:3] | passed | 0.00029 seconds |
56
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:11:1:1] | passed | 0.01283 seconds |
57
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:11:1:2] | passed | 0.00013 seconds |
58
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:11:2:1] | passed | 0.01119 seconds |
59
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:11:2:2] | passed | 0.00013 seconds |
60
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:11:2:3] | passed | 0.00026 seconds |
61
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:12:1:1] | passed | 0.01163 seconds |
62
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:12:1:2] | passed | 0.00014 seconds |
63
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:12:2:1] | passed | 0.01164 seconds |
64
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:12:2:2] | passed | 0.00015 seconds |
65
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:12:2:3] | passed | 0.00029 seconds |
66
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:13:1:1] | passed | 0.01194 seconds |
67
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:13:1:2] | passed | 0.00013 seconds |
68
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:13:2:1] | passed | 0.01178 seconds |
69
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:13:2:2] | passed | 0.00014 seconds |
70
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:13:2:3] | passed | 0.00031 seconds |
71
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:14:1:1] | passed | 0.0119 seconds |
72
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:14:1:2] | passed | 0.00014 seconds |
73
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:14:2:1] | passed | 0.01467 seconds |
74
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:14:2:2] | passed | 0.00019 seconds |
75
+ ./spec/rspec/be_valid_when/is_type_spec.rb[1:14:2:3] | passed | 0.00029 seconds |
76
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:1] | passed | 0.00029 seconds |
77
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:2] | passed | 0.00012 seconds |
78
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:3] | passed | 0.0001 seconds |
79
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:4] | passed | 0.00009 seconds |
80
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:5] | passed | 0.00009 seconds |
81
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:6] | passed | 0.00009 seconds |
82
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:7] | passed | 0.00011 seconds |
83
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:8] | passed | 0.00062 seconds |
84
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:9] | passed | 0.0001 seconds |
85
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:1:10] | passed | 0.00008 seconds |
86
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:1] | passed | 0.0001 seconds |
87
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:2] | passed | 0.00013 seconds |
88
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:1] | passed | 0.00012 seconds |
89
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:2] | passed | 0.00012 seconds |
90
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:3] | passed | 0.00012 seconds |
91
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:4] | passed | 0.00011 seconds |
92
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:2:3:5] | passed | 0.00013 seconds |
93
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:1] | passed | 0.00009 seconds |
94
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:2:1] | passed | 0.00075 seconds |
95
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:3:2:2] | passed | 0.00079 seconds |
96
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:1] | passed | 0.00009 seconds |
97
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:2:1] | passed | 0.00081 seconds |
98
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:4:2:2] | passed | 0.00078 seconds |
99
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:5] | passed | 0.00012 seconds |
100
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:1] | passed | 0.00017 seconds |
101
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:2] | passed | 0.00013 seconds |
102
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:3] | passed | 0.0001 seconds |
103
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:6:4] | passed | 0.0001 seconds |
104
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:1:1] | passed | 0.00075 seconds |
105
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:1:2] | passed | 0.00203 seconds |
106
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:2:1] | passed | 0.00078 seconds |
107
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:7:2:2] | passed | 0.00196 seconds |
108
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:8:1] | passed | 0.00082 seconds |
109
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:8:2:1] | passed | 0.00083 seconds |
110
+ ./spec/rspec/be_valid_when_matcher_spec.rb[1:9:1] | passed | 0.00012 seconds |
@@ -1,4 +1,7 @@
1
1
  require 'active_model'
2
+ require 'support/has_correct_description'
3
+ require 'support/returns_proper_results'
4
+ require 'support/takes_no_arguments'
2
5
 
3
6
  # @private
4
7
  class FakeModel
@@ -17,20 +20,12 @@ describe 'be_valid_when#is_not_present' do
17
20
  let(:passing_matcher) { be_valid_when(:nil_field).is_not_present }
18
21
  let(:failing_matcher) { be_valid_when(:not_nil_field).is_not_present }
19
22
 
20
- let(:description) { /^be valid when #nil_field is not present \(nil\)$/ }
23
+ include_examples 'returns proper results'
21
24
 
22
- it 'has the correct description' do
23
- expect(passing_matcher.description).to match description
25
+ include_examples 'has correct description' do
26
+ let(:matcher) { passing_matcher }
27
+ let(:description) { /^be valid when #nil_field is not present \(nil\)$/ }
24
28
  end
25
29
 
26
- it 'returns proper result' do
27
- expect(passing_matcher.matches? model).to eq true
28
- expect(passing_matcher.does_not_match? model).to eq false
29
- expect(failing_matcher.matches? model).to eq false
30
- expect(failing_matcher.does_not_match? model).to eq true
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
30
+ include_examples 'takes no arguments', :field, :is_not_present
36
31
  end
@@ -0,0 +1,213 @@
1
+ require 'active_model'
2
+ require 'support/has_correct_description'
3
+ require 'support/returns_proper_results'
4
+
5
+ # @private
6
+ class FakeModelFoo
7
+ include ActiveModel::Validations
8
+
9
+ [Numeric, Integer, Fixnum, Bignum, Float, Complex, Rational, BigDecimal,
10
+ String, Regexp, Array, Hash, Symbol].each do |type|
11
+ type_name = type.name.downcase
12
+ field_name = "#{type_name}_field"
13
+ not_field_name = "not_#{field_name}"
14
+
15
+ # Accessors
16
+ send(:attr_accessor, field_name)
17
+ send(:attr_accessor, not_field_name)
18
+
19
+ # Validator for not_field_name attribute
20
+ validator_name = "#{not_field_name}_cannot_be_#{type_name}"
21
+
22
+ define_method validator_name do
23
+ errors.add(not_field_name.to_sym, "can't be #{type_name}") if
24
+ send(not_field_name).is_a? type
25
+ end
26
+
27
+ send(:validate, validator_name)
28
+ end
29
+
30
+ %w(numeric integer fixnum complex rational bigdecimal).each do |type_name|
31
+ send(:validates_numericality_of, "#{type_name}_field".to_sym, greater_than: 41)
32
+ end
33
+
34
+ validates_numericality_of :float_field, greater_than: 3.0
35
+ validates_numericality_of :bignum_field, greater_than: 30129469486639681537
36
+ validates_length_of :string_field, minimum: 4
37
+ validate :regexp_field_cannot_be_empty
38
+ validate :array_field_cannot_be_empty
39
+ validate :hash_field_cannot_be_empty
40
+ validate :symbol_field_cannot_be_short
41
+
42
+ def regexp_field_cannot_be_empty
43
+ errors.add(:regexp_field, "can't be empty") if regexp_field.inspect.length < 3
44
+ end
45
+
46
+ def array_field_cannot_be_empty
47
+ errors.add(:array_field, "can't be empty") if !array_field.nil? && array_field.length == 0
48
+ end
49
+
50
+ def hash_field_cannot_be_empty
51
+ errors.add(:hash_field, "can't be empty") if !hash_field.nil? && hash_field.keys.length == 0
52
+ end
53
+
54
+ def symbol_field_cannot_be_short
55
+ errors.add(:symbol_field, "can't be short") if !symbol_field.nil? && symbol_field.length < 2
56
+ end
57
+ end
58
+
59
+ describe 'be_valid_when' do
60
+ let(:model) { FakeModelFoo.new }
61
+
62
+ def invalid_values_for(type_name)
63
+ { integer: 42, bignum: 42**42, float: 3.14, complex: 42.to_c, rational: 42.to_r,
64
+ bigdecimal: BigDecimal.new('42'), string: 'value', regexp: /^value$/, array: [1, 2],
65
+ hash: {}, symbol: :value
66
+ }.reject do |key|
67
+ if type_name.is_a? Symbol
68
+ key == type_name
69
+ else
70
+ type_name.include? key
71
+ end
72
+ end
73
+ end
74
+
75
+ {
76
+ numeric: {
77
+ argument: { passing: 50, failing: 40 },
78
+ description: {
79
+ no_arguments: /^be valid when #numeric_field is a numeric \(42\)$/,
80
+ one_argument: /^be valid when #numeric_field is a numeric \(50\)$/
81
+ },
82
+ treat_as: [:integer, :bignum, :float, :complex, :rational, :bigdecimal]
83
+ },
84
+ integer: {
85
+ argument: { passing: 50, failing: 40 },
86
+ description: {
87
+ no_arguments: /^be valid when #integer_field is a integer \(42\)$/,
88
+ one_argument: /^be valid when #integer_field is a integer \(50\)$/
89
+ },
90
+ treat_as: [:integer, :bignum]
91
+ },
92
+ fixnum: {
93
+ argument: { passing: 50, failing: 40 },
94
+ description: {
95
+ no_arguments: /^be valid when #fixnum_field is a fixnum \(42\)$/,
96
+ one_argument: /^be valid when #fixnum_field is a fixnum \(50\)$/
97
+ },
98
+ treat_as: :integer
99
+ },
100
+ bignum: {
101
+ argument: { passing: 2232232135326160725639168, failing: 30129469486639681536 },
102
+ description: {
103
+ no_arguments: /^be valid when #bignum_field is a bignum \(1265437718438866624512\)$/,
104
+ one_argument: /^be valid when #bignum_field is a bignum \(2232232135326160725639168\)$/
105
+ }
106
+ },
107
+ float: {
108
+ argument: { passing: 4.2, failing: 2.4 },
109
+ description: {
110
+ no_arguments: /^be valid when #float_field is a float \(3.141592653589793\)$/,
111
+ one_argument: /^be valid when #float_field is a float \(4.2\)$/
112
+ }
113
+ },
114
+ complex: {
115
+ argument: { passing: 50.to_c, failing: 40.to_c },
116
+ description: {
117
+ no_arguments: /^be valid when #complex_field is a complex \(42\+0i\)$/,
118
+ one_argument: /^be valid when #complex_field is a complex \(50\+0i\)$/
119
+ }
120
+ },
121
+ rational: {
122
+ argument: { passing: 50.to_r, failing: 40.to_r },
123
+ description: {
124
+ no_arguments: %r{^be valid when #rational_field is a rational \(42/1\)$},
125
+ one_argument: %r{^be valid when #rational_field is a rational \(50/1\)$}
126
+ }
127
+ },
128
+ bigdecimal: {
129
+ argument: { passing: BigDecimal.new('50'), failing: BigDecimal.new('40') },
130
+ description: {
131
+ no_arguments: /^be valid when #bigdecimal_field is a bigdecimal \(0.42E2\)$/,
132
+ one_argument: /^be valid when #bigdecimal_field is a bigdecimal \(0.5E2\)$/
133
+ }
134
+ },
135
+ string: {
136
+ argument: { passing: 'some string', failing: 'a' },
137
+ description: {
138
+ no_arguments: /^be valid when #string_field is a string \("value"\)$/,
139
+ one_argument: /^be valid when #string_field is a string \("some string"\)$/
140
+ }
141
+ },
142
+ regexp: {
143
+ argument: { passing: /some regexp/, failing: // },
144
+ description: {
145
+ no_arguments: %r{^be valid when #regexp_field is a regexp \(/\^value\$/\)$},
146
+ one_argument: %r{^be valid when #regexp_field is a regexp \(/some regexp/\)$}
147
+ }
148
+ },
149
+ array: {
150
+ argument: { passing: [1, 2], failing: [] },
151
+ description: {
152
+ no_arguments: /^be valid when #array_field is a array \(\[42\]\)$/,
153
+ one_argument: /^be valid when #array_field is a array \(\[1, 2\]\)$/
154
+ }
155
+ },
156
+ hash: {
157
+ argument: { passing: { a: 1 }, failing: {} },
158
+ description: {
159
+ no_arguments: /^be valid when #hash_field is a hash \(\{:value=>42\}\)$/,
160
+ one_argument: /^be valid when #hash_field is a hash \({:a=>1\}\)$/
161
+ }
162
+ },
163
+ symbol: {
164
+ argument: { passing: :some_symbol, failing: :a },
165
+ description: {
166
+ no_arguments: /^be valid when #symbol_field is a symbol \(:value\)$/,
167
+ one_argument: /^be valid when #symbol_field is a symbol \(:some_symbol\)$/
168
+ }
169
+ }
170
+ }.each do |name, props|
171
+ method_name = "is_#{name}".to_sym
172
+ field_name = "#{name}_field".to_sym
173
+ not_field_name = "not_#{field_name}".to_sym
174
+
175
+ context "#is_#{name}" do
176
+ context 'with no arguments' do
177
+ let(:passing_matcher) { be_valid_when(field_name).send(method_name) }
178
+ let(:failing_matcher) { be_valid_when(not_field_name).send(method_name) }
179
+
180
+ include_examples 'returns proper results'
181
+
182
+ include_examples 'has correct description' do
183
+ let(:matcher) { passing_matcher }
184
+ let(:description) { props[:description][:no_arguments] }
185
+ end
186
+ end
187
+
188
+ context 'with one argument' do
189
+ let(:passing_matcher) do
190
+ be_valid_when(field_name).send(method_name, props[:argument][:passing])
191
+ end
192
+ let(:failing_matcher) do
193
+ be_valid_when(field_name).send(method_name, props[:argument][:failing])
194
+ end
195
+
196
+ include_examples 'returns proper results'
197
+
198
+ include_examples 'has correct description' do
199
+ let(:matcher) { passing_matcher }
200
+ let(:description) { props[:description][:one_argument] }
201
+ end
202
+
203
+ it "should fail if passed non #{name}" do
204
+ invalid_values_for(props[:treat_as] ? props[:treat_as] : name.to_sym).each do |_, value|
205
+ expect do
206
+ be_valid_when(field_name).send(method_name, value)
207
+ end.to raise_error ArgumentError
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.shared_examples 'has correct description' do
2
+ it 'has the correct description' do
3
+ expect(matcher.description).to match description
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.shared_examples 'returns proper results' do
2
+ it 'returns proper result' do
3
+ expect(passing_matcher.matches? model).to eq true
4
+ expect(passing_matcher.does_not_match? model).to eq false
5
+ expect(failing_matcher.matches? model).to eq false
6
+ expect(failing_matcher.does_not_match? model).to eq true
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.shared_examples 'takes no arguments' do |field, matcher_name|
2
+ it 'does not accept any arguments' do
3
+ expect { be_valid_when(field).send(matcher_name, nil) }.to raise_error ArgumentError
4
+ expect { be_valid_when(field).send(matcher_name, 'string') }.to raise_error ArgumentError
5
+ expect { be_valid_when(field).send(matcher_name, 42) }.to raise_error ArgumentError
6
+ end
7
+ end