Rails 3.2.3 with spork does not recognize helper methods in cucumber tests
Asked Answered
M

3

10

I have a application that is using rails 3.2.3 and spork 1.0.0rc2. When I run my cucumber test I get:

ActionView::Template::Error: undefined local variable or method `page_title'

Where page_title is defined in my application helper. I am not sure what broke them as it was working until the last bundle update.

Anyone having the same issue?

Margoriemargot answered 18/4, 2012 at 20:50 Comment(3)
What gems were updated before the issue appeared?Sitin
Is this helper call inside a view that's used by devise? I've a similar problem and I suspect its because the view is rendered by the devise gem and somehow doesn't have the helpers.Cariole
@Cariole how did you solved it?Margoriemargot
R
5

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
Ropeway answered 20/12, 2012 at 10:5 Comment(1)
I was hoping this would fix this problem for me. I added the code to my prefork block. Now I'm getting the following error when I try to start sprok: uninitialized constant ApplicationHelper in `const_get'Goldstone
M
2

Take a look at this thread https://github.com/sporkrb/spork-rails/issues/6#issuecomment-11105681 there are two solutions for this problem

Morehouse answered 7/12, 2012 at 9:24 Comment(0)
M
1

People has been reporting something alike for rails 3.1 when using spork: https://github.com/sporkrb/spork/issues/109

Basically, they tell you to use this:

Spork.trap_method(Rails::Application::RoutesReloader, :reload!)

I use rails 3.1 but that did not solve my problems. I'm still looking for an answer.

Medicine answered 21/6, 2012 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.