Question

I am using rvm and ruby 1.9.3 on Mac OS 10.7.5.

I'd like to be able to use Sublime Text 2 RubyTest package to verify my Ruby syntax.

However, when I attempt to run Tools -> RubyTest -> Verify Ruby Syntax on any ruby file (test.rb below) the following error shows up in the RubyTest console:

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

My test.rb file contents is very simple:

class Test
  def hello
    puts "Hello world"
  end
end

My RubyTest.sublime_settings file is as follows:

{
  "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": ""
}

Running the following command at the command line works to validate my syntax:

$ ruby -c test.rb 
  Syntax OK

Finally, I've tried a number of of approaches to fixing the US-ASCII issue to no avail:

  • Adding -ku flag to the verify command in the RubyTest settings
  • export RUBYOPT=-Ku in my .bash_profile before opening sublime
  • export LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8in my bash profile before opening sublime

Anyone able to get this to work using a similar setup?

Note: found an answer (see below), but interested if anyone finds a better solution, thanks!

Was it helpful?

Solution

On further investigation based on feedback from Aaron and Thomas, changing the ruby_verify_command from ruby -c {file_name} to just -c {file_name} works.

The reason for this is using check_for_rvm: true causes the command that gets run to be:

$ /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)

Setting ruby_verify_command to omit ruby correctly results in the following command to be run:

$ /Users/jladieu/.rvm/bin/rvm-auto-ruby -S -c test.rb
Syntax OK
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top