2

我在 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 个人资料中

任何人都可以使用类似的设置来让它工作吗?

注意:找到答案(见下文),但如果有人找到更好的解决方案感兴趣,谢谢!

4

1 回答 1

7

根据 Aaron 和 Thomas 的反馈进行进一步调查,将ruby_verify_commandfrom更改ruby -c {file_name}为 just-c {file_name}有效。

这样做的原因是使用check_for_rvm: true导致运行的命令是:

$ /Users/jladieu/.rvm/bin/rvm-auto-ruby ruby -c test.rb
/Users/jladieu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby:1: invalid multibyte char (US-ASCII)

设置ruby_verify_command为正确省略ruby会导致运行以下命令:

$ /Users/jladieu/.rvm/bin/rvm-auto-ruby -S -c test.rb
Syntax OK
于 2013-04-14T16:58:13.040 回答