|
| 1 | +require "active_support/inflector" |
| 2 | +# Defines the matching rules for Guard. |
| 3 | +guard :minitest, all_on_start: false do |
| 4 | + watch(%r{^test/(.*)/?(.*)_test\.rb$}) |
| 5 | + 'foos'.singularize |
| 6 | + watch('test/test_helper.rb') { 'test' } |
| 7 | + watch('config/routes.rb') { interface_tests } |
| 8 | + watch(%r{app/views/layouts/*}) { interface_tests } |
| 9 | + watch(%r{^app/models/(.*?)\.rb$}) do |matches| |
| 10 | + ["test/models/#{matches[1]}_test.rb", |
| 11 | + "test/integration/microposts_interface_test.rb"] |
| 12 | + end |
| 13 | + watch(%r{^test/fixtures/(.*?)\.yml$}) do |matches| |
| 14 | + "test/models/#{matches[1].singularize}_test.rb" |
| 15 | + end |
| 16 | + watch(%r{^app/mailers/(.*?)\.rb$}) do |matches| |
| 17 | + "test/mailers/#{matches[1]}_test.rb" |
| 18 | + end |
| 19 | + watch(%r{^app/views/(.*)_mailer/.*$}) do |matches| |
| 20 | + "test/mailers/#{matches[1]}_mailer_test.rb" |
| 21 | + end |
| 22 | + watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches| |
| 23 | + resource_tests(matches[1]) |
| 24 | + end |
| 25 | + watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches| |
| 26 | + ["test/controllers/#{matches[1]}_controller_test.rb"] + |
| 27 | + integration_tests(matches[1]) |
| 28 | + end |
| 29 | + watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches| |
| 30 | + integration_tests(matches[1]) |
| 31 | + end |
| 32 | + watch('app/views/layouts/application.html.erb') do |
| 33 | + 'test/integration/site_layout_test.rb' |
| 34 | + end |
| 35 | + watch('app/helpers/sessions_helper.rb') do |
| 36 | + integration_tests << 'test/helpers/sessions_helper_test.rb' |
| 37 | + end |
| 38 | + watch('app/controllers/sessions_controller.rb') do |
| 39 | + ['test/controllers/sessions_controller_test.rb', |
| 40 | + 'test/integration/users_login_test.rb'] |
| 41 | + end |
| 42 | + watch('app/controllers/account_activations_controller.rb') do |
| 43 | + 'test/integration/users_signup_test.rb' |
| 44 | + end |
| 45 | + watch(%r{app/views/users/*}) do |
| 46 | + resource_tests('users') + |
| 47 | + ['test/integration/microposts_interface_test.rb'] |
| 48 | + end |
| 49 | + watch('app/controllers/relationships_controller.rb') do |
| 50 | + ['test/controllers/relationships_controller_test.rb', |
| 51 | + 'test/integration/following_test.rb'] |
| 52 | + end |
| 53 | +end |
| 54 | + |
| 55 | +# Returns the integration tests corresponding to the given resource. |
| 56 | +def integration_tests(resource = :all) |
| 57 | + if resource == :all |
| 58 | + Dir["test/integration/*"] |
| 59 | + else |
| 60 | + Dir["test/integration/#{resource}_*.rb"] |
| 61 | + end |
| 62 | +end |
| 63 | + |
| 64 | +# Returns all tests that hit the interface. |
| 65 | +def interface_tests |
| 66 | + integration_tests << "test/controllers" |
| 67 | +end |
| 68 | + |
| 69 | +# Returns the controller tests corresponding to the given resource. |
| 70 | +def controller_test(resource) |
| 71 | + "test/controllers/#{resource}_controller_test.rb" |
| 72 | +end |
| 73 | + |
| 74 | +# Returns all tests for the given resource. |
| 75 | +def resource_tests(resource) |
| 76 | + integration_tests(resource) << controller_test(resource) |
| 77 | +end |
0 commit comments