sporkrb / spork

A DRb server for testing frameworks (RSpec / Cucumber currently) that forks before each run to ensure a clean testing state.
spork.rubyforge.org
MIT License
1.4k stars 202 forks source link

acceptance tests not loading helpers in 9.0.0.rc5 #109

Open ludicast opened 13 years ago

ludicast commented 13 years ago

In using both Steak and my own tool Saki, I get missing method errors whenever the views are loading in helper methods. This problem is also mentioned by folk on the Steak group: http://groups.google.com/group/steakrb/browse_thread/thread/bbba8b1e79d323c2 and seems to be, a reincarnation of this issue: http://groups.google.com/group/sporkgem/browse_thread/thread/631f143d2c10277d/2c71652b2e2c9f79?lnk=gst&q=helpers#2c71652b2e2c9f79

I backed out to 0.8.4 which seems to be doing the trick.

timcharper commented 13 years ago

That's odd.. the integration tests are specifically testing for this (rails_delayed_loading_workarounds.feature).

0.8.4 is not compatible with rails 3, which version of rails are you using?

ludicast commented 13 years ago

It gets odder then, Rails 3.0.5, Rspec 2.5.0, Ruby 1.9.2. Maybe I'm not exercising parts of Rails that 1.8.4 is incompatible with.

To try to be a more productive citizen I tried to run your test suite for the latest commit and am getting a slew of failures.

loading cucumber the way listed gives me: "can't convert Pathname into String"

And the RSpec tests give me: 1) Spork::Diagnoser installs it's hook and tells you when files have been loaded Failure/Error: require filename LoadError: no such file to load -- my_awesome_library_include.rb

./lib/spork/diagnoser.rb:31:in `require'

 # ./lib/spork/diagnoser.rb:31:in`require'
 # ./spec/spork/diagnoser_spec.rb:16:in `block in run_simulation'
 # ./spec/spork/diagnoser_spec.rb:12:in`chdir'
 # ./spec/spork/diagnoser_spec.rb:12:in `run_simulation'
 # ./spec/spork/diagnoser_spec.rb:23:in`block (2 levels) in <top (required)>'

2) Spork::Diagnoser excludes files outside of Dir.pwd Failure/Error: Unable to find matching line from backtrace SystemStackError: stack level too deep

./lib/spork/diagnoser.rb:93

3) Spork::Diagnoser excludes files outside of Dir.pwd but in ruby's include path Failure/Error: Unable to find matching line from backtrace SystemStackError: stack level too deep

./lib/spork/diagnoser.rb:93

4) Spork::Diagnoser expands files to their fully their fully qualified path Failure/Error: Unable to find matching line from backtrace SystemStackError: stack level too deep

./lib/spork/diagnoser.rb:93

5) Spork::Diagnoser can tell the difference between a folder in the project path and a file in an external path Failure/Error: Unable to find matching line from backtrace SystemStackError: stack level too deep

./lib/spork/diagnoser.rb:93

6) Spork::Diagnoser filters backtrace beyond the last line matching the entry point Failure/Error: Unable to find matching line from backtrace SystemStackError: stack level too deep

./lib/spork/diagnoser.rb:93

7) Spork::Diagnoser.output_results outputs the results relative to the current directory Failure/Error: Spork::Diagnoser.output_results(out) NoMethodError: undefined method `map' for "/project_path/lib/parent_file.rb:35":String

./lib/spork/diagnoser.rb:77:in`block in output_results'

 # ./lib/spork/diagnoser.rb:75:in `each'
 # ./lib/spork/diagnoser.rb:75:in`output_results'
 # ./spec/spork/diagnoser_spec.rb:99:in `block (3 levels) in <top (required)>'

8) Spork::RunStrategy::Forking returns the result of the run_tests method from the forked child Failure/Error: @run_strategy.run("test", STDOUT, STDIN).should == "tests were ran" expected: "tests were ran" got: nil (using ==)

./spec/spork/run_strategy/forking_spec.rb:13:in `block (2 levels) in <top (required)>'

9) Spork::RunStrategy::Forking aborts the current running thread when another run is started Failure/Error: @run_strategy.run("test", STDOUT, STDIN).should == true expected: true got: nil (using ==)

./spec/spork/run_strategy/forking_spec.rb:21:in `block (2 levels) in <top (required)>'

timcharper commented 13 years ago

Do you have an instance of spork running while running the test suite? That has caused problems for me... it would help if spork would refuse to run specs outside of it's working directory.

What command are you running to run the test suite? Which version of ruby? Rubygems? I usually run them with "bundle exec rspec spec/".

I've run it with ruby 1.8.7, rubygems 1.5.0 and everything passes... features and specs. :S

I've run the features with ruby 1.9.2, but not the specs... I'll give that a run

timcharper commented 13 years ago

I reproduced the failures with Ruby 1.9.2, thank you for raising those. (For some reason, they just fail when running specs, but not features… And Spork works for me in Ruby 1.9.2). Weird

timcharper commented 13 years ago

Hmm.. I was pretty sure that I just ran the features with Ruby 1.9.2… I also get an error there. Looks like I've got some work to do. Thanks, I'll get it fixed.

ludicast commented 13 years ago

Yeah, I'm using rubygems 1.3.7 and ruby 1.9.2, and I've been launching it the same way (bundle exec rspec spec). Maybe some part of my environment isn't sane but everything's pretty vanilla I believe.

timcharper commented 13 years ago

Ok... specs and features all passing with latest master. Ruby 1.9.2 / rubygems 1.8.1. They were compatibility issues with the test code and not the actual application itself :S

timcharper commented 13 years ago

Spork 0.9.0.rc6 is out with the test updates, although no application code was specifically written to address this. However, some other fixes were made and may resolve? May be worth trying.

The tests I added to confirms that this is working, so it appears to be an interaction with webrat or steak.

Maybe we'll need to add a test that tests interaction with webrat / steak. Hmm...

ludicast commented 13 years ago

Under RubyGems 1.7.2 & 1.8.1 all tests are passing except for two cucumber tests which both seem to be failing at file lookups

1) cucumber features/diagnostic_mode.feature:6 # Scenario: Running spork --diagnose And the output should contain "lib/awesome.rb" # features/steps/sandbox_steps.rb:93 expected "" to include "lib/awesome.rb" (RSpec::Expectations::ExpectationNotMetError) ./features/steps/sandbox_steps.rb:94:in /^the (error output|output) should contain "(.+)"$/' features/diagnostic_mode.feature:37:inAnd the output should contain "lib/awesome.rb"'

2) cucumber features/rails_delayed_loading_workarounds.feature:70 # Scenario: respecting custom autoload paths Then the output should contain "BOOGIE!!!" # features/steps/sandbox_steps.rb:93 expected "Exception encountered: #<LoadError: no such file to load -- app/models/non_standard/boogie>\nbacktrace:\n/usr/l

Also for 1.8.2 I'm failing at 3) cucumber features/spork_debugger.feature:6 # Scenario: Invoking the debugger via 'debugger' Then the spork window should output a line containing "count = 0" # features/steps/sandbox_steps.rb:61 expected "\n\n\n\n - Debug Session Terminated - \n\n\n" to include "count = 0"

I'd like to start writing tests for Spork & RSpec integration tests (webrat / capybara / steak etc.) but to do that I'd obviously want to first get to green with cucumber, especially where file lookups are concerned.

below is my Gemfile.lock

GEM remote: http://rubygems.org/ specs: archive-tar-minitar (0.5.2) builder (3.0.0) columnize (0.3.2) cucumber (0.10.2) builder (>= 2.1.2) diff-lcs (>= 1.1.2) gherkin (>= 2.3.5) json (>= 1.4.6) term-ansicolor (>= 1.0.5) diff-lcs (1.1.2) gherkin (2.3.7) json (>= 1.4.6) json (1.5.1) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) rake (0.8.7) rspec (2.5.0) rspec-core (~> 2.5.0) rspec-expectations (~> 2.5.0) rspec-mocks (~> 2.5.0) rspec-core (2.5.2) rspec-expectations (2.5.0) diff-lcs (~> 1.1.2) rspec-mocks (2.5.0) ruby-debug-base19 (0.11.25) columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby_core_source (>= 0.1.4) ruby-debug19 (0.11.6) columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby-debug-base19 (>= 0.11.19) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) term-ansicolor (1.0.5)

PLATFORMS ruby

DEPENDENCIES cucumber (= 0.10.2) rake rspec (= 2.5.0) ruby-debug19


As a note I'm running 1.9.2p0. I'll upgrade that and see if the cucumber tests start passing.

timcharper commented 13 years ago

Ok... this is wild. That failure DOES show that spork isn't working. Sure enough... it (Scenario: respecting custom autoload paths # features/rails_delayed_loading_workarounds.feature:70) passes on ruby 1.8.7, but fails on 1.9.2. Ugh, how weird. At least I'm able to replicate it on my side.

benhutton commented 13 years ago

Anyone have a workaround for this?

dpickett commented 13 years ago

also interested in what's happening here - super weird

kamal commented 13 years ago

This still happens for me on ruby 1.9.2p136, spork 0.9.0rc9 and webrat 0.7.3

jackkinsella commented 13 years ago

Still happens on Ruby 1.9.2p180, Capybara 1.1.1, Rails 3.0.4, Sprok 0.9.0rc9 ;-(

Metallord commented 12 years ago

This doesn't seem to fix it for me. Still getting errors of unitialized constant WhateverHelper.

Metallord commented 12 years ago

However adding ActiveSupport::Dependencies.clear at the end of the prefork block did.

joshuap commented 12 years ago

I'm having this issue as well. Any luck?

pauljamesrussell commented 12 years ago

I'm also seeing this in my app. Interestingly, it only started happening when I installed activeadmin (0.3.4), which in turn installed fastercsv (1.5.4), formtastic (1.2.4), has_scope (0.5.1), inherited_resources (1.2.2), kaminari (0.13.0), meta_search (1.1.1), polyamorous (0.5.0), and responders (0.6.4).

Just wondering if it is something in one of these gems that's causing the issue somehow?

jrust commented 12 years ago

Had this problem as well after installing devise and so far none of the suggestions or commits above have helped.

chalofa commented 12 years ago

can confirm the problem here also, I have both installed (devise and activeadmin) so not sure which one is causing the error... anyone has a workaround?

timcharper commented 12 years ago

What needs to be done here, is someone needs to write an integration test to create the failure independent of any 3rd-party gems (other than rails).

Spork-rails has an integration test that specifically tests for this, and it now passes using ruby 1.9.2. The above "Fix for issue #109. Helpers now available to request specs." may fix this specific issue, but breaks other known tested use cases, so I can't merge it.

So, here's my challenge: Somebody go clone http://github.com/sporkrb/spork-rails. Look at the cucumber features. Copy one and modify it to manifest this specific bug. Submit it as a pull request and I will create a fix.

johnf commented 12 years ago

Pretty sure this is related to ActiveAdmin and not one if it's dependencies. Will try and produce an independent test case though.

johnf commented 12 years ago

I've tracked this down a bit further but not enough to work out what is going on. Hopefully these notes might help someone else

If you are using ActiveAdmin then you add the following in routes.rb

devise_for :admin_users, ActiveAdmin::Devise.config

To break it you can even simply add

puts ActiveAdmin::Devise.config

In ActiveAdmin::Devise the lines that cause the issue are

class SessionsController < ::Devise::SessionsController include ::ActiveAdmin::Devise::Controller end

But including anything here will break it. For example

module Foo end class SessionsController < ::Devise::SessionsController include Foo end

Also causes the problem

Makes no sense to me!

cade commented 12 years ago

I had this same issue with ActiveAdmin/Spork. This resolved it for me: https://github.com/gregbell/active_admin/wiki/Use-spork

jmajonis commented 12 years ago

I've had a problem where methods in application_helper.rb were not being loaded when running Cucumber scenarios against Spork. I also use ActiveAdmin. The above made things work. I only needed to add

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

to the env.rb prefork block.

drewB commented 12 years ago

I have had the https://github.com/gregbell/active_admin/wiki/Use-spork fix in place for a while and it doesn't fix the helpers loading problem.

patrickmcelwee commented 12 years ago

I also have tried the https://github.com/gregbell/active_admin/wiki/Use-spork fix without success using guard-spork, devise, rails 3.1.6, ruby 1.9.3.

akshayrawat commented 12 years ago

Same problem exists on Rails 3.2.7 with Ruby 1.9.3, Spork 0.9.2. Helpers don't get loaded, there is also a ticket in spork-rails about this.

gravis commented 12 years ago

same issue here when trying to use Turnip (spork 0.9.2, ruby 1.9.3, rails 3.2.8)

pedrobachiega commented 12 years ago

same 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
  ...
gravis commented 12 years ago
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?

from https://github.com/sporkrb/spork/pull/140 fixed the issue for me.

pedrobachiega commented 12 years ago

@gravis thanks, but this not worked for me :/