Skip to content

Commit

Permalink
compatible now with Ruby 1.9 and Ruby 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
alto committed Jun 22, 2012
1 parent 15cc1cd commit 01ad3cc
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 51 deletions.
3 changes: 1 addition & 2 deletions lib/seatbelt/assert_mail.rb
Expand Up @@ -40,8 +40,7 @@ def got_mail?(mail, options={})

end
end

if Module.const_defined?(:ActionMailer)
if Object.const_defined?(:ActionMailer)
class Test::Unit::TestCase
include Seatbelt::AssertMail
end
Expand Down
40 changes: 20 additions & 20 deletions test/assert_json_old_dsl_test.rb
Expand Up @@ -9,7 +9,7 @@ class Seatbelt::AssertJsonTest < Test::Unit::TestCase
# end
# end
# def test_string_crosscheck
# assert_raises(MiniTest::Assertion) do
# assert_assertion_fails do
# assert_json '"key"' do |json|
# json.element 'wrong_key'
# end
Expand All @@ -33,14 +33,14 @@ def test_single_hash
end
end
def test_single_hash_crosscheck_for_key
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":"value"}' do |json|
json.element 'wrong_key', 'value'
end
end
end
def test_single_hash_crosscheck_for_value
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":"value"}' do |json|
json.element 'key', 'wrong_value'
end
Expand All @@ -54,7 +54,7 @@ def test_not_element
end
end
def test_not_element_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":"value"}' do |json|
json.not_element 'key'
end
Expand All @@ -76,21 +76,21 @@ def test_not_element_array
end
end
def test_array_crosscheck_order
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["value1","value2","value3"]' do |json|
json.element 'value2'
end
end
end
def test_array_crosscheck_for_first_item
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["value1","value2","value3"]' do |json|
json.element 'wrong_value1'
end
end
end
def test_array_crosscheck_for_second_item
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["value1","value2","value3"]' do |json|
json.element 'value1'
json.element 'wrong_value2'
Expand All @@ -104,12 +104,12 @@ def test_nested_arrays
end
end
def test_nested_arrays_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[[["deep","another_depp"],["second_deep"]]]' do |json|
json.element [["deep","wrong_another_depp"],["second_deep"]]
end
end
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[[["deep","another_depp"],["second_deep"]]]' do |json|
json.element [["deep","another_depp"],["wrong_second_deep"]]
end
Expand All @@ -122,21 +122,21 @@ def test_hash_with_value_array
end
end
def test_hash_with_value_array_crosscheck_wrong_key
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":["value1","value2"]}' do |json|
json.element 'wrong_key', ['value1', 'value2']
end
end
end
def test_hash_with_value_array_crosscheck_wrong_value1
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":["value1","value2"]}' do |json|
json.element 'key', ['wrong_value1', 'value2']
end
end
end
def test_hash_with_value_array_crosscheck_wrong_value2
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":["value1","value2"]}' do |json|
json.element 'key', ['value1', 'wrong_value2']
end
Expand All @@ -152,7 +152,7 @@ def test_hash_with_array_of_hashes
end
end
def test_hash_with_array_of_hashes_crosscheck_inner_key
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}' do |json|
json.element 'key' do
json.element 'wrong_inner_key1', 'value1'
Expand All @@ -161,7 +161,7 @@ def test_hash_with_array_of_hashes_crosscheck_inner_key
end
end
def test_hash_with_array_of_hashes_crosscheck_inner_value
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}' do |json|
json.element 'key' do
json.element 'inner_key1', 'wrong_value1'
Expand All @@ -184,13 +184,13 @@ def test_array_with_nested_hashes
end
end
def test_array_with_two_hashes_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[{"key1":"value1"}, {"key2":"value2"}]' do |json|
json.element 'wrong_key1', 'value1'
json.element 'key2', 'value2'
end
end
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[{"key1":"value1"}, {"key2":"value2"}]' do |json|
json.element 'key1', 'value1'
json.element 'key2', 'wrong_value2'
Expand All @@ -208,12 +208,12 @@ def test_nested_hashes
end
end
def test_nested_hashes_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"outer_key":{"key":{"inner_key":"value"}}}' do |json|
json.element 'wrong_outer_key'
end
end
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"outer_key":{"key":{"inner_key":"value"}}}' do |json|
json.element 'outer_key' do
json.element 'key' do
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_real_xws
end

def test_not_enough_elements_in_array
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["one","two"]' do |json|
json.element "one"
json.element "two"
Expand All @@ -255,7 +255,7 @@ def test_not_enough_elements_in_array
end

def test_not_enough_elements_in_hash_array
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":[{"key1":"value1"}, {"key2":"value2"}]}' do |json|
json.element 'key' do
json.element 'key1', 'value1'
Expand Down
40 changes: 20 additions & 20 deletions test/assert_json_test.rb
Expand Up @@ -9,7 +9,7 @@ class Seatbelt::AssertJsonNewDslTest < Test::Unit::TestCase
# end
# end
# def test_string_crosscheck
# assert_raises(MiniTest::Assertion) do
# assert_assertion_fails do
# assert_json '"key"' do
# has 'wrong_key'
# end
Expand Down Expand Up @@ -38,14 +38,14 @@ def test_single_hash_with_outer_variable
end
end
def test_single_hash_crosscheck_for_key
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":"value"}' do
has 'wrong_key', 'value'
end
end
end
def test_single_hash_crosscheck_for_value
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":"value"}' do
has 'key', 'wrong_value'
end
Expand All @@ -59,7 +59,7 @@ def test_has_not
end
end
def test_has_not_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":"value"}' do
has_not 'key'
end
Expand All @@ -81,21 +81,21 @@ def test_has_not_array
end
end
def test_array_crosscheck_order
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["value1","value2","value3"]' do
has 'value2'
end
end
end
def test_array_crosscheck_for_first_item
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["value1","value2","value3"]' do
has 'wrong_value1'
end
end
end
def test_array_crosscheck_for_second_item
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["value1","value2","value3"]' do
has 'value1'
has 'wrong_value2'
Expand All @@ -109,12 +109,12 @@ def test_nested_arrays
end
end
def test_nested_arrays_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[[["deep","another_depp"],["second_deep"]]]' do
has [["deep","wrong_another_depp"],["second_deep"]]
end
end
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[[["deep","another_depp"],["second_deep"]]]' do
has [["deep","another_depp"],["wrong_second_deep"]]
end
Expand All @@ -127,21 +127,21 @@ def test_hash_with_value_array
end
end
def test_hash_with_value_array_crosscheck_wrong_key
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":["value1","value2"]}' do
has 'wrong_key', ['value1', 'value2']
end
end
end
def test_hash_with_value_array_crosscheck_wrong_value1
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":["value1","value2"]}' do
has 'key', ['wrong_value1', 'value2']
end
end
end
def test_hash_with_value_array_crosscheck_wrong_value2
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":["value1","value2"]}' do
has 'key', ['value1', 'wrong_value2']
end
Expand All @@ -157,7 +157,7 @@ def test_hash_with_array_of_hashes
end
end
def test_hash_with_array_of_hashes_crosscheck_inner_key
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}' do
has 'key' do
has 'wrong_inner_key1', 'value1'
Expand All @@ -166,7 +166,7 @@ def test_hash_with_array_of_hashes_crosscheck_inner_key
end
end
def test_hash_with_array_of_hashes_crosscheck_inner_value
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}' do
has 'key' do
has 'inner_key1', 'wrong_value1'
Expand All @@ -189,13 +189,13 @@ def test_array_with_nested_hashes
end
end
def test_array_with_two_hashes_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[{"key1":"value1"}, {"key2":"value2"}]' do
has 'wrong_key1', 'value1'
has 'key2', 'value2'
end
end
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '[{"key1":"value1"}, {"key2":"value2"}]' do
has 'key1', 'value1'
has 'key2', 'wrong_value2'
Expand All @@ -213,12 +213,12 @@ def test_nested_hashes
end
end
def test_nested_hashes_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"outer_key":{"key":{"inner_key":"value"}}}' do
has 'wrong_outer_key'
end
end
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"outer_key":{"key":{"inner_key":"value"}}}' do
has 'outer_key' do
has 'key' do
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_real_xws
end

def test_not_enough_hass_in_array
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '["one","two"]' do
has "one"
has "two"
Expand All @@ -260,7 +260,7 @@ def test_not_enough_hass_in_array
end

def test_not_enough_hass_in_hash_array
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_json '{"key":[{"key1":"value1"}, {"key2":"value2"}]}' do
has 'key' do
has 'key1', 'value1'
Expand Down
18 changes: 9 additions & 9 deletions test/assert_mail_test.rb
Expand Up @@ -20,13 +20,13 @@ def test_assert_mail
def test_assert_mail_crosscheck
Mailer.test.deliver

assert_raises(MiniTest::Assertion) { assert_mail :to => 'unknown@seatbelt.co.nz' }
assert_raises(MiniTest::Assertion) { assert_mail :cc => 'unknown@seatbelt.co.nz' }
assert_raises(MiniTest::Assertion) { assert_mail :bcc => 'unknown@seatbelt.co.nz' }
assert_raises(MiniTest::Assertion) { assert_mail :from => 'unknown@seatbelt.co.nz' }
assert_raises(MiniTest::Assertion) { assert_mail :subject => 'unknown' }
assert_raises(MiniTest::Assertion) { assert_mail :body => 'unknown' }
assert_raises(MiniTest::Assertion) { assert_mail :to => 'unknown@seatbelt.co.nz', :subject => 'unknown', :body => 'unknown' }
assert_assertion_fails { assert_mail :to => 'unknown@seatbelt.co.nz' }
assert_assertion_fails { assert_mail :cc => 'unknown@seatbelt.co.nz' }
assert_assertion_fails { assert_mail :bcc => 'unknown@seatbelt.co.nz' }
assert_assertion_fails { assert_mail :from => 'unknown@seatbelt.co.nz' }
assert_assertion_fails { assert_mail :subject => 'unknown' }
assert_assertion_fails { assert_mail :body => 'unknown' }
assert_assertion_fails { assert_mail :to => 'unknown@seatbelt.co.nz', :subject => 'unknown', :body => 'unknown' }
end

def test_assert_mail_with_multiple_mails
Expand All @@ -43,7 +43,7 @@ def test_assert_mail_with_block
end
end
def test_assert_mail_with_block_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_mail :to => 'unknown@seatbelt.co.nz' do
Mailer.test.deliver
end
Expand All @@ -68,7 +68,7 @@ def test_assert_no_mail
end

def test_assert_no_mail_crosscheck
assert_raises(MiniTest::Assertion) do
assert_assertion_fails do
assert_no_mail :to => 'test@seatbelt.co.nz' do
Mailer.test.deliver
end
Expand Down

0 comments on commit 01ad3cc

Please sign in to comment.