2011-08-04 11 views
0

1つの関数で単純なクラスをrubyに書きます。これは、文字列から空白を削除する機能です。Ruby NameErrorの問題

マイコード:

module TestString 
     class StringUtils  
     # 
     # Delete space from string 
     # 
     def remove_space str 
      space = " " 
      str.delete space 
     end 
     end 
     end 

今、私はこの機能のための簡単なテストを書くことを試みる:私は、テストを実行しようとすると

require 'teststring' 

class TestStringUtils < Test::Unit::TestCase 
    def test_remove_space 
    assert_equal("Teststring", TestString::StringUtils.new().remove_space("Test string")) 
    end 
end 

私はエラーを取得:

1) Error: 
test_remove_space(TestStringUtils): 
NameError: uninitialized constant TestStringUtils::Json 
    /home/workspace/lib/test.rb:16:in `test_remove_space' 

なぜ?何が間違っているのか教えてください。

ありがとうございます。

答えて

1

あなたのファイルにTestStringUtilsというファイルがある場合は、requireというファイルが必要です。

+0

また、コードサンプルが不完全な場合を除き、StringUtilsはJsonという名前のモジュール内にありません。 – sepp2k

+0

返事ありがとう、私はtest.rbでTestStringUtilsコードを持っています、私はtest.rbの 'test'をrequireする必要があります、私は正しく理解していますか? – 0xAX

+0

はい、ありがとう、私は、TestStringモジュール内のStringUtilsクラスを混合しました。 – 0xAX