Class: Autotest::RailsRspec2

Inherits:
Rspec2
  • Object
show all
Defined in:
lib/autotest/rails_rspec2.rb

Instance Method Summary collapse

Constructor Details

#initializeRailsRspec2

Returns a new instance of RailsRspec2.



30
31
32
33
# File 'lib/autotest/rails_rspec2.rb', line 30

def initialize
  super
  setup_rails_rspec2_mappings
end

Instance Method Details

#setup_rails_rspec2_mappingsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/autotest/rails_rspec2.rb', line 35

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

  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|requests|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|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"]
  }
end