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

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

Closed
wants to merge 1 commit into from
Closed

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

wants to merge 1 commit into from

Conversation

jackkinsella
Copy link

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

@parndt
Copy link

parndt commented Nov 8, 2011

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

@parndt
Copy link

parndt commented Nov 8, 2011

@timcharper could you merge this please?

@timcharper
Copy link
Contributor

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
Copy link

parndt commented Nov 8, 2011

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

@thirdreplicator
Copy link

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

@eavonius
Copy link

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

@timcharper
Copy link
Contributor

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.

@eavonius
Copy link

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
Copy link

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

@patrickmcelwee
Copy link

Thanks ... worked for me.

@skyriverbend
Copy link

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

@skyriverbend
Copy link

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

@skyriverbend
Copy link

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?

@jmgarnier
Copy link

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

@gingerlime
Copy link

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

@sahilm
Copy link
Contributor

sahilm commented Sep 14, 2013

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

@sahilm sahilm closed this Sep 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.