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

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet

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

parndt commented Nov 8, 2011

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

parndt commented Nov 8, 2011

@timcharper could you merge this please?

Owner

timcharper commented Nov 8, 2011

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.

parndt commented Nov 8, 2011

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).

FYI:
spork (0.9.0)
rails (= 3.2.1)
ruby-1.9.2-p290
rspec (2.8.0)

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

Owner

timcharper commented Apr 26, 2012

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.

kasperbn commented Jun 8, 2012

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
   ...
end

Spork.each_run do
   ...
end

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...

Contributor

sahilm commented Sep 14, 2013

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

sahilm closed this Sep 14, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment