问题
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