assert-moar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assert_moar/version.rb +1 -1
- data/lib/minitest/assertions.rb +25 -7
- data/test/lib/minitest/assertions_test.rb +22 -4
- data/test/test_helper.rb +12 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c127ad0f44d56ae95f5a6be9b7cab84235dad3b
|
4
|
+
data.tar.gz: ba1bb17eb3cdb23907a75393b1f058bb426e6a3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8993578106bcc32c2d27afe488d601a76924444dc95ba14e017d073d589bad9882be542d813dc13d42aa42f6662d9b88a5ff30804d6de8f6cff72cce12de403d
|
7
|
+
data.tar.gz: d09a311ba5283bebf24fab23f09a7fc806cdd5cb0f9977ca0835a01955be193614a5c4d3207dfa8abdacd7cca78a52419065d9f9408d7b97e345e90ae748390a
|
data/lib/assert_moar/version.rb
CHANGED
data/lib/minitest/assertions.rb
CHANGED
@@ -1,27 +1,45 @@
|
|
1
1
|
module MiniTest::Assertions
|
2
2
|
def assert_validates_presence_of(object, property)
|
3
|
-
assert_valid
|
3
|
+
assert_valid object
|
4
4
|
tmp = object.send("#{property}")
|
5
5
|
object.send("#{property}=", nil)
|
6
|
-
|
7
|
-
|
6
|
+
refute_valid object
|
7
|
+
refute_nil object.errors[property.to_sym], "Expected errors to exist for #{property}"
|
8
8
|
object.send("#{property}=", tmp)
|
9
9
|
end
|
10
10
|
|
11
11
|
def refute_validates_presence_of(object, property)
|
12
|
-
assert_valid
|
12
|
+
assert_valid object
|
13
13
|
tmp = object.send("#{property}")
|
14
14
|
object.send("#{property}=", nil)
|
15
|
-
assert_valid
|
15
|
+
assert_valid object
|
16
16
|
assert_nil object.errors[property.to_sym]
|
17
17
|
object.send("#{property}=", tmp)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
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_valid object
|
21
39
|
assert object.valid?, "Expected object to be valid"
|
22
40
|
end
|
23
41
|
|
24
|
-
def refute_valid
|
42
|
+
def refute_valid object
|
25
43
|
refute object.valid?, "Expected object to not be valid"
|
26
44
|
end
|
27
45
|
end
|
@@ -11,18 +11,18 @@ class Minitest::AssertionTest < Minitest::Test
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_assert_valid
|
14
|
-
double =
|
14
|
+
double = spy
|
15
15
|
double.property = "foo"
|
16
16
|
@tc.assert_valid double
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_refute_valid
|
20
|
-
@tc.refute_valid
|
20
|
+
@tc.refute_valid spy(:property)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_assert_validates_presence_of
|
24
24
|
@assertion_count = 3
|
25
|
-
double =
|
25
|
+
double = spy(:property)
|
26
26
|
double.property = "foo"
|
27
27
|
@tc.assert_validates_presence_of(double, :property)
|
28
28
|
assert_equal "foo", double.property
|
@@ -30,11 +30,29 @@ class Minitest::AssertionTest < Minitest::Test
|
|
30
30
|
|
31
31
|
def test_refute_validates_presence_of
|
32
32
|
@assertion_count = 3
|
33
|
-
@tc.refute_validates_presence_of(
|
33
|
+
@tc.refute_validates_presence_of(spy, :property)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_assert_validates_attachment_presence_of
|
37
|
+
@assertion_count = 3
|
38
|
+
double = spy(:property_file_name)
|
39
|
+
double.property_file_name = "foo.png"
|
40
|
+
@tc.assert_validates_attachment_presence_of(double, :property)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_refute_validates_attachment_presence_of
|
44
|
+
@assertion_count = 3
|
45
|
+
@tc.refute_validates_attachment_presence_of(spy, :property)
|
34
46
|
end
|
35
47
|
|
36
48
|
def teardown
|
37
49
|
assert_equal(@assertion_count, @tc.assertions,
|
38
50
|
"expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
|
39
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def spy(assert_valid = nil)
|
56
|
+
ActiveRecordSpy.new(assert_valid)
|
57
|
+
end
|
40
58
|
end
|
data/test/test_helper.rb
CHANGED
@@ -10,24 +10,25 @@ require 'mocha/mini_test'
|
|
10
10
|
require_relative '../lib/minitest/assertions'
|
11
11
|
require_relative '../lib/assert_moar'
|
12
12
|
|
13
|
-
class
|
14
|
-
attr_accessor :errors, :property
|
13
|
+
class ActiveRecordSpy
|
14
|
+
attr_accessor :errors, :property, :property_file_name
|
15
15
|
|
16
|
-
def initialize(assert_valid =
|
16
|
+
def initialize(assert_valid = nil)
|
17
17
|
@errors = {}
|
18
18
|
@assert_valid = assert_valid
|
19
19
|
end
|
20
20
|
|
21
|
-
def property=(value)
|
22
|
-
@property = value
|
23
|
-
@errors[:property] = value.nil? ? String.new : nil if asserts_valid?
|
24
|
-
end
|
25
|
-
|
26
21
|
def valid?
|
27
|
-
|
22
|
+
apply_errors
|
23
|
+
@errors.empty?
|
28
24
|
end
|
29
25
|
|
30
|
-
|
31
|
-
|
26
|
+
private
|
27
|
+
def apply_errors
|
28
|
+
if !@assert_valid.nil? && self.send(@assert_valid).nil?
|
29
|
+
@errors[:property] = String.new
|
30
|
+
else
|
31
|
+
@errors.delete(:property)
|
32
|
+
end
|
32
33
|
end
|
33
34
|
end
|