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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcc1728ac901b97cddff74e59b689e5618f7c26e
4
- data.tar.gz: 2b72423b1105203607a90bbde92c6c53d501d3d0
3
+ metadata.gz: 1c127ad0f44d56ae95f5a6be9b7cab84235dad3b
4
+ data.tar.gz: ba1bb17eb3cdb23907a75393b1f058bb426e6a3c
5
5
  SHA512:
6
- metadata.gz: e1b90e1f8d9cf8543e3610071650b4f96ae9b325896666e1605ab4e6b752f85ddb186e2fc21f32d948d2edc29222cf6e5da76519935e4a0693451a2b1af38f96
7
- data.tar.gz: f55cfd7da6a40088247728048a45627f402235869a01b78eab2b157b88ef2e2c48d0aea37f0e8536a1db88e45e0474103ffc53d98ccb7d1041ae16412195205c
6
+ metadata.gz: 8993578106bcc32c2d27afe488d601a76924444dc95ba14e017d073d589bad9882be542d813dc13d42aa42f6662d9b88a5ff30804d6de8f6cff72cce12de403d
7
+ data.tar.gz: d09a311ba5283bebf24fab23f09a7fc806cdd5cb0f9977ca0835a01955be193614a5c4d3207dfa8abdacd7cca78a52419065d9f9408d7b97e345e90ae748390a
@@ -1,3 +1,3 @@
1
1
  module AssertMoar
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,27 +1,45 @@
1
1
  module MiniTest::Assertions
2
2
  def assert_validates_presence_of(object, property)
3
- assert_valid(object)
3
+ assert_valid object
4
4
  tmp = object.send("#{property}")
5
5
  object.send("#{property}=", nil)
6
- refute object.valid?, "Expected object not to be valid"
7
- assert object.errors[property.to_sym], "Expected errors to exist for #{property}"
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(object)
12
+ assert_valid object
13
13
  tmp = object.send("#{property}")
14
14
  object.send("#{property}=", nil)
15
- assert_valid(object)
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 assert_valid(object)
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(object)
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 = ActiveRecordBaseDouble.new
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 ActiveRecordBaseDouble.new
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 = ActiveRecordBaseDouble.new
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(ActiveRecordBaseDouble.new(false), :property)
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 ActiveRecordBaseDouble
14
- attr_accessor :errors, :property
13
+ class ActiveRecordSpy
14
+ attr_accessor :errors, :property, :property_file_name
15
15
 
16
- def initialize(assert_valid = true)
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
- !@property.nil? || !asserts_valid?
22
+ apply_errors
23
+ @errors.empty?
28
24
  end
29
25
 
30
- def asserts_valid?
31
- @assert_valid == true
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
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bohn