diff --git a/test/strongbox_test.rb b/test/strongbox_test.rb index 4809097..03ce26b 100644 --- a/test/strongbox_test.rb +++ b/test/strongbox_test.rb @@ -197,12 +197,12 @@ class StrongboxTest < Test::Unit::TestCase should 'not have an error on the secret when valid' do assert @valid.valid? - assert_nil @valid.errors.on(:secret) + assert_does_not_have_errors_on(@valid,:secret) end should 'have an error on the secret when invalid' do assert !@invalid.valid? - assert @invalid.errors.on(:secret) + assert_has_errors_on(@invalid,:secret) end end @@ -223,22 +223,22 @@ class StrongboxTest < Test::Unit::TestCase should 'not have an error on the secret when in range' do assert @valid.valid? - assert_nil @valid.errors.on(:secret) + assert_does_not_have_errors_on(@valid,:secret) end should 'not have an error on the secret when nil' do assert @valid_nil.valid? - assert_nil @valid_nil.errors.on(:secret) + assert_does_not_have_errors_on(@valid_nil,:secret) end should 'not have an error on the secret when blank' do assert @valid_blank.valid? - assert_nil @valid_blank.errors.on(:secret) + assert_does_not_have_errors_on(@valid_blank,:secret) end should 'have an error on the secret when invalid' do assert !@invalid.valid? - assert @invalid.errors.on(:secret) + assert_has_errors_on(@invalid,:secret) end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index acfacd6..4b8b5f2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,7 +4,9 @@ require 'rubygems' require 'test/unit' +require 'sqlite3' require 'active_record' +require 'logger' gem 'thoughtbot-shoulda', ">= 2.9.0" require 'shoulda' begin require 'redgreen'; rescue LoadError; end @@ -49,6 +51,16 @@ def rebuild_class options = {} end end +def assert_has_errors_on(model,attribute) + # Rails 2.X && Rails 3.X + !model.errors[attribute].empty? +end + +def assert_does_not_have_errors_on(model,attribute) + # Rails 2.X Rails 3.X + model.errors[attribute].nil? || model.errors[attribute].empty? +end + def generate_key_pair(password = nil,size = 2048) rsa_key = OpenSSL::PKey::RSA.new(size) # If no password is provided, don't encrypt the key