assert-moar 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assert-moar.gemspec +1 -0
- data/lib/assert_moar.rb +1 -0
- data/lib/assert_moar/assertions.rb +38 -0
- data/lib/assert_moar/version.rb +1 -1
- data/test/lib/assert_moar/assertions_test.rb +48 -0
- data/test/support/active_model/validations.rb +5 -0
- data/test/support/active_record/validations.rb +5 -0
- data/test/test_helper.rb +11 -16
- metadata +23 -5
- data/lib/minitest/assertions.rb +0 -59
- data/test/lib/minitest/assertions_test.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e84a3b9014385250895e77106131c496e61c636
|
4
|
+
data.tar.gz: 84c529c012b077a7575193e5f06b1458dc2ade81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a8eaa0eb6c40bc4c02cc0593808a193f893cb46368a0276a0c2ebfdc1e2c760985bd7101cddd83b1588a3db7ea08d1f3421738fcee63e2014926b52d4d4f40c
|
7
|
+
data.tar.gz: ffa217da9d619ab9bbdb4e8afa786c038370f49690be4867cd9165c0e562110f01a11ddc78bf5b9c54b845c8e059d7fe0cecff50fe6d084c1a6b66cf42fffe75
|
data/assert-moar.gemspec
CHANGED
data/lib/assert_moar.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
module AssertMoar::Assertions
|
2
|
+
def assert_validates_presence_of(object, property)
|
3
|
+
assert has_validator?(object, property, ::ActiveModel::Validations::PresenceValidator),
|
4
|
+
"#{object} does not validate the presence of #{property}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def refute_validates_presence_of(object, property)
|
8
|
+
refute has_validator?(object, property, ::ActiveModel::Validations::PresenceValidator),
|
9
|
+
"#{object} validates presence of #{property}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_validates_uniqueness_of(object, property)
|
13
|
+
assert has_validator?(object, property, ::ActiveRecord::Validations::UniquenessValidator),
|
14
|
+
"#{object} does not validate the presence of #{property}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def refute_validates_uniqueness_of(object, property)
|
18
|
+
refute has_validator?(object, property, ::ActiveRecord::Validations::UniquenessValidator),
|
19
|
+
"#{object} validates presence of #{property}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_valid(object)
|
23
|
+
assert object.valid?, "Expected object to be valid"
|
24
|
+
end
|
25
|
+
|
26
|
+
def refute_valid object
|
27
|
+
refute object.valid?, "Expected object to not be valid"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def has_validator?(object_or_class, property, validator_class)
|
32
|
+
klass = object_or_class.class
|
33
|
+
property = property.to_sym
|
34
|
+
validators = Array(klass._validators[property])
|
35
|
+
|
36
|
+
validators.any? { |v| v.is_a?(validator_class) }
|
37
|
+
end
|
38
|
+
end
|
data/lib/assert_moar/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class AssertMoar::AssertionTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
|
7
|
+
Minitest::Test.reset
|
8
|
+
|
9
|
+
@tc = Minitest::Test.new('foo')
|
10
|
+
@tc.send(:extend, AssertMoar::Assertions)
|
11
|
+
@assertion_count = 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_assert_valid
|
15
|
+
@tc.assert_valid ActiveRecordDouble.new(valid: true)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_refute_valid
|
19
|
+
@tc.refute_valid ActiveRecordDouble.new(valid: false)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_assert_validates_presence_of
|
23
|
+
validator = ::ActiveModel::Validations::PresenceValidator
|
24
|
+
double = ActiveRecordDouble.new(error_map: { property: validator })
|
25
|
+
@tc.assert_validates_presence_of(double, :property)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_refute_validates_presence_of
|
29
|
+
double = ActiveRecordDouble.new()
|
30
|
+
@tc.refute_validates_presence_of(double, :property)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_assert_uniqueness_of
|
34
|
+
validator = ::ActiveRecord::Validations::UniquenessValidator
|
35
|
+
double = ActiveRecordDouble.new(error_map: { property: validator })
|
36
|
+
@tc.assert_validates_uniqueness_of(double, :property)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_refute_uniqueness_of
|
40
|
+
double = ActiveRecordDouble.new()
|
41
|
+
@tc.refute_validates_uniqueness_of(double, :property)
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
assert_equal(@assertion_count, @tc.assertions,
|
46
|
+
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
|
47
|
+
end
|
48
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -7,28 +7,23 @@ Coveralls.wear!
|
|
7
7
|
|
8
8
|
require 'minitest/autorun'
|
9
9
|
require 'mocha/mini_test'
|
10
|
-
require_relative '../lib/minitest/assertions'
|
11
10
|
require_relative '../lib/assert_moar'
|
11
|
+
require_relative 'support/active_model/validations'
|
12
|
+
require_relative 'support/active_record/validations'
|
12
13
|
|
13
|
-
class
|
14
|
-
attr_accessor :
|
14
|
+
class ActiveRecordDouble
|
15
|
+
attr_accessor :valid, :error_map
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
@assert_valid = assert_valid
|
17
|
+
def self._validators
|
18
|
+
@@error_map.inject({}) { |hash, (k, v)| hash.merge(k => Array(v.new)) }
|
19
19
|
end
|
20
20
|
|
21
|
-
def valid
|
22
|
-
|
23
|
-
|
21
|
+
def initialize(valid: false, error_map: {})
|
22
|
+
@valid = valid
|
23
|
+
@@error_map = error_map.to_h
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
if !@assert_valid.nil? && self.send(@assert_valid).nil?
|
29
|
-
@errors[:property] = String.new
|
30
|
-
else
|
31
|
-
@errors.delete(:property)
|
32
|
-
end
|
26
|
+
def valid?
|
27
|
+
@valid == true
|
33
28
|
end
|
34
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bohn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: awesome_print
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: Extra assertions for minitest
|
168
182
|
email:
|
169
183
|
- jjbohn@gmail.com
|
@@ -180,10 +194,12 @@ files:
|
|
180
194
|
- Rakefile
|
181
195
|
- assert-moar.gemspec
|
182
196
|
- lib/assert_moar.rb
|
197
|
+
- lib/assert_moar/assertions.rb
|
183
198
|
- lib/assert_moar/version.rb
|
184
|
-
- lib/
|
199
|
+
- test/lib/assert_moar/assertions_test.rb
|
185
200
|
- test/lib/assert_moar/version_test.rb
|
186
|
-
- test/
|
201
|
+
- test/support/active_model/validations.rb
|
202
|
+
- test/support/active_record/validations.rb
|
187
203
|
- test/test_helper.rb
|
188
204
|
homepage: https://github.com/jjbohn/assert-moar
|
189
205
|
licenses:
|
@@ -210,6 +226,8 @@ signing_key:
|
|
210
226
|
specification_version: 4
|
211
227
|
summary: Extra assertions for minitest
|
212
228
|
test_files:
|
229
|
+
- test/lib/assert_moar/assertions_test.rb
|
213
230
|
- test/lib/assert_moar/version_test.rb
|
214
|
-
- test/
|
231
|
+
- test/support/active_model/validations.rb
|
232
|
+
- test/support/active_record/validations.rb
|
215
233
|
- test/test_helper.rb
|
data/lib/minitest/assertions.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module MiniTest::Assertions
|
2
|
-
def assert_validates_presence_of(object, property)
|
3
|
-
assert_valid object
|
4
|
-
tmp = object.send("#{property}")
|
5
|
-
object.send("#{property}=", nil)
|
6
|
-
refute_valid object
|
7
|
-
refute_nil object.errors[property.to_sym], "Expected errors to exist for #{property}"
|
8
|
-
object.send("#{property}=", tmp)
|
9
|
-
end
|
10
|
-
|
11
|
-
def refute_validates_presence_of(object, property)
|
12
|
-
assert_valid object
|
13
|
-
tmp = object.send("#{property}")
|
14
|
-
object.send("#{property}=", nil)
|
15
|
-
assert_valid object
|
16
|
-
assert_nil object.errors[property.to_sym]
|
17
|
-
object.send("#{property}=", tmp)
|
18
|
-
end
|
19
|
-
|
20
|
-
def assert_validates_attachment_presence_of(object, property)
|
21
|
-
assert_valid object
|
22
|
-
tmp = object.send("#{property}_file_name")
|
23
|
-
object.send("#{property}_file_name=", nil)
|
24
|
-
refute_valid object
|
25
|
-
refute_nil object.errors[property.to_sym], "Expected errors to exist for #{property}"
|
26
|
-
object.send("#{property}_file_name=", tmp)
|
27
|
-
end
|
28
|
-
|
29
|
-
def refute_validates_attachment_presence_of(object, property)
|
30
|
-
assert_valid object
|
31
|
-
tmp = object.send("#{property}_file_name")
|
32
|
-
object.send("#{property}_file_name=", nil)
|
33
|
-
assert_valid object
|
34
|
-
assert_nil object.errors[property.to_sym]
|
35
|
-
object.send("#{property}_file_name=", tmp)
|
36
|
-
end
|
37
|
-
|
38
|
-
def assert_validates_uniqueness_of(object, property)
|
39
|
-
assert_valid object
|
40
|
-
object2 = object.clone
|
41
|
-
refute object2.valid?, "Expected object not to be valid"
|
42
|
-
refute_nil object2.errors[property.to_sym], "Expected errors to exist for #{property}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def refute_validates_uniqueness_of(object, property)
|
46
|
-
assert_valid object
|
47
|
-
object2 = object.clone
|
48
|
-
assert_valid object2
|
49
|
-
assert_nil object2.errors[property.to_sym]
|
50
|
-
end
|
51
|
-
|
52
|
-
def assert_valid(object)
|
53
|
-
assert object.valid?, "Expected object to be valid"
|
54
|
-
end
|
55
|
-
|
56
|
-
def refute_valid object
|
57
|
-
refute object.valid?, "Expected object to not be valid"
|
58
|
-
end
|
59
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative '../../test_helper'
|
2
|
-
|
3
|
-
class Minitest::AssertionTest < Minitest::Test
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
|
7
|
-
Minitest::Test.reset
|
8
|
-
|
9
|
-
@tc = Minitest::Test.new('foo')
|
10
|
-
@assertion_count = 1
|
11
|
-
end
|
12
|
-
|
13
|
-
def invalid_clone(object)
|
14
|
-
clone = object.class.new(:property)
|
15
|
-
clone.property = nil
|
16
|
-
clone
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_assert_valid
|
20
|
-
double = spy
|
21
|
-
double.property = "foo"
|
22
|
-
@tc.assert_valid double
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_refute_valid
|
26
|
-
@tc.refute_valid spy(:property)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_assert_validates_presence_of
|
30
|
-
@assertion_count = 3
|
31
|
-
double = spy(:property)
|
32
|
-
double.property = "foo"
|
33
|
-
@tc.assert_validates_presence_of(double, :property)
|
34
|
-
assert_equal "foo", double.property
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_refute_validates_presence_of
|
38
|
-
@assertion_count = 3
|
39
|
-
@tc.refute_validates_presence_of(spy, :property)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_assert_validates_attachment_presence_of
|
43
|
-
@assertion_count = 3
|
44
|
-
double = spy(:property_file_name)
|
45
|
-
double.property_file_name = "foo.png"
|
46
|
-
@tc.assert_validates_attachment_presence_of(double, :property)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_refute_validates_attachment_presence_of
|
50
|
-
@assertion_count = 3
|
51
|
-
@tc.refute_validates_attachment_presence_of(spy, :property)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_assert_uniqueness_of
|
55
|
-
@assertion_count = 3
|
56
|
-
double = spy
|
57
|
-
double.property = "foo"
|
58
|
-
double.stub(:clone, invalid_clone(double)) do
|
59
|
-
@tc.assert_validates_uniqueness_of(double, :property)
|
60
|
-
end
|
61
|
-
assert_equal "foo", double.property
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_refute_uniqueness_of
|
65
|
-
@assertion_count = 3
|
66
|
-
@tc.refute_validates_uniqueness_of(spy(nil), :property)
|
67
|
-
end
|
68
|
-
|
69
|
-
def teardown
|
70
|
-
assert_equal(@assertion_count, @tc.assertions,
|
71
|
-
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def spy(assert_valid = nil)
|
77
|
-
ActiveRecordSpy.new(assert_valid)
|
78
|
-
end
|
79
|
-
end
|