how to tell autotest to correctly track changes in app source?

妖精的绣舞 提交于 2019-12-11 11:49:14

问题


I want to get autotest to run Steak acceptance tests whenever one of my rails app's relevant files is changed. After studying Rspec's and Cucumber's own autotest configs, I'm trying the following mappings:


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

at.add_mapping(%r%^app/(models|controllers|helpers|lib)/.rb$%) { at.files_matching %r%^spec/acceptance/._spec.rb$% }

at.add_mapping(%r%^app/views/(.*)/.rb$%) { at.files_matching %r%^spec/acceptance/._spec.rb$% } end

the first one works: whenever a Steak spec is changed, it gets run again.

but the second and third don't. changing any source files under the /app subdirectories just gets ignored.

what's the correct way to get these mappings to work?

thanks Oliver


回答1:


I just changed my .autotest file to add:

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

  at.add_mapping(%r%^app/(models|controllers|helpers|lib)/.*rb$%, true) {
    at.files_matching %r%^spec/acceptance/.*_spec.rb$%
  }

  at.add_mapping(%r%^app/views/(.*)$%, true) {
    at.files_matching %r%^spec/acceptance/.*_spec.rb$%
  }
end

And this is working but I don't know the collateral effects of invoking acceptance tests before others (the true flag on add_mapping)




回答2:


For RSpec 1.3:

I had to use the :post_initialize hook because the built-in RSpec support starts by clearing all existing mappings. So it was clearing these out and then adding the default RSpec mappings. But using the :post_initialize hook (instead of :initialize on the first line) fixed it.

I also had to put all this in autotest/discover.rb instead of .autotest.



来源:https://stackoverflow.com/questions/2975006/how-to-tell-autotest-to-correctly-track-changes-in-app-source

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