assert_equal __([]), fido.instance_variables
fido.set_name("Fido")
- assert_equal __(["@name"]), fido.instance_variables
+ assert_equal __(["@name"], [:@name]), fido.instance_variables
end
def test_instance_variables_cannot_be_accessed_outside_the_class
fido = Dog2.new
fido.set_name("Fido")
- assert_equal __("Fido"), fido.instance_variable_get("@name")
+ assert_equal __("Fido"), fido.instance_variable_get("@name")
end
def test_you_can_rip_the_value_out_using_instance_eval
assert_equal __("Fido"), fido.name
end
-
+
# ------------------------------------------------------------------
class Dog5
# THINK ABOUT IT:
# Why is this so?
end
-
+
def test_different_objects_have_difference_instance_variables
fido = Dog6.new("Fido")
rover = Dog6.new("Rover")
def test_all_objects_support_to_s_and_inspect
array = [1,2,3]
- assert_equal __("123"), array.to_s
+ assert_equal __("123", "[1, 2, 3]"), array.to_s
assert_equal __("[1, 2, 3]"), array.inspect
assert_equal __("STRING"), "STRING".to_s
assert_equal __('"STRING"'), "STRING".inspect
end
-
+
end
rover = Joes::Dog.new
assert_equal __(:jims_dog), fido.identify
assert_equal __(:joes_dog), rover.identify
-
+
assert_not_equal fido.class, rover.class
assert_not_equal Jims::Dog, Joes::Dog
end
def test_bare_bones_class_names_assume_the_current_scope
assert_equal __(true), AboutScope::String == String
end
-
+
def test_nested_string_is_not_the_same_as_the_system_string
assert_equal __(false), String == "HI".class
end
end
def test_you_can_get_a_list_of_constants_for_any_class_or_module
- assert_equal __(["Dog"]), Jims.constants
+ assert_equal __(["Dog"], [:Dog]), Jims.constants
assert Object.constants.size > _n_(10)
end
end
def test_you_can_get_a_single_character_from_a_string
string = "Bacon, lettuce and tomato"
- assert_equal __(97), string[1]
+ assert_equal __(97, 'a'), string[1]
# Surprised?
end
- def test_single_characters_are_represented_by_integers
- assert_equal __(97), ?a
- assert_equal __(true), ?a == 97
+ in_ruby_version("1.8") do
+ def test_in_ruby_1_8_single_characters_are_represented_by_integers
+ assert_equal __(97, 'a'), ?a
+ assert_equal __(true, false), ?a == 97
- assert_equal __(true), ?b == (?a + 1)
+ assert_equal __(true), ?b == (?a + 1)
+ end
+ end
+
+ in_ruby_version("1.9") do
+ def test_in_ruby_1_8_single_characters_are_represented_by_strings
+ assert_equal __('a'), ?a
+ assert_equal __(false), ?a == 97
+ end
end
def test_strings_can_be_split
class FillMeInError < StandardError
end
-def __(value="FILL ME IN")
- value
+def in_ruby_version(version)
+ yield if RUBY_VERSION =~ /^#{version}/
end
-def _n_(value=999999)
- value
+def __(value="FILL ME IN", value19=:mu)
+ if RUBY_VERSION < "1.9"
+ value
+ else
+ (value19 == :mu) ? value : value19
+ end
+end
+
+def _n_(value=999999, value19=:mu)
+ if RUBY_VERSION < "1.9"
+ value
+ else
+ (value19 == :mu) ? value : value19
+ end
end
def ___(value=FillMeInError)
end
end
end
- end
+ end
class Koan
include Test::Unit::Assertions
load(arg)
else
fail "Unknown command line argument '#{arg}'"
- end
+ end
end
end
end