Open sliute opened 7 years ago
hi @sliute - haven't tried this with 2.4 yet - you might try bundle update ... or possibly even deleting the Gemfile.lock and seeing if a gems update will fix things ...
ah, sorry, scratch that, we don't have a Gemfile - hmmm
I replicated this in 2.4 - not immediately sure how to fix ...
Hey,
I'll try going more in-depth, but I'm a noob, so I can't guarantee anything :-)
Cheers,
On 19 January 2017 at 12:07, Sam Joseph notifications@github.com wrote:
I replicated this in 2.4 - not immediately sure how to fix ...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tansaku/rspec-sinatra/issues/2#issuecomment-273760336, or mute the thread https://github.com/notifications/unsubscribe-auth/ATbkW62P5LmZl8WUhbNejJO4MlieiTjRks5rT1HvgaJpZM4Llrlf .
Upshot is I can only confirm that gem works fine on 2.3.3 and gives parser / templater errors on 2.4.0. This is the same whether gem is built on 2.3.3 or 2.4.0.
I'm really interested in any solutions that arise from investigations, and helping further to resolve. For now I can only contribute suggestion that you limit the required ruby version of gem.
s.required_ruby_version = '<2.4.0'
to rspec-sinatra.gemspec with version = 0.2.0
I tested and this works, building gem locally, then running both on 2.3.3
rspec-sinatra init MyApp lib/app.rb
rspec-sinatra init --app MyApp lib/app.rb
I cloned locally. I added 'p' to arguments and the template actions in generators.rb. I commented out 3rd argument default below but have tested with / without and this line makes no difference to 2.3.3 and 2.4.0 results.
#p option :app, :as => :boolean, :default => false, :desc => 'Create the application files as well.'
The build ran successfully with ruby 2.3.3 and produced the same errors when I switched to ruby 2.4.0 - see "peed" output below.
Olwens-MBP:rspec-sinatra DOE$ rspec-sinatra init --app MyApp lib/app.rb
:app_class=
:app_file=
:app=
[#<Templater::ActionDescription:0x007fd22318f388 @name=:spec_helper, @options={}, @block=#<Proc:0x007fd22318f2e8@/Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/generator.rb:231>>]
[#<Templater::ActionDescription:0x007fd22318f388 @name=:spec_helper, @options={}, @block=#<Proc:0x007fd22318f2e8@/Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/generator.rb:231>>, #<Templater::ActionDescription:0x007fd22318ee60 @name=:app_file, @options={:app=>true}, @block=#<Proc:0x007fd22318ed98@/Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/generator.rb:231>>]
[#<Templater::ActionDescription:0x007fd22318f388 @name=:spec_helper, @options={}, @block=#<Proc:0x007fd22318f2e8@/Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/generator.rb:231>>, #<Templater::ActionDescription:0x007fd22318ee60 @name=:app_file, @options={:app=>true}, @block=#<Proc:0x007fd22318ed98@/Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/generator.rb:231>>, #<Templater::ActionDescription:0x007fd22318e758 @name=:rackup_file, @options={:app=>true}, @block=#<Proc:0x007fd22318e6b8@/Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/generator.rb:231>>]
/Users/DOE/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1627:in `[]=': wrong number of arguments (given 3, expected 2) (ArgumentError)
from /Users/DOE/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1627:in `permute!'
from /Users/DOE/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1648:in `parse!'
from /Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/cli/parser.rb:68:in `parse'
from /Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/cli/generator.rb:34:in `run'
from /Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/cli/manifold.rb:24:in `run'
from /Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/manifold.rb:80:in `run_cli'
from /Users/DOE/Projects/Makers_Course/rspec_sinatra_bug/rspec-sinatra/bin/rspec-sinatra:7:in `<top (required)>'
from /Users/DOE/.rvm/gems/ruby-2.4.0/bin/rspec-sinatra:22:in `load'
from /Users/DOE/.rvm/gems/ruby-2.4.0/bin/rspec-sinatra:22:in `<main>'
from /Users/DOE/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/DOE/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'
Worked perfectly with 2.3.3
Then I switched to ruby 2.4.0 and deleted gem I rebuilt locally with gemfile below and changing version in rsepc-sinatra.gemspec to 0.20.
source 'https://rubygems.org'
ruby '2.4.0'
gemspec
Successfully built RubyGem
Name: rspec-sinatra
Version: 0.2.0
File: rspec-sinatra-0.2.0.gem
It errors on 2.4.0 with original error Stefan posted
ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1627:in `[]=': wrong number of arguments (given 3, expected 2) (ArgumentError)
2.3.3 runs successfully again though build was on 2.4.0
So conclusion is something changed at 2.4.0 with interaction of Templater::Generator
The error occurs from /Users/DOE/.rvm/gems/ruby-2.4.0/gems/templater-1.0.0/lib/templater/cli/parser.rb:68:in `parse'
which is this file https://github.com/jnicklas/templater/blob/master/lib/templater/cli/parser.rb
See https://docs.ruby-lang.org/en/2.4.0/OptionParser.html#method-i-permute-21
the error occurs on
/Users/DOE/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1627:in `[]=': wrong number of arguments (given 3, expected 2) (ArgumentError)
from /Users/DOE/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1627:in `permute!'
from /Users/DOE/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/optparse.rb:1648:in `parse!'
These lines are in methods listed
# File lib/optparse.rb, line 1643
def parse!(argv = default_argv, into: nil)
if ENV.include?('POSIXLY_CORRECT')
order!(argv, into: into)
else
permute!(argv, into: into)
end
end
# File lib/optparse.rb, line 1623
def permute!(argv = default_argv, into: nil)
nonopts = []
order!(argv, into: into, &nonopts.method(:<<))
argv[0, 0] = nonopts
argv
end
Perhaps write custom module using updated option parser to cut out errant templater? http://ruby-doc.org/stdlib-2.4.0/libdoc/optparse/rdoc/OptionParser.html
thanks for looking @olwend - PRs very gratefully received :-)
Hi guys ! I just found this issue when try to found how fix the same issue :-) I found root of issue and solution.
Root of issue: Templater require "extlib" gem extlib add method "to_hash" into Array class By unknown reason Ruby call this method when processing parameters for OptionParser.parse!(argv) But to_hash is not applicable for this case
Solution: So Templater do not use to_hash method added by extlib - just remove it before call Templater functionality:
class Array remove_method :to_hash end
@dmitrys That is great - blast from the past thanks for sharing this solution. Which files would you make this change to (sorry long time since I looked at this..)
Hi, If any modules use extlib gem (like Templater gem), you should just remove to_hash from Array after load that modules and before execute OptionParser.parse!(argv)
For example in our product we use templater gem (templater use OptionParser and extlib) for generate sources etc. So I added this code in our main generator file - this code executed after load extlib (after require templater) and before we execute run_cli from templater https://github.com/rhomobile/rhodes/blob/d0b3e28e8b6b4190be574b49fe05647b9dc3ae3b/res/generators/rhogen.rb#L1605-L1612
Hi!
When running
rspec-sinatra init --app MyApp lib/app.rb
(in Ruby 2.4.0) I got the following error message:I tried messing around with the rspec-sinatra bin, but didn't get very far. The init works well in Ruby 2.2.3.
Is there something I can do to make this work in 2.4.0?
Thanks!