2

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!

jladieu
  • 149
  • 1
  • 6
  • You could try to use `{relative_path}` instead of `{file_name}`? – Thomas Klemm Apr 13 '13 at 17:51
  • Thomas, thanks for the suggestion -- I tried that out and now instead of printing anything to the RubyTest console, nothing happens at all (console doesn't even show up), so not sure that's the trick. – jladieu Apr 13 '13 at 19:06
  • Actually `{file_name}` should [work](https://github.com/maltize/sublime-text-2-ruby-tests#settings-1). You could try setting the rvm detection, but that's just a wild guess. – Thomas Klemm Apr 13 '13 at 19:19
  • I meant the `"check_for_rvm": true` setting, but you already applied it. – Thomas Klemm Apr 13 '13 at 19:55
  • Strangest thing, I was getting this error until I added bundle exec ruby which you have above. Now my tests run normally. However, when I verify syntax I now get ruby: No such file or directory -- foobar.rb (LoadError), when I add bundle exec ruby to the verify command. I think it's working but can't find the file now? – Aaron Van Bokhoven Apr 14 '13 at 02:30
  • Changing file_name to relative path in the verify_command line doesn't display anything in the test console, but in the regular console it throws: Traceback (most recent call last): File "./sublime_plugin.py", line 362, in run_ File "./run_ruby_test.py", line 315, in run File "./run_ruby_test.py", line 205, in verify_syntax_command File "./run_ruby_test.py", line 113, in KeyError: u'relative_path' – Aaron Van Bokhoven Apr 14 '13 at 02:37
  • @Aaron, thanks for the idea to use the regular console of Sublime. I checked out what was printing there, which was this: `Running /Users/jladieu/.rvm/bin/rvm-auto-ruby -S ruby -c test.rb`, it turns out when I run that from the command line I get the same error, which tells me this has nothing to do with Sublime and everything to do with rvm-auto-ruby! Will post back once I know more. – jladieu Apr 14 '13 at 16:47

1 Answers1

7

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
jladieu
  • 149
  • 1
  • 6