Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved setup of mappings to Autotest subclass

  • Loading branch information...
commit 93b50e4ecb9dd6697b8f9c9471e009c9bf2e25e3 1 parent 2ddb077
@zargony zargony authored dchelimsky committed
Showing with 52 additions and 47 deletions.
  1. +52 −47 lib/autotest/rails_rspec2.rb
View
99 lib/autotest/rails_rspec2.rb
@@ -25,55 +25,60 @@
require 'active_support/core_ext'
require 'autotest/rspec2'
-Autotest.add_hook :initialize do |at|
- %w{config/ coverage/ db/ doc/ log/ public/ script/ tmp/ vendor/rails vendor/plugins vendor/gems}.each do |exception|
- at.add_exception("^#{exception}")
- end
+class Autotest::RailsRspec2 < Autotest::Rspec2
- at.clear_mappings
+ def initialize
+ super
+ setup_rails_rspec2_mappings
+ end
- at.add_mapping(%r%^(test|spec)/fixtures/(.*).yml$%) { |_, m|
- ["spec/models/#{m[2].singularize}_spec.rb"] + at.files_matching(%r%^spec\/views\/#{m[2]}/.*_spec\.rb$%)
- }
- at.add_mapping(%r%^spec/(models|controllers|routing|views|helpers|mailers|lib)/.*rb$%) { |filename, _|
- filename
- }
- at.add_mapping(%r%^app/models/(.*)\.rb$%) { |_, m|
- ["spec/models/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^app/views/(.*)$%) { |_, m|
- at.files_matching %r%^spec/views/#{m[1]}_spec.rb$%
- }
- at.add_mapping(%r%^app/controllers/(.*)\.rb$%) { |_, m|
- if m[1] == "application"
- at.files_matching %r%^spec/controllers/.*_spec\.rb$%
- else
- ["spec/controllers/#{m[1]}_spec.rb"]
- end
- }
- at.add_mapping(%r%^app/helpers/(.*)_helper\.rb$%) { |_, m|
- if m[1] == "application" then
- at.files_matching(%r%^spec/(views|helpers)/.*_spec\.rb$%)
- else
- ["spec/helpers/#{m[1]}_helper_spec.rb"] + at.files_matching(%r%^spec\/views\/#{m[1]}/.*_spec\.rb$%)
+ def setup_rails_rspec2_mappings
+ %w{config/ coverage/ db/ doc/ log/ public/ script/ tmp/ vendor/rails vendor/plugins vendor/gems}.each do |exception|
+ add_exception("^#{exception}")
end
- }
- at.add_mapping(%r%^config/routes\.rb$%) {
- at.files_matching %r%^spec/(controllers|routing|views|helpers)/.*_spec\.rb$%
- }
- at.add_mapping(%r%^config/database\.yml$%) { |_, m|
- at.files_matching %r%^spec/models/.*_spec\.rb$%
- }
- at.add_mapping(%r%^(spec/(spec_helper|shared/.*)|config/(boot|environment(s/test)?))\.rb$%) {
- at.files_matching %r%^spec/(models|controllers|routing|views|helpers)/.*_spec\.rb$%
- }
- at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
- ["spec/lib/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^app/mailers/(.*)\.rb$%) { |_, m|
- ["spec/mailers/#{m[1]}_spec.rb"]
- }
-end
-class Autotest::RailsRspec2 < Autotest::Rspec2
+ clear_mappings
+
+ 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/(models|controllers|routing|views|helpers|mailers|lib)/.*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|shared/.*)|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"]
+ }
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.