0

I am getting syntax error, unexpected tLABEL in below Ruby code. The error description is pointing to ':' after 'timeout'.

def self.run(*args, timeout: nil, environment: {})
  # ...
end

I have no knowledge of Ruby. I have tried few things like replacing ':' with '=' or putting nil in {} but nothing seems to work.

My ruby version is 2.1.5.

IUQ-mini:~ IUQ$ rbenv versions
system
* 2.1.5 (set by /Users/IUQ/.ruby-version)
2.1.7
2.2.3

The particular code can be found here at line #38.

Few questions over SO points that this could happen due to misplaced braces but I did not see error - again my lack of Ruby knowledge!

Please help me to understand cause of this error and How can I resolve this?

Thanks

iuq
  • 1,487
  • 1
  • 20
  • 42
  • 2
    The above code is valid in Ruby 2.x. Are you sure that you are not running Ruby 1.9? – Stefan Mar 18 '16 at 11:57
  • @Stefan - yes its 2.1.5. *rbenv versions* returns _* 2.1.5 (set by /Users/me/.rbenv/versions/.ruby-version) – iuq Mar 18 '16 at 12:15
  • How do you execute the code that is generating this error? – Stefan Mar 18 '16 at 12:18
  • 1
    I have a Java program which is executing this code indirectly through JRuby (version 1.7.24). As you could see its part of **command_runner_ng** gem which is dependency to **run_loop** gem. And they all are part of calabash-ios setup. – iuq Mar 18 '16 at 12:20
  • How does your Ruby 2.1.5 installation fit into that setup? – Stefan Mar 18 '16 at 12:40
  • Calabash is again a set of gems and they need Ruby to work I guess. – iuq Mar 18 '16 at 12:45
  • 1
    Seems like JRuby is running your code in "1.9 mode" and that your Ruby 2.1.5 installation is not used at all. Maybe someone familiar with JRuby and / or calabash-ios (I'm not) can help. – Stefan Mar 18 '16 at 13:21
  • can you give the lines how you call the method? – devanand Mar 18 '16 at 14:15
  • command_output = CommandRunner.run(['xcrun'] + args, timeout: timeout) - This is the caller code – iuq Mar 22 '16 at 13:38

2 Answers2

2

That won't work in ruby 1.9 (if in fact JRuby is limiting you to 1.9) as-is since the splat is expected to have a hash immediately following it if it's the first argument.

You can do something like this:

def self.run (environment = {}, timeout = nil, *args)
end

The only rub is you'll have to explicitly pass something (even nil) for timeout if you want to pass stuff in to be args[].

10dot
  • 111
  • 6
  • FWIW, there is ways to say JRuby to use newer Ruby spec, 1.9 is used I guess to ensure most stable environment. – Smar Mar 18 '16 at 14:19
  • Syntax error disappears but then program throws the exception **Unsupported timeout value 'timeout'. Must be a Numeric**. [Line #59](https://github.com/kamstrup/command_runner_ng/blob/master/lib/command_runner.rb) – iuq Mar 22 '16 at 12:57
  • command_output = CommandRunner.run(['xcrun'] + args, timeout: timeout) - This is the caller code – iuq Mar 22 '16 at 13:19
  • thanks @10dot. It removes the original error but sounds like patchwork since it is suggested its all happening due to JRuby. I'll try to figure it out how make JRuby to use newer Ruby. – iuq Mar 25 '16 at 14:40
0

Calabash iOS and Android require ruby >= 2.0.

The latest released version of ruby is recommended.

JRuby of any version is not supported at this time.

Travis build

If you look at the info for that build, you'll see it failed because it was running on ruby 1.9.3.

enter image description here

I believe that you have ruby 2.0 installed. I don't think you are using it.

$ rbenv versions
  system
  1.8.7-p375
  1.9.3-p484
  2.0.0-p481
  2.1.5
  2.2.2
  2.2.3
* 2.3.0 (set by /Users/moody/.rbenv/version)  <== Active ruby in this dir
  jruby-1.7.18

 $ rbenv version # Active ruby in this directory
 2.3.0

You never mentioned what version of run_loop you are using. You should update to the most recent stable release.

https://github.com/calabash/calabash-ios/wiki/Updating-your-run-loop-version

jmoody
  • 2,480
  • 1
  • 16
  • 22
  • [https://travis-ci.org/calabash/run_loop/jobs/81955466](https://travis-ci.org/calabash/run_loop/jobs/81955466). Line #178 in error log snapshot. I have three Ruby versions (2.1.5, 2.1.7, 2.2.3) installed on my system, all of them are >2 and 2.1.5 is active one following xamarin's recommendations. Thanks. – iuq Mar 22 '16 at 13:29
  • In my case it returns __* 2.1.5 (set by /Users/IUQ/.ruby-version)__. Updated the question to reflect the same. And run_loop version is 2.0.9. Any run_loop version >1.5.0 is giving this error. – iuq Mar 23 '16 at 12:01
  • I think the problem is the JRuby interface as 10dot suggests. We will not be updating the run-loop code to support ruby 1.9 syntax. I know exactly nothing about JRuby, but can you pass --2.0 as option? http://stackoverflow.com/questions/15281036/how-to-run-ruby-2-0-with-jruby-1-7 – jmoody Mar 24 '16 at 08:19