Sha256: 7671f5d5a59c457569fd083cad65d93b4273e75f01de4db01386488a63dafaea
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
require "test_helper" require "micro_validator" class MyKlass include MicroValidator private def testing errors.add(:testing, "Something failed...") end def another errors.add(:testing, "Another failure!") end def different errors.add(:different, "It's different this time.") end def successful (5 > 1) ? true : errors.add(:comparison, "5 is less than 1!") end end module MicroValidator class MicroValidatorTest < Minitest::Test def setup @klass = MyKlass.new MyKlass.validation_methods.clear end def test_should_not_pass_validation MyKlass.validate :testing, :successful assert !@klass.valid? end def test_should_pass_validation MyKlass.validate :successful assert @klass.valid? end def test_should_return_all_errors MyKlass.validate :testing, :another, :successful, :different @klass.valid? assert_equal ({ testing: ["Something failed...", "Another failure!"], different: ["It's different this time."]} ), @klass.errors.all end def test_picking_one_error MyKlass.validate :testing, :different @klass.valid? assert_equal ["It's different this time."], @klass.errors.field(:different) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
micro_validator-0.0.2 | test/micro_validator_test.rb |