Search code examples
ruby-on-railsrubyrspecsporkguard

Rails engine test/dummy with Spork, Guard, RSpec?


I have a Rails gem that I am testing with RSpec. My gem's code is in lib/my_gem, and there is a test application that Rails generated for me when I created the gem, in the folder test/dummy. I have my specs in test/dummy/spec/models/task_spec.rb. I can run these specs fine with the rspec command.

Now I wanted to use Spork and Guard for my testing. I followed RailsCasts http://railscasts.com/episodes/285-spork to install spork in my test/dummy app. It does work but I have 2 issues:

  • How to make spork reload my lib/my_gem/* files? I tried putting paths like ../../lib/my_gem/... in my Guardfile, but it does not watch/reload the files.
  • For some reason, rspec is ignoring my options from spec_helper, for example the "config.filter_run :focus => true" line. I did properly put these into Spork.prefork. This setting is working when I run rspec manually with rspec spec/models/task_spec.rb, but it is being ignored when I use guard/spork.

Solution

  • I finally was able to solve the problem. The key is running the tests from the root directory and not from test/dummy. You can see my setup if you clone my gem https://github.com/mrbrdo/has_moderated I think the key was in the Guardfile (note the paths to test/dummy), Rakefile (the spec task) and in both spec_helper.rb files (one in spec/ and one in test/dummy/spec). Feel free to comment if you find something else was required.