3
votes

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.
3
I'm facing the same issue: my helper files are not reloaded using Spork. Any more info about this issue?Joshua Muheim
@JoshuaMuheim I solved my problem, sorry for the late reply. The answer is below.mrbrdo

3 Answers

1
votes

Usually in the development environment config.cache_classes is set to true. When you're using spork you should disable this options, for more details see: ./config/environments/test.rb file.

Instead config.filter_run :focus => true try use RSpec's tags: https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/tag-option

1
votes

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.

0
votes

Spring now has documentation on how to use when developing a Rails Engine. https://github.com/rails/spring#application-root

Simply specify where to find the root of the test app:

Spring.application_root = './test/dummy'