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

rspec extensions not working with spork #278

Closed
dipnlik opened this issue Oct 1, 2013 · 5 comments
Closed

rspec extensions not working with spork #278

dipnlik opened this issue Oct 1, 2013 · 5 comments
Assignees
Milestone

Comments

@dipnlik
Copy link

dipnlik commented Oct 1, 2013

When using spork, paper_trail's rspec helpers are not being loaded. I tried to load them manually but couldn't do it.

I created a sample project that reproduces the issue at https://github.com/dipnlik/paper_trail_sandbox .

Not sure if it's a paper_trail bug or a spork bug, but #272 looks similar to this, only with zeus instead of spork (both are preloading tools that aim to run specs faster).

I'm using ruby 2.0.0p247, rails 4.0.0, paper_trail 3.0.0.beta1 and spork-rails 4.0.0 straight from github because it wouldn't work with rails 4 otherwise.

Will keep doing tests by myself, but any help will be greatly appreciated.

@batter
Copy link
Collaborator

batter commented Oct 2, 2013

Interesting, just went to the spork issues wiki, and found a link to this StackOverflow post. I'm thinking that you could do something like this:

# spec/spec_helpr.rb
require 'rubygems'
require 'spork'

Spork.prefork do
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'paper_trail/frameworks/rspec'
  ...
end

I haven't used spork before so I can't say that would work for certain. If this doesn't work, then I'm wondering if I may need to change the way the code for the frameworks gets required so that the require statements are only executed conditionally if the framework is defined.

In 3.0.0.beta1, all framework extensions get required by this one line, and then the code inside some of the optional frameworks (such as RSpec and Cucumber) actually gets defined only if the framework has been required, like so.
That works most of the time, but of libraries like spork or zeus which try to preload your environment before loading the test framework, it wouldn't work, because the test framework won't be defined when that file is required, and then since the file has already been required, it will prevent the file from being able to be required again.

If the suggested code doesn't work above, perhaps try swapping this in for the require 'paper_trail/frameworks/rspec':

load 'paper_trail/frameworks/rspec.rb' # should force a reload of the file regardless of whether it was required previously

Please let me know if either of those works and I'll try to change the code and/or the README accordingly.

@batter
Copy link
Collaborator

batter commented Oct 2, 2013

Ok, so I just cloned down the app and tried the two methods I suggested above. Looks like the load line worked, so I think I'm going to have to change the way the framework code gets required. I'll take a crack at that later today.

@ghost ghost assigned batter Oct 2, 2013
@dipnlik
Copy link
Author

dipnlik commented Oct 2, 2013

Just tried load instead of require and it's working fine, thank you!

I think your way of requiring the helpers is a smart move. If it can be improved for zeus/spork compatibility, great, but if not, I guess a note on paper_trail's readme for zeus/spork users with this solution will be very helpful.

Thanks again!

@batter batter closed this as completed in 39decb3 Oct 2, 2013
@batter
Copy link
Collaborator

batter commented Oct 2, 2013

Just pushed a 39decb3, which makes it so the require syntax should work. I've also added instructions on the README for using the helpers with Spork. 🍻

note: you'll need to clone down the master branch in order to use this syntax, so if you want to wait until the next official release you'll need to keep using the load syntax.

@dipnlik
Copy link
Author

dipnlik commented Oct 2, 2013

Awesome! 👍

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

No branches or pull requests

2 participants