Search code examples
ruby-on-railsrubyrspecguard

Using guard-rspec with factory-girl-rails


I'm using factory_girl_rails as a replacement for fixtures in my Rails project. I'm also using guard-rspec to automatically run my specs. Guard is not picking up the changes I make to my factory files (e.g. spec/factories/users.rb)—I have to stop guard, then reinitialize it for it to pick up those changes.

What are some options for avoiding this manual process?


Solution

  • To add to your own answer:

    I limit what it runs, so it doesn't run too much:

    watch(%r{^spec/factories/(.+)\.rb$}) { "spec/models" }
    

    or including the relevant controller:

    watch(%r{^spec/factories/(.+)\.rb$}) { |m|
      ["spec/models/", "spec/controllers/#{m[1]}_controller_spec.rb"]
    }