2010-01-15 70 views
19

我有一个非常奇怪的消息错误。我认为它不是来自Ruby,而是来自unix系统。Rails奇怪的错误=> IndexError:字符串不匹配

所以,我有以下的测试文件:

require File.dirname(__FILE__) + '/../test_helper' 

class CatTest < ActiveSupport::TestCase 
    def test_truth 
    assert true 
    end 
end 

所以,没有从YAML文件进来的灯具目录。

当我运行上面的命令测试:

$ ruby ./test/unit/cat_test.rb 

我得到很奇怪的结果:

Loaded suite ./test/unit/cat_test 
Started 
E 
Finished in 0.011252 seconds. 

    1) Error: 
test_truth(CatTest): 
IndexError: string not matched 


1 tests, 0 assertions, 0 failures, 1 errors 

我找不到错误

IndexError: string not matched 
的意义

但最奇怪的是,昨天,它的工作!

非常感谢您的帮助。

问候

(我的Ubuntu 9.04下工作)

回答

44

出现这种情况,例如,当您尝试访问一个字符串变量作为错误的哈希值。

s = "a string" 
s["position"] = "an other string" 

IndexError: string not matched 
    from (irb):5:in `[]=' 
    from (irb):5 

Additional Information

0

正如西蒙所指出的,当你认为你有一个哈希值但实际上它的字符串错误引起的。它是一个真正的Ruby异常。由于我的代码中存在拼写错误,因此我有例外。在你的情况下,我不确定原因,但它可能与Ruby/Rails版本的组合有关。

你可以尝试向上/向下分级Ruby或Rails来查看是否修复它。

对于多个Ruby版本,我强烈推荐使用“RVM”:http://rvm.beginrescueend.com/