Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with RSpec #198

Closed
duckinator opened this issue Aug 21, 2016 · 3 comments
Closed

Conflict with RSpec #198

duckinator opened this issue Aug 21, 2016 · 3 comments

Comments

@duckinator
Copy link

duckinator commented Aug 21, 2016

TL;DR: I'm trying to test something using Slop with RSpec, and RSpec injects a matches? method, which leads to it trying to access the Matches?Option constant, which is invalid and thus raises an exception instead of performing the normal default behavior.

Given:

I get the following error: https://travis-ci.org/how-is/how_is/jobs/153859371#L228

  1) HowIs::CLI::Parser#parse converts flags to a Hash
     Failure/Error: expect(actual).to eq({help: true})

     NameError:
       wrong constant name Matches?Option
     # ./.bundle/gems/slop-4.3.0/lib/slop.rb:34:in `const_defined?'
     # ./.bundle/gems/slop-4.3.0/lib/slop.rb:34:in `option_defined?'
     # ./.bundle/gems/slop-4.3.0/lib/slop/options.rb:91:in `respond_to_missing?'
     # ./spec/how_is/cli/parser_spec.rb:13:in `block (3 levels) in <top (required)>'

This happens because of const_defined?(string_to_open(name.to_s)) in slop.rb, line 33.

I'll look into building a testcase.

@duckinator
Copy link
Author

I believe changing Slop.option_defined? to the following would fix it:

  def self.option_defined?(name)
    const_defined?(string_to_option(name.to_s))
  rescue NameError
    # If a NameError is raised, it wasn't a valid constant name,
    # and thus couldn't have been defined.
    false
  end

@leejarvis
Copy link
Owner

Thanks for reporting @duckinator -- I dropped in your code and have released a bug fix version.

@duckinator
Copy link
Author

awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants