tags:

views:

324

answers:

1

I am trying to add a hook in Autotest to trigger tests when javascript files are changed.

Below the is the .autotest file I am using. The syntax seems to be correct, but nothing is happening when a javascript file is updated.

The first hook works fine, the second does not.


Autotest.add_hook :initialize do |at|
  at.add_mapping(%r%^spec/(selenium)/.*rb$%) { |filename, _|
    filename
  }

  at.add_mapping(%r%^public/(javascripts)/.*js$%) do |f, _|
    at.files_matching %r%^spec/(selenium)/.*rb$%
  end
end
A: 

The above code works, however the the Rspec Rails discovery.rb file adds an exception to ignore the public directory.

In the above autotest file the exception for public/ needs to be removed.

 at.remove_exception "public/"

Then add whatever files or directories in public to be ignored:

 %w{stylesheets images assets}.each {|exception|at.add_exception(exception)}

What I ended up with is:


Autotest.add_hook :initialize do |at|

  at.add_mapping(%r%^spec/(selenium)/.*rb$%) { |filename, _|
    filename
  }

  at.remove_exception "public/"
  %w{.git public/stylesheets public/images public/assets}.each {|exception|at.add_exception(exception)}

  at.add_mapping(%r%^public/(javascripts)/.*js$%, true) do |f, _|
    (at.files_matching %r%^spec/(selenium)/.*rb$% )
  end
end
The Who