Rails奇怪错误=> IndexError:字符串不匹配
我有一个非常奇怪的消息错误。 我认为它不是来自Ruby,而是来自unix系统。
所以,我有以下测试文件:
require File.dirname(__FILE__) + '/../test_helper' class CatTest < ActiveSupport::TestCase def test_truth assert true end end
因此,没有来自Fixtures目录中的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下工作)
例如,当您尝试错误地将字符串变量作为哈希访问时,就会发生这种情况。
s = "a string" s["position"] = "an other string" IndexError: string not matched from (irb):5:in `[]=' from (irb):5
附加信息
正如Simone所指出的那样,当你认为你有一个哈希但是真的是一个字符串时会导致错误。 它是一个真正的Ruby例外。 由于我的代码中存在拼写错误,我遇到了exception。 在你的情况下,我不确定原因,但它可能与Ruby / Rails版本的组合有关。
您可以尝试上/下评分Ruby或Rails以查看是否可以修复它。
对于多个Ruby版本,我强烈推荐“RVM”:http://rvm.beginrescueend.com/