Restrict assert checks to .rb files.
[ruby_koans.git] / koans / about_scope.rb
1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
2
3 class AboutScope < EdgeCase::Koan
4   module Jims
5     class Dog
6       def identify
7         :jims_dog
8       end
9     end
10   end
11
12   module Joes
13     class Dog
14       def identify
15         :joes_dog
16       end
17     end
18   end
19
20   def test_dog_is_not_available_in_the_current_scope
21     assert_raise(___) do
22       fido = Dog.new
23     end
24   end
25
26   def test_you_can_reference_nested_classes_using_the_scope_operator
27     fido = Jims::Dog.new
28     rover = Joes::Dog.new
29     assert_equal __, fido.identify
30     assert_equal __, rover.identify
31
32     assert_equal __, fido.class != rover.class
33     assert_equal __, Jims::Dog != Joes::Dog
34   end
35
36   # ------------------------------------------------------------------
37
38   class String
39   end
40
41   def test_bare_bones_class_names_assume_the_current_scope
42     assert_equal __, AboutScope::String == String
43   end
44
45   def test_nested_string_is_not_the_same_as_the_system_string
46     assert_equal __, String == "HI".class
47   end
48
49   def test_use_the_prefix_scope_operator_to_force_the_global_scope
50     assert_equal __, ::String == "HI".class
51   end
52
53   # ------------------------------------------------------------------
54
55   PI = 3.1416
56
57   def test_constants_are_defined_with_an_initial_uppercase_letter
58     assert_equal __, PI
59   end
60
61   # ------------------------------------------------------------------
62
63   MyString = ::String
64
65   def test_class_names_are_just_constants
66     assert_equal __, MyString == ::String
67     assert_equal __, MyString == "HI".class
68   end
69
70   def test_constants_can_be_looked_up_explicitly
71     assert_equal __, PI == AboutScope.const_get("PI")
72     assert_equal __, MyString == AboutScope.const_get("MyString")
73   end
74
75   def test_you_can_get_a_list_of_constants_for_any_class_or_module
76     assert_equal __, Jims.constants
77     assert Object.constants.size > _n_
78   end
79 end