[rspec-devel] [ rspec-Patches-9598 ] Change to Object.path2class to resolve conflicts with namespaced controllers
noreply at rubyforge.org
noreply at rubyforge.org
Sun Apr 8 10:39:42 EDT 2007
Patches item #9598, was opened at 2007-03-26 20:10
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=9598&group_id=797
Category: rails plugin
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: bruno bornsztein (bborn)
Assigned to: Nobody (None)
Summary: Change to Object.path2class to resolve conflicts with namespaced controllers
Initial Comment:
The RSpec on Rails plugin adds a path2class method to Object, which is intended to get a class from a string; however the existing implementation failed when using namespaced classes, for example:
def self.path2class(klassname)
klassname.split('::').inject(Object) { |k,n| k.const_get n }
end
"TenantsController".inject(Object) { |k,n| k.const_get n }
=> TenantsController
"Admin::TenantsController".inject(Object) { |k,n| k.const_get n }
=> TenantsController
This is a problem if you have two controllers with the same name in different namespaces.
The solution uses Rails' Inflector.constantize instead:
def self.path2class(klassname)
klassname.constantize
end
"TenantsController".constantize
=> TenantsController
"Admin::TenantsController".constantize
=> Admin::TenantsController
This yields the expected result.
----------------------------------------------------------------------
>Comment By: David Chelimsky (dchelimsky)
Date: 2007-04-08 14:39
Message:
Applying this patch causes other failures when run against trunk rev 1727 (output below). Please be sure all specs are passing and resubmit.
=============================================
rake spec:plugins
1)
'Given a controller spec running in isolation mode a spec in a context without controller_name set should fail with a useful warning' FAILED
example block expected #<Spec::Expectations::ExpectationNotMetError: (?-mix:You have to declare the controller name in controller specs)> but raised #<NameError: "" is not a valid constant name!>
./vendor/plugins/rspec_on_rails/spec/rails/runner/controller_spec_spec.rb:83
2)
'Given a controller spec running in integration mode a spec in a context without controller_name set should fail with a useful warning' FAILED
example block expected #<Spec::Expectations::ExpectationNotMetError: (?-mix:You have to declare the controller name in controller specs)> but raised #<NameError: "" is not a valid constant name!>
./vendor/plugins/rspec_on_rails/spec/rails/runner/controller_spec_spec.rb:83
----------------------------------------------------------------------
Comment By: bruno bornsztein (bborn)
Date: 2007-03-26 20:12
Message:
Sorry... forgot to check the box when attaching files.
----------------------------------------------------------------------
Comment By: bruno bornsztein (bborn)
Date: 2007-03-26 20:11
Message:
Here's a spec.
----------------------------------------------------------------------
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=9598&group_id=797
More information about the rspec-devel
mailing list