Created
June 28, 2013 17:41
-
-
Save uxp/5886548 to your computer and use it in GitHub Desktop.
Syntax errors when using assert_equal with the suggested syntax in minitest v4.3.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
class HashEquality | |
attr_reader :options | |
def initialize(opts={}) | |
@options = opts | |
end | |
end | |
class HashEqualityTest < MiniTest::Unit::TestCase | |
def test_options_is_empty | |
hash_equality = HashEquality.new | |
# no problem here, just demonstrating I'm not stupid. | |
assert_empty hash_equality.options, "options must be empty when not given any arguments" | |
end | |
def test_options_with_arguments_is_not_empty | |
hash_equality = HashEquality.new(:foo => 'bar') | |
# no problem here, just demonstrating I'm not stupid. | |
refute_empty hash_equality.options, "options must not be empty when given arguments" | |
end | |
# assert_equal is written as assert_equal(expected, actual, message)... | |
def test_options_with_no_args_is_equal_to_empty_hash_literal | |
hash_equality = HashEquality.new | |
# raises 'syntax error, unexpected ',', expecting keyword_end' after hash literal | |
assert_equal {}, hash_equality.options, "options should be the same as an empty hash literal" | |
end | |
def test_options_with_no_args_is_equal_to_empty_hash_literal_reversed | |
hash_equality = HashEquality.new | |
# works | |
assert_equal hash_equality.options, {}, "options should be the same as an empty hash literal" | |
end | |
def test_options_with_args_is_equal_to_hash_literal_with_values | |
hash_equality = HashEquality.new(:foo => 'bar') | |
# raises 'syntax error, unexpected ',', expecting keyword_end' after hash literal | |
assert_equal {:foo => 'bar'}, hash_equality.options, "options should be the same as hash literal with values" | |
end | |
def test_options_with_args_is_equal_to_hash_literal_with_values_reversed | |
hash_equality = HashEquality.new(:foo => 'bar') | |
# works | |
assert_equal hash_equality.options, {:foo => 'bar'}, "options should be the same as hash literal with values" | |
end | |
def test_options_with_no_args_same_as_new_hash | |
hash_equality = HashEquality.new | |
# works. | |
assert_equal Hash.new, hash_equality.options, "options should be equal to a Hash.new object" | |
end | |
def test_options_with_args_same_as_new_hash_with_args | |
hash_equality = HashEquality.new(:foo => 'bar') | |
# works. | |
assert_equal Hash[:foo, 'bar'], hash_equality.options, "options should be equal to a Hash.new object with args" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment