Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Fix for issue #109. Helpers now available to request specs. #140

wants to merge 1 commit into from

I'm not sure if this breaks something else, all I know is that it fixes the issue for me.


lib/abstract_controller/helper.rb of actioncontroller relevant here.


This fixed issues I was having loading helpers into request specs :+1: +1


@timcharper could you merge this please?


I'm concerned about this patch. I need to get the integration tests working again so I can validate the change. The code that is deleted there was written specifically to address another issue.


It kills any methods I have in app/helpers/application_helper.rb from being available in my tests' environment.


+1 for this patch.

When doing: bundle exec rspec --drb spec

ApplicationHelper methods were not being loaded in controller specs that called "render_views." Now apps/helpers/application_helper.rb methods are available.... (opposite effect of parndt's comment).

spork (0.9.0)
rails (= 3.2.1)
rspec (2.8.0)


I need this right now. Does anyone have a workaround?


The patch introduces other bugs that are tested with the integration tests. I can't reproduce this in isolation. If you want Spork to change, you'll have to prove it's not interaction with some other gem, or distill the interaction down. I'm very sorry, but the complex nature of this problem due to the wide array of gems out there that may hook into the application loader process inclines me to take a very conservative approach. While this patch may make it better for you in this case, it makes things worse for others in known, tested cases.


That's understandable. Can someone point me to a workaround though? Currently when I try to write a request spec, it goes to render the view and this fails because the view calls helper methods and they aren't found. If there is some code I can write to make this succeed in my test, I don't care. I just need to be able to test my requests.


Thanks, this worked for me.

@eavonius: you can override the method with the original code to workaround this. The code is in the actionpack gem (this is from version 3.2.3). Here I've compressed it to one line:

require 'spork'

# Workaround for issue #109 until pull-req #140 gets merged
AbstractController::Helpers::ClassMethods.module_eval do def helper(*args, &block); modules_for_helpers(args).each {|mod| add_template_helper(mod)}; _helpers.module_eval(&block) if block_given?; end end

Spork.prefork do

Spork.each_run do

Thanks ... worked for me.


+1 thanks @kasperbn for the workaround.

I was getting one random failing test when using spork. It would only fail on the test where devise was redirecting to the log-in screen (even though the helper was still being referenced in all the other tests)...


@kasperbn - Hmm... when using your workaround rspec seems to give the following error if I try to run my specs without using spork:

uninitialized constant AbstractController (NameError)


Wrapping the workaround in if Spork.using_spork? solves the issue i was having with the workaround. So a slight modification to the workaround would be:

AbstractController::Helpers::ClassMethods.module_eval do def helper(*args, &block); modules_for_helpers(args).each {|mod| add_template_helper(mod)}; _helpers.module_eval(&block) if block_given?; end end if Spork.using_spork?

Thanks, this works for me (Rails 3.2.8 / cuke 1.2.1)


was trying the workaround provided by @kasperbn but somehow spork doesn't seem to reload my helper. Using a helper in app/helpers and accessing it in the spec as helper... Any changes to the helper go unnoticed on the next time I run a spec...


Closing old pull requests. Please send new ones if this is still an issue.

@sahilm sahilm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 0 additions and 22 deletions.
  1. +0 −22 lib/spork/app_framework/rails.rb
22 lib/spork/app_framework/rails.rb
@@ -55,28 +55,6 @@ def eager_load!
# Spork.trap_method(::AbstractController::Helpers::ClassMethods, :helper)
Spork.trap_method(::ActiveModel::Observing::ClassMethods, :instantiate_observers)
Spork.each_run { ActiveRecord::Base.establish_connection rescue nil } if Object.const_defined?(:ActiveRecord)
- AbstractController::Helpers::ClassMethods.module_eval do
- def helper(*args, &block)
- ([args].flatten - [:all]).each do |arg|
- next unless arg.is_a?(String)
- filename = arg + "_helper"
- unless ::ActiveSupport::Dependencies.search_for_file(filename)
- # this error message must raise in the format such that LoadError#path returns the filename
- raise"Missing helper file helpers/%s.rb" % filename)
- end
- end
- Spork.each_run(false) do
- modules_for_helpers(args).each do |mod|
- add_template_helper(mod)
- end
- _helpers.module_eval(&block) if block_given?
- end
- end
- end
Something went wrong with that request. Please try again.