[rspec-devel] Aliasing view helpers...

Mark Van Holstyn mvanholstyn at gmail.com
Mon Nov 12 15:54:52 EST 2007


I have one application which aliases some view helpers. The code works fine,
but the specs fail with this error...

~/application/vendor/rails/activesupport/lib/active_support/core_ext/module/aliasing.rb:31:in
`alias_method': undefined method `expand_javascript_sources' for class
`Spec::Rails::DSL::HelperExample' (NameError)
    from
~/application/vendor/rails/activesupport/lib/active_support/core_ext/module/aliasing.rb:31:in
`alias_method_chain'
    from
~/application/vendor/plugins/dhtml_calendar/lib/helpers/calendar.rb:59:in
`included'
    from
~/application/vendor/plugins/dhtml_calendar/lib/helpers/calendar.rb:58:in
`class_eval'
    from
~/application/vendor/plugins/dhtml_calendar/lib/helpers/calendar.rb:58:in
`included'
    from
~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:37:in
`include'
    from
~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:37
    from
~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:36:in
`each'
    from
~/application/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/helper_example.rb:36
     ... 51 levels...
    from
~/application/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:13:in
`load_files'
    from ~/application/vendor/plugins/rspec/lib/spec/runner/options.rb:73:in
`run_examples'
    from
~/application/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in
`run'
    from ~/application/vendor/plugins/rspec/bin/spec:3

Looking at the code, I notice this:

ActionView::Base.included_modules.each do |mod|
  include mod if mod.parents.include?(ActionView::Helpers)
end

The problem is that "included_modules" returns the included modules in the
reverse order that they were included.

>> ActionView::Base.included_modules
=> [#<Module:0x192cca4>, ActionController::Routing::Helpers,
ActionController::PolymorphicRoutes, WillPaginate::ViewHelpers,
FileColumnHelper, ActionView::Helpers::DhtmlCalendarHelper,
ActionView::Helpers::UrlHelper, ActionView::Helpers::TextHelper,
ActionView::Helpers::TagHelper, ActionView::Helpers::ScriptaculousHelper,
ActionView::Helpers::SanitizeHelper, ActionView::Helpers::RecordTagHelper,
ActionView::Helpers::RecordIdentificationHelper,
ActionView::Helpers::NumberHelper, ActionView::Helpers::JavaScriptHelper,
ActionView::Helpers::PrototypeHelper, ActionView::Helpers::FormTagHelper,
ActionView::Helpers::FormOptionsHelper, ActionView::Helpers::FormHelper,
ActionView::Helpers::DebugHelper, ActionView::Helpers::DateHelper,
ActionView::Helpers::CaptureHelper, ActionView::Helpers::CacheHelper,
ActionView::Helpers::BenchmarkHelper, ActionView::Helpers::AtomFeedHelper,
ActionView::Helpers::AssetTagHelper,
ActionView::Helpers::ActiveRecordHelper, ActionView::Partials,
ActionView::Base::CompiledTemplates, ERB::Util, InstanceExecMethods,
Base64::Deprecated, Base64, PP::ObjectMixin, Kernel]

My module is now included BEFORE any of the modules provided by rails, so
the alias call fails. I changed the first line of code to reverse the array
returned from included_modules so that they are included in the proper
order, and this did not cause any problems on my application.

ActionView::Base.included_modules.*reverse*.each do |mod|

Thoughts?

Mark

-- 
Mark Van Holstyn, Partner / Software Developer
mvanholstyn at mutuallyhuman.com, (616) 706-6842
Mutually Human Software, http://mutuallyhuman.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20071112/243f0150/attachment.html 


More information about the rspec-devel mailing list