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

cucumber v 1.1.0 fails when used on a rails project with model named Usage #158

Closed
jarl-dk opened this issue Oct 20, 2011 · 5 comments
Closed

Comments

@jarl-dk
Copy link
Member

jarl-dk commented Oct 20, 2011

On a rails project I use cucumber. We have a model named Usage.

When I run

cucumber -f usage

it fails because constantize returns the constanct Usage and without the constant being fully qualified, it evaluates to the one that derives from ActiveRecord. The result is

$ bundle exec cucumber -f usage
Using the default profile...
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
wrong number of arguments (3 for 2)
Error creating formatter: usage (ArgumentError)
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.1/lib/active_record/base.rb:1549:in `initialize'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:168:in `new'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:168:in `block in formatters'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:163:in `map'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:163:in `formatters'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:68:in `build_tree_walker'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/runtime.rb:42:in `run!'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/main.rb:43:in `execute!'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/lib/cucumber/cli/main.rb:20:in `execute'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.0/bin/cucumber:14:in `<top (required)>'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/bin/cucumber:19:in `load'
/home/jarl/.rvm/gems/ruby-1.9.2-p290/bin/cucumber:19:in `<main>'

One resolution is to make constantize return the fully qualified constant, I will provide a patch.

You can reproduce by creating a rails project and use cucumber-rails and create a model named Usage, then run

bundle exec cucumber -f usage
@jarl-dk
Copy link
Member Author

jarl-dk commented Oct 20, 2011

Here is a patch

diff --git a/lib/cucumber/constantize.rb b/lib/cucumber/constantize.rb
index 7917390..7b61652 100644
--- a/lib/cucumber/constantize.rb
+++ b/lib/cucumber/constantize.rb
@@ -11,7 +11,7 @@ module Cucumber
         names.each do |name|
           constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
         end
-        constant
+        eval(camel_cased_word)
       rescue NameError => e
         require underscore(camel_cased_word)
         if try < 2

@mattwynne
Copy link
Member

If this is the solution, then we could presumably delete lots more of the method: we don't need to do any processing of the camel_cased_word at all anymore, do we?

Could you please provide this as a pull request?

@jarl-dk
Copy link
Member Author

jarl-dk commented Oct 21, 2011

I know. In this patch was applied, the whole constantize method could be refactored away, replaced by eval(arg). To me it was most important to illustrate the problem and a solution. The rest of the code i constantize is doing some input argument sanity validation. Actually I would like to see a patch could turn the variable constant into the fully qualified constant name including the prefix Cucumber::Formatter:: (for built-in formatters), so basically I would like to see a better patch than the one provided by me. Anyone?

@os97673
Copy link
Member

os97673 commented Mar 5, 2013

I think that the problem has been fixed by PR #346

@os97673 os97673 closed this as completed Mar 5, 2013
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants