assert-moar 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/assert_moar/assertions.rb +16 -0
- data/lib/assert_moar/version.rb +1 -1
- data/test/lib/assert_moar/assertions_test.rb +14 -0
- data/test/support/active_support/callbacks.rb +11 -0
- data/test/test_helper.rb +5 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f530f1dad82d4ffe2b1c1cdee8a186f3b0ba1eb9
|
4
|
+
data.tar.gz: 6a65ac645a2ba0b6eeb0ca449162b883e243f868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07218e00c8a3309559af3a17a8e4d2ae3627ce18d8422e0c2de3c37e542b3ed406220271c8a547906c8d23128c295948fc5c11fe2dd758c88c2d01a7db138d43
|
7
|
+
data.tar.gz: 8923bbad1292e0a4fd13a7ef6d890c62e38058c34cf66566074bde833827126c9652c69fbfd9831604a29dc6cfbfb45b3f0fa06034618ae0d20309c010a4aa08
|
data/README.md
CHANGED
@@ -39,6 +39,16 @@ module AssertMoar::Assertions
|
|
39
39
|
"#{object} validates the acceptance of #{property}"
|
40
40
|
end
|
41
41
|
|
42
|
+
def assert_validates_with_callback(object, callback)
|
43
|
+
assert has_callback_validator?(object, callback),
|
44
|
+
"#{object} does not validate with #{callback}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def refute_validates_with_callback(object, callback)
|
48
|
+
refute has_callback_validator?(object, callback),
|
49
|
+
"#{object} does not validate with #{callback}"
|
50
|
+
end
|
51
|
+
|
42
52
|
def assert_valid(object)
|
43
53
|
assert object.valid?, "Expected object to be valid"
|
44
54
|
end
|
@@ -55,4 +65,10 @@ module AssertMoar::Assertions
|
|
55
65
|
|
56
66
|
validators.any? { |v| v.is_a?(validator_class) }
|
57
67
|
end
|
68
|
+
|
69
|
+
def has_callback_validator?(object_or_class, callback)
|
70
|
+
klass = object_or_class.class
|
71
|
+
|
72
|
+
klass._validate_callbacks.any? { |v| v.filter == callback }
|
73
|
+
end
|
58
74
|
end
|
data/lib/assert_moar/version.rb
CHANGED
@@ -63,6 +63,20 @@ class AssertMoar::AssertionTest < Minitest::Test
|
|
63
63
|
@tc.refute_validates_acceptance_of(double, :property)
|
64
64
|
end
|
65
65
|
|
66
|
+
def test_assert_validates_with_callback
|
67
|
+
validator = ::ActiveSupport::Callbacks::Callback.new(:callback)
|
68
|
+
double = ActiveRecordDouble.new(error_map: { callback: validator })
|
69
|
+
|
70
|
+
@tc.assert_validates_with_callback(double, :callback)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_refute_validates_with_callback
|
74
|
+
validator = ::ActiveSupport::Callbacks::Callback.new(:callback)
|
75
|
+
double = ActiveRecordDouble.new()
|
76
|
+
|
77
|
+
@tc.refute_validates_with_callback(double, :callback)
|
78
|
+
end
|
79
|
+
|
66
80
|
def teardown
|
67
81
|
assert_equal(@assertion_count, @tc.assertions,
|
68
82
|
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
|
data/test/test_helper.rb
CHANGED
@@ -10,6 +10,7 @@ require 'mocha/mini_test'
|
|
10
10
|
require_relative '../lib/assert_moar'
|
11
11
|
require_relative 'support/active_model/validations'
|
12
12
|
require_relative 'support/active_record/validations'
|
13
|
+
require_relative 'support/active_support/callbacks'
|
13
14
|
|
14
15
|
class ActiveRecordDouble
|
15
16
|
attr_accessor :valid, :error_map
|
@@ -18,6 +19,10 @@ class ActiveRecordDouble
|
|
18
19
|
@@error_map.inject({}) { |hash, (k, v)| hash.merge(k => Array(v.new)) }
|
19
20
|
end
|
20
21
|
|
22
|
+
def self._validate_callbacks
|
23
|
+
Array(@@error_map[:callback])
|
24
|
+
end
|
25
|
+
|
21
26
|
def initialize(valid: false, error_map: {})
|
22
27
|
@valid = valid
|
23
28
|
@@error_map = error_map.to_h
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert-moar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bohn
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- test/lib/assert_moar/version_test.rb
|
201
201
|
- test/support/active_model/validations.rb
|
202
202
|
- test/support/active_record/validations.rb
|
203
|
+
- test/support/active_support/callbacks.rb
|
203
204
|
- test/test_helper.rb
|
204
205
|
homepage: https://github.com/jjbohn/assert-moar
|
205
206
|
licenses:
|
@@ -230,4 +231,5 @@ test_files:
|
|
230
231
|
- test/lib/assert_moar/version_test.rb
|
231
232
|
- test/support/active_model/validations.rb
|
232
233
|
- test/support/active_record/validations.rb
|
234
|
+
- test/support/active_support/callbacks.rb
|
233
235
|
- test/test_helper.rb
|