Fixed typo
[ruby_koans.git] / koans / about_symbols.rb
1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
2
3 class AboutSymbols < EdgeCase::Koan
4   def test_symbols_are_symbols
5     symbol = :ruby
6     assert_equal __, symbol.is_a?(Symbol)
7   end
8
9   def test_symbols_are_not_strings
10     symbol = :ruby
11     assert_equal __, symbol.is_a?(String)
12     assert_equal __, symbol.eql?("ruby")
13   end
14
15   def test_symbols_have_unique_identity
16     symbol1 = :identity
17     symbol2 = :identity
18     symbol3 = :something_else
19
20     assert symbol1 == __
21     assert symbol1 != __
22   end
23
24   def test_identical_symbols_are_represented_by_a_single_internal_object
25     symbol1 = :identity
26     symbol2 = :identity
27
28     assert symbol1.equal?(__)
29     assert_equal __, symbol2.object_id
30   end
31
32   def test_method_names_become_symbols
33     all_symbols = Symbol.all_symbols
34
35     assert_equal __, all_symbols.include?(:test_method_names_are_symbols)
36   end
37
38   RubyConstant = "This string is assigned to a constant."
39   def test_constants_become_symbols
40     all_symbols = Symbol.all_symbols
41
42     assert_equal true, all_symbols.include?(__)
43   end
44
45   def test_symbols_can_be_made_from_strings
46     string = "catsAndDogs"
47     assert_equal __, string.to_sym
48   end
49
50   def test_symbols_with_spaces_can_be_built
51     symbol = :"cats and dogs"
52
53     assert_equal symbol, __.to_sym
54   end
55
56   def test_interpolated_symbols_become_strings
57     symbol = :cats
58     string = "It is raining #{symbol} and dogs."
59
60     assert_equal __, string
61   end
62
63   def test_symbols_cannot_be_concatenated
64     assert_raise(__) do
65       :cats + :dogs
66     end
67   end
68 end