testing Guardfile with RSpec

15 views
Skip to first unread message

MacSig

unread,
May 7, 2015, 9:40:30 AM5/7/15
to guar...@googlegroups.com
How can I test with RSpec (3.2) that my Guardfile is correct?
I have in a simple Ruby app the following Guardfile

# require all Guard plugins

    guard
:csv_file do
      watch
(%r{^(.+)\.csv})
   
end

    guard
:xls_file do
      watch
(%r{^(.+)\.xls})
   
end

I need to make sure the correct plugin is called when a file is copied, for instance if a csv file is copied the CsvFile plugin is called while if a xls file is copied the XlsFileplugin is called.


Thanks.

MS

Cezary Baginski

unread,
May 30, 2015, 3:47:42 PM5/30/15
to guar...@googlegroups.com
A late reply, but in case it's still relevant:

1. Check out https://github.com/guard/guard/wiki/Understanding-Guard#debugging-complex-rules (for an overview of accessing the watchers/rules)

2. You can trigger changes manually with something like:

  Guard.async_queue_add(modified: files, added: [], removed: [])

But you probably want something more low-level here: 

  Runner.new.run_on_changes(*changes.values)

But, this uses global state, which you'll have to stub out.

3. There's a Dsl class which can evaluate code, though there's a bit to stub out. Check out `spec/lib/guard/dsl_spec.rb` which does this exactly

4. You probably want to stub/mock out the CsvFile and XlsFile classes before programatically triggering changes

It's important to decide whether you want to test if the guards are properly configured, or if you want to check the rules - because the Guardfile handles both (and you'll probably prefer to test them separately).

Open an issue on GH if you're interested and let me know what you need there.
Reply all
Reply to author
Forward
0 new messages