Ruby Autotest with add_mapping

强颜欢笑 提交于 2020-01-05 05:10:24

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/1645346/ruby-autotest-with-add-mapping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!