Ruby - ArgumentError: wrong number of arguments (given 3, expected 2) - ruby

I am new to Ruby and am attempting to run a program written long ago. I've installed Ruby 2.4.1 and the gem package (test-unit 3.4.3), but when I try to run the following command:
ruby ./run.rb test_5772.rb config_sprint210_uae.rb
Here I am passing two arguments to master ruby script (run.rb). But I am getting an error:
Uncaught exception -- ArgumentError: wrong number of arguments (given 3, expected 2)
from /usr/lib/ruby/2.4.0/optparse.rb:1631:in `permute!'
from /usr/lib/ruby/2.4.0/optparse.rb:1652:in `parse!'
from /home/sadmin/SSN_FWQA/test-framework/lib/testrunner/arguments.rb:279:in `parse'
from ./run.rb:76:in `<main>'
The same code is working fine with Ruby 1.8.7.

This is fixed now, its actually parse method issue because this API is receving arguments (argv) in a hash format but expecting an array.
After making change in this API call, issue has been resolved.

Related

unexpected keyword_rescue, expecting keyword_end (SyntaxError) [duplicate]

I have the following ruby code:
EmailTemplate.for(mailer).each do |template|
begin
print '.'
template.upload(publish)
rescue Mandrill::UnknownTemplateError
failed.push(mailer)
end
end
Rubocop corrected my code to:
EmailTemplate.for(mailer).each do |template|
print '.'
template.upload(publish)
rescue Mandrill::UnknownTemplateError
failed.push(mailer)
end
and now it returns following error:
syntax error, unexpected keyword_rescue, expecting keyword_end
How can I fix that?
Rubocop warnings was:
C: Style/RedundantBegin: Redundant begin block detected.
Ruby 2.5.0 added a feature:
rescue/else/ensure are now allowed to be used directly with do/end blocks. [Feature #12906]
But before that, it was not allowed. So syntax error will be there.
Lets do syntax test for the code in sample.rb:
[].each do |a|
# ops
rescue Exception => ex
puts ex.inspect
end
From terminal:
Ruby$ ruby -c sample.rb
sample.rb:3: syntax error, unexpected keyword_rescue
rescue Exception => ex
^
sample.rb:5: syntax error, unexpected keyword_end, expecting end-of-input
Ruby$ rvm use 2.5.1
Using /Users/aruprakshit/.rvm/gems/ruby-2.5.1
Ruby$ ruby -c sample.rb
Syntax OK
See the News. So before 2.5.0, you need to write it like:
[].each do |a|
begin
# ops
rescue => Exception
puts ex.inspect
end
end
You can configure Rubocop to select the version of Ruby you want by following Setting the target Ruby version.
Some checks are dependent on the version of the Ruby interpreter which
the inspected code must run on. For example, enforcing using Ruby 2.3+
safe navigation operator rather than try can help make your code
shorter and more consistent... unless it must run on Ruby 2.2.
If .ruby-version exists in the directory RuboCop is invoked in,
RuboCop will use the version specified by it. Otherwise, users may let
RuboCop know the oldest version of Ruby which your project supports
with:
AllCops:
TargetRubyVersion: 2.4
For some reason, Rubocop thinks you're running Ruby 2.5, not Ruby 2.4.1.
You can fix this one of two ways:
1) Create a file .ruby-version with content 2.4.1. Rubocop should pick up your Ruby version from this file.
2) Add the following to your .rubocop.yml:
AllCops:
TargetRubyVersion: 2.4

When running an application under ruby 2.3.1 using the rails server command, the following error occurs: can not modify a frozen array (RuntimeError)

I have to run an application developed in Ruby on rails. ruby 2.3.1 and rails 4.2.0
When I execute the rails server command. I get the following error:
.... config / initializers / doorkeeper.rb: 75: in <top (required)>: can not modify a frozen array (RuntimeError).
Can I explain how to succeed to no longer have this error, thank you
Info :
The "bundle install" command runs successfully.
The code around doorkeepee.rb near line 75 : Doorkeeper.configuration.token_grant_types << "password"
I'm trying to understand how RAIL_ENV works. Can you help me at the same time?

Ruby bug with fresh install (no implicit conversion of nil into String)

I updated Ruby. When I request Ruby version in CLI, it works, but when I request for the Gem version, it returns the following error:
C:/Ruby23/lib/ruby/2.3.0/rubygems/config_file.rb:90:in `join': no implicit conversion of nil into String (TypeError)
The error is found on a portable version on Windows, as well as on an installed version.
I don't know what to do to run a working version of Ruby. Does anyone already got this bug or have a clue to resolve this?
You need to somehow set the environment variable SYSTEM_CONFIG_PATH
Here's line 90 of rubygems/config_file.rb:
SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH, 'gemrc'
That fails when SYSTEM_CONFIG_PATH is nil.
Searching the exact error message "no implicit conversion of nil into String", I finally found a working solution (may not be the best).
I replace the line 90:
SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH, 'gemrc'
With:
SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH.to_s, 'gemrc'

b.javascript_dialog().exists? is not working for me in WATIR 4.0.2

When I execute the code
b.javascript_dialog().exists?
it works fine in WATIR 3.0.0 but it's throwing the following error in WATIR 4.0.2, Why it is so? Have they given any other function corresponding to "javascript_dialog()"?
hello.rb:8:in <main>': undefined methodjavascript_dialog' for # (NoMethodError)
From the changelog for v3.1.0:
Remove Browser#(javascript_)dialog. Use Browser#alert API instead.
The javascript_dialog has been replaced by alert:
b.alert.exists?

Ruby Rspec outputs literal escape characters on windows

I'm following the ruby on rails tutorial: http://railstutorial.org/chapters/static-pages#top
I'm up to using rspec. Having installed the win32console gem, it outputs gibberish in the console, i assume it is outputting the ansi colour change codes:
>rspec spec/
?[31mF?[0m?[31mF?[0m
Finished in 0.34376 seconds
?[31m2 examples, 2 failures?[0m
1) PagesController GET 'home' should be successful
Failure/Error: Unable to find C to read failed line
?[31mundefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x22294e0>?[0m
?[90m # ./spec/controllers/pages_controller_spec.rb:7:in `block (3 levels) in <top (required)>'?[0m
2) PagesController GET 'contact' should be successful
Failure/Error: Unable to find C to read failed line
?[31mundefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x2173d28>?[0m
?[90m # ./spec/controllers/pages_controller_spec.rb:14:in `block (3 levels) in <top (required)>'?[0m
Any tips how to fix this?
Ansicon works a treat!
http://adoxa.110mb.com/ansicon/index.html
Download, extract it somewhere, and do:
ansicon -i
Then close/reopen the command prompt. Sweet!
There was a bug in beta releases of RSpec 2. If you upgrade to latest you should now see colors if you have win32console installed.
See this: http://github.com/rspec/rspec-core/issuesearch?state=closed&q=color#issue/143
UPDATE: Keep an eye on this thread:
http://groups.google.com/group/rubyinstaller/browse_thread/thread/2d2a62db7281509a/?pli=1
Update:
Rspec is still very buggy with windows coloring, especially if you're trying to use it with Autotest and/or Spork.
If you are still seeing escape codes, a quick hack is to edit the following file (exact path will depend on your version of RSpec)
%RUBY_HOME%\lib\ruby\gems\1.9.1\gems\rspec-core-2.0.1\bin\rspec
And add the following line
require 'win32console'

Resources