我在 Mac OS 10.7.5 上使用 rvm 和 ruby 1.9.3。
我希望能够使用 Sublime Text 2 RubyTest 包来验证我的 Ruby 语法。
但是,当我尝试Tools -> RubyTest -> Verify Ruby Syntax
在任何 ruby 文件(test.rb
如下)上运行时,RubyTest 控制台中会显示以下错误:
/Users/jladieu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby:1:无效的多字节字符(US-ASCII)
我的test.rb
文件内容很简单:
class Test
def hello
puts "Hello world"
end
end
我的RubyTest.sublime_settings
文件如下:
{
"erb_verify_command": "erb -xT - {file_name} | ruby -c",
"ruby_verify_command": "ruby -c {file_name}",
"run_ruby_unit_command": "bundle exec ruby -Itest {relative_path}",
"run_single_ruby_unit_command": "bundle exec ruby -Itest {relative_path} -n '{test_name}'",
"run_cucumber_command": "zeus cucumber {relative_path} --no-color",
"run_single_cucumber_command": "zeus cucumber {relative_path}:{line_number} --no-color",
"run_rspec_command": "zeus rspec {relative_path}",
"run_single_rspec_command": "zeus rspec {relative_path}:{line_number}",
"ruby_unit_folder": "test",
"ruby_cucumber_folder": "features",
"ruby_rspec_folder": "spec",
"check_for_rbenv": false,
"check_for_rvm": true,
"ruby_use_scratch" : false,
"save_on_run": true,
"ignored_directories": [".git", "vendor", "tmp"],
"hide_panel": false,
"before_callback": "",
"after_callback": ""
}
在命令行运行以下命令可以验证我的语法:
$ ruby -c test.rb
Syntax OK
最后,我尝试了多种方法来修复 US-ASCII 问题,但均无济于事:
-ku
在 RubyTest 设置中向验证命令添加标志export RUBYOPT=-Ku
在我.bash_profile
打开 sublime 之前export LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
在打开 sublime 之前在我的 bash 个人资料中
任何人都可以使用类似的设置来让它工作吗?
注意:找到答案(见下文),但如果有人找到更好的解决方案感兴趣,谢谢!