|
| 1 | +# (c) Copyright 2006 Nick Sieger <[email protected]> |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person |
| 4 | +# obtaining a copy of this software and associated documentation files |
| 5 | +# (the "Software"), to deal in the Software without restriction, |
| 6 | +# including without limitation the rights to use, copy, modify, merge, |
| 7 | +# publish, distribute, sublicense, and/or sell copies of the Software, |
| 8 | +# and to permit persons to whom the Software is furnished to do so, |
| 9 | +# subject to the following conditions: |
| 10 | +# |
| 11 | +# The above copyright notice and this permission notice shall be |
| 12 | +# included in all copies or substantial portions of the Software. |
| 13 | +# |
| 14 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 | +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 | +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 18 | +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 19 | +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 | +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +$:.push(*Dir["vendor/rails/*/lib"]) |
| 24 | + |
| 25 | +require 'active_support/core_ext' |
| 26 | +require 'autotest/rspec2' |
| 27 | + |
| 28 | +class Autotest::RailsRspec2 < Autotest::Rspec2 |
| 29 | + |
| 30 | + def initialize |
| 31 | + super |
| 32 | + setup_rails_rspec2_mappings |
| 33 | + end |
| 34 | + |
| 35 | + def setup_rails_rspec2_mappings |
| 36 | + %w{coverage/ db/ doc/ log/ public/ script/ tmp/ vendor/rails vendor/plugins vendor/gems}.each do |exception| |
| 37 | + add_exception(/^([\.\/]*)?#{exception}/) |
| 38 | + end |
| 39 | + |
| 40 | + clear_mappings |
| 41 | + |
| 42 | + add_mapping(%r%^(test|spec)/fixtures/(.*).yml$%) { |_, m| |
| 43 | + ["spec/models/#{m[2].singularize}_spec.rb"] + files_matching(%r%^spec\/views\/#{m[2]}/.*_spec\.rb$%) |
| 44 | + } |
| 45 | + add_mapping(%r%^spec/.*_spec\.rb$%) { |filename, _| |
| 46 | + filename |
| 47 | + } |
| 48 | + add_mapping(%r%^app/models/(.*)\.rb$%) { |_, m| |
| 49 | + ["spec/models/#{m[1]}_spec.rb"] |
| 50 | + } |
| 51 | + add_mapping(%r%^app/views/(.*)$%) { |_, m| |
| 52 | + files_matching %r%^spec/views/#{m[1]}_spec.rb$% |
| 53 | + } |
| 54 | + add_mapping(%r%^app/controllers/(.*)\.rb$%) { |_, m| |
| 55 | + if m[1] == "application" |
| 56 | + files_matching %r%^spec/controllers/.*_spec\.rb$% |
| 57 | + else |
| 58 | + ["spec/controllers/#{m[1]}_spec.rb"] |
| 59 | + end |
| 60 | + } |
| 61 | + add_mapping(%r%^app/helpers/(.*)_helper\.rb$%) { |_, m| |
| 62 | + if m[1] == "application" then |
| 63 | + files_matching(%r%^spec/(views|helpers)/.*_spec\.rb$%) |
| 64 | + else |
| 65 | + ["spec/helpers/#{m[1]}_helper_spec.rb"] + files_matching(%r%^spec\/views\/#{m[1]}/.*_spec\.rb$%) |
| 66 | + end |
| 67 | + } |
| 68 | + add_mapping(%r%^config/routes\.rb$%) { |
| 69 | + files_matching %r%^spec/(controllers|routing|views|helpers)/.*_spec\.rb$% |
| 70 | + } |
| 71 | + add_mapping(%r%^config/database\.yml$%) { |_, m| |
| 72 | + files_matching %r%^spec/models/.*_spec\.rb$% |
| 73 | + } |
| 74 | + add_mapping(%r%^(spec/(spec_helper|support/.*)|config/(boot|environment(s/test)?))\.rb$%) { |
| 75 | + files_matching %r%^spec/(models|controllers|routing|views|helpers)/.*_spec\.rb$% |
| 76 | + } |
| 77 | + add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| |
| 78 | + ["spec/lib/#{m[1]}_spec.rb"] |
| 79 | + } |
| 80 | + add_mapping(%r%^app/mailers/(.*)\.rb$%) { |_, m| |
| 81 | + ["spec/mailers/#{m[1]}_spec.rb"] |
| 82 | + } |
| 83 | + end |
| 84 | +end |
0 commit comments