Rails strange error => IndexError: string not matched

匿名 (未验证) 提交于 2019-12-03 02:23:02

问题:

I've got a very strange message error. I think it's not coming from Ruby but from the unix system.

So, I have the following test file:

require File.dirname(__FILE__) + '/../test_helper'   class CatTest < ActiveSupport::TestCase     def test_truth     assert true    end end

So, nothing coming from YAML files in the Fixtures directory.

When I run the test above with the command:

$ ruby ./test/unit/cat_test.rb

I get the very strange result:

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

I can't find the meaning of the error

IndexError: string not matched

But the most strange is that yesterday, It worked!

Thank you very much for your help.

Regards

(I'm working under Ubuntu 9.04)

回答1:

This happens, for example, when you try to access a string variable as a Hash by mistake.

s = "a string" s["position"] = "an other string"  IndexError: string not matched     from (irb):5:in `[]='     from (irb):5

Additional Information



回答2:

As Simone points out the error is caused when you think you have a hash but really it a string. Its a genuine Ruby exception. I've had the exception due to a typo in my code. In your case I'm not sure of the cause but it could be something to do with a combination of Ruby / Rails versions.

You could try up/down grading Ruby or Rails to see if that fixes it.

For multiple Ruby versions I would highly recommended "RVM":http://rvm.beginrescueend.com/



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!