lib/rspec/rails/autotest.rb in rspec-autotest-1.0.0.rc1 vs lib/rspec/rails/autotest.rb in rspec-autotest-1.0.0.rc2

- old
+ new

@@ -18,67 +18,68 @@ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -$:.push(*Dir["vendor/rails/*/lib"]) +$:.push(*Dir['vendor/rails/*/lib']) require 'active_support/core_ext' require 'autotest/rspec' -class Autotest::RailsRspec < Autotest::Rspec +class Autotest + class RailsRspec < Autotest::Rspec + IGNORED_FOLDERS = %w{coverage db doc log public script tmp vendor/rails vendor/plugins vendor/gems} - def initialize - super - setup_rails_rspec_mappings - end - - def setup_rails_rspec_mappings - %w{coverage/ db/ doc/ log/ public/ script/ tmp/ vendor/rails vendor/plugins vendor/gems}.each do |exception| - add_exception(/^([\.\/]*)?#{exception}/) + def initialize + super + setup_rails_rspec_mappings end - clear_mappings + def setup_rails_rspec_mappings + IGNORED_FOLDERS.each { |exception| add_exception(/^([\.\/]*)?#{exception}/) } - add_mapping(%r%^(test|spec)/fixtures/(.*).yml$%) { |_, m| - ["spec/models/#{m[2].singularize}_spec.rb"] + files_matching(%r%^spec\/views\/#{m[2]}/.*_spec\.rb$%) - } - add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _| - filename - } - add_mapping(%r%^app/models/(.*)\.rb$%) { |_, m| - ["spec/models/#{m[1]}_spec.rb"] - } - add_mapping(%r%^app/views/(.*)$%) { |_, m| - files_matching %r%^spec/views/#{m[1]}_spec.rb$% - } - add_mapping(%r%^app/controllers/(.*)\.rb$%) { |_, m| - if m[1] == "application" - files_matching %r%^spec/controllers/.*_spec\.rb$% - else - ["spec/controllers/#{m[1]}_spec.rb"] - end - } - add_mapping(%r%^app/helpers/(.*)_helper\.rb$%) { |_, m| - if m[1] == "application" then - files_matching(%r%^spec/(views|helpers)/.*_spec\.rb$%) - else - ["spec/helpers/#{m[1]}_helper_spec.rb"] + files_matching(%r%^spec\/views\/#{m[1]}/.*_spec\.rb$%) - end - } - add_mapping(%r%^config/routes\.rb$%) { - files_matching %r%^spec/(controllers|routing|views|helpers)/.*_spec\.rb$% - } - add_mapping(%r%^config/database\.yml$%) { |_, m| - files_matching %r%^spec/models/.*_spec\.rb$% - } - add_mapping(%r%^(spec/(spec_helper|support/.*)|config/(boot|environment(s/test)?))\.rb$%) { - files_matching %r%^spec/(models|controllers|routing|views|helpers)/.*_spec\.rb$% - } - add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| - ["spec/lib/#{m[1]}_spec.rb"] - } - add_mapping(%r%^app/mailers/(.*)\.rb$%) { |_, m| - ["spec/mailers/#{m[1]}_spec.rb"] - } + clear_mappings + + add_mapping(%r{\A(test|spec)/fixtures/(.*).yml\z}) { |_, m| + ["spec/models/#{m[2].singularize}_spec.rb"] + files_matching(%r{\Aspec\/views\/#{m[2]}/.*_spec\.rb\z}) + } + add_mapping(%r{\Aspec/.*_spec\.rb\z}) { |filename, _| + filename + } + add_mapping(%r{\Aapp/models/(.*)\.rb\z}) { |_, m| + ["spec/models/#{m[1]}_spec.rb"] + } + add_mapping(%r{\Aapp/views/(.*)\z}) { |_, m| + files_matching %r{\Aspec/views/#{m[1]}_spec.rb\z} + } + add_mapping(%r{\Aapp/controllers/(.*)\.rb\z}) { |_, m| + if m[1] == 'application' + files_matching %r{\Aspec/controllers/.*_spec\.rb\z} + else + ["spec/controllers/#{m[1]}_spec.rb"] + end + } + add_mapping(%r{\Aapp/helpers/(.*)_helper\.rb\z}) { |_, m| + if m[1] == 'application' + files_matching(%r{\Aspec/(views|helpers)/.*_spec\.rb\z}) + else + ["spec/helpers/#{m[1]}_helper_spec.rb"] + files_matching(%r{\Aspec\/views\/#{m[1]}/.*_spec\.rb\z}) + end + } + add_mapping(%r{\Aconfig/routes\.rb\z}) { + files_matching %r{\Aspec/(controllers|routing|views|helpers)/.*_spec\.rb\z} + } + add_mapping(%r{\Aconfig/database\.yml\z}) { |_, m| + files_matching %r{\Aspec/models/.*_spec\.rb\z} + } + add_mapping(%r{\A(spec/(spec_helper|support/.*)|config/(boot|environment(s/test)?))\.rb\z}) { + files_matching %r{\Aspec/(models|controllers|routing|views|helpers)/.*_spec\.rb\z} + } + add_mapping(%r{\Alib/(.*)\.rb\z}) { |_, m| + ["spec/lib/#{m[1]}_spec.rb"] + } + add_mapping(%r{\Aapp/mailers/(.*)\.rb\z}) { |_, m| + ["spec/mailers/#{m[1]}_spec.rb"] + } + end end end