Closed rchampourlier closed 11 years ago
Same issue when running integration/request specs within RSpec.
Any help? Thanks in advance... to anyone!
Same here. Seems any helpers coming from gems are not being loaded. All is fine when running tests directly...
ok, actually all helpers are not being available in the tests. If I disable the handling for reloading helpers (as in my branch at https://github.com/mreinsch/spork-rails), the helpers are fine.
Could this be an ordering issue where the helpers are somehow cleared again after getting loaded? I could confirm that they are being added, just not sure what happens then before the tests start.
I have the same problem. Devise helper devise_error_messages!
is not available in tests and shows error:
undefined method `devise_error_messages!'
Devise includes this helper into DeviseController with method helper DeviseHelper
(app/controllers/devise_controller.rb). spork-rails changes the helper
method in app_framework/rails.rb
, line 61. It them runs add_template_helper(mod)
which does not work for DeviseHelper.
To make the Devise helper work, I needed to add the following code to spec_helper.rb
class DeviseController
include DeviseHelper
include ActionView::Helpers::TagHelper
helper_method :devise_error_messages!
helper_method :content_tag
end
same issue as https://github.com/sporkrb/spork/issues/109
Same issue with rails 3.2.8, spork 1.0.0rc3, spork-rails 3.2.0. I spent a few time trying to find out where the things went wrong.
Given a simple gem which defines module ApplicationHelper
with method hello_world
and given an application without ApplicationHelper
in app/helpers/
, the spec which tries to render view with hello_world
method fails with undefined method hello_world
.
ApplicationHelper
anywhere, it just defines it in it's lib
directoryApplicationHelper
in app/helpers/application_helper.rb
I believe the problem is in the method helper
. The spork version will raise an exception if ::ActiveSupport::Dependencies.search_for_file(filename)
doesn't find the helper file in app/helpers
while the original one from ruby AbstractController
fallbacks to require 'application_helper'
. Since the gem's lib
directory is in $LOAD_PATH
, the module from gem is loaded and the helper
loads the helper methods.
helper
is called with ApplicationHelper
as an argumentsame problem to load helpers here...
if I include each helper, it works, but I would know some clean way to do this
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda/matchers/integrations/rspec'
include ApplicationHelper
include GraphicsHelper
...
I had the same problem. The only workaround I found was calling those helpers with
ApplicationController.helpers.<helper name>
This problem still exists. I was digging around the source, and I think it has something to do with how spork-rails overrides the AbstractController::Helpers::ClassMethods#helper(), but I'm not sure, as I wasn't able to fix it there. I did figure out that if I just use spork instead of spork-rails, everything seems to work fine. I'm wondering what the benefit of spork-rails is. It doesn't do too much; disables eager loading (not sure why), loads some Rails environment stuff, and overrides #helper(). Everything runs nice and fast with just plain spork, though.
I got same issue in spork, I tried in spork-rails gem but same issue. Is there any progress for this issue?
To fix this issue add these below lines in Spork.prefork block
full_names = Dir["#{Rails.root}/app/helpers/*.rb"]
full_names.collect do |full_name|
include Object.const_get(File.basename(full_name,'.rb').camelize)
end
@krishnasrihari this works for me! thanks!
@krishnasrihari's workaround looks like it will cover helpers defined within the application, but not helpers in gems. It could be adapted, but really, my Spork configuration shouldn't have to go find all the gems with helpers in them.
I'm inclined to agree with @fweep's hunch that it has to do with the #helper
override. The pull request for sporkrb/spork#140 fixes this problem by removing the override completely, but it was rejected because that caused other problems. (I.e., that code is there for a reason!)
The #helper
override was added in sporkrb/spork@d08fee3b64d94c43a9f6347fb89e3e8f2311f691. It looks like the goal was to ensure helpers are reloaded in each run, so you don't have to restart spork. Good idea, but is it somehow preventing helpers in gems from being loaded at all?
Oh hey, it looks like @tom-kuca's analysis has more details on this. Good job! Now all we need is a fix and an integration test.
I'm also having this problem...
Me too. +1
@krishnasrihari's fix worked for me.
The fixed that worked for me was:
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
I don't remember where I got this code, sorry for not giving any credit.
any progress here?
+1
+1
Closing old bugs. If you think this issue needs resolution please open a new issue.
@sahilm why did you close this issue? It's still not fixed, despite many people requesting it.
@sahilm can you reopen this, because it is not fixed. thanks!
Yes this is still borked.
+1
:+1:
Yes, it still doesn't work for me. I am using the following:
spork (1.0.0rc4)
spork-rails (4.0.0)
Workaround: use Zeus.
:(
I just installed Spork (+ guard) today, and I'm up against a bug that was first mentioned 2 years ago. Why closed?
I found an easy fix, just add this in your spec_helper, Spork.prefork:
Dir[Rails.root.join("spec/helpers/*.rb")].each { |f| require f }
Also remove "require 'spec_helper'" from your helpers it will cause an error if it's there
I'm running some tests with Cucumber through spork with spork-rails 3.2.0 and spork 1.0.0rc2 and I cannot get my helper methods to be loaded.
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
3.0.12
Everything is fine when:
I'm using many gems (Devise, FactoryGirl, Mongoid - also using ActiveRecord), but not ActiveAdmin. I say this because this issue is like the issue #109 on spork. Nothing from this issue could help me, and now that
spork-rails
has been extracted, it seemed to me the issue belonged here.Here is a gist of my configuration. For now, I will be running my features without Spork...