Search code examples
ruby-on-railsrspecautotestacceptance-testing

how to tell autotest to correctly track changes in app source?


I want to get autotest to run Steak acceptance tests whenever one of my rails app's relevant files is changed. After studying Rspec's and Cucumber's own autotest configs, I'm trying the following mappings:


Autotest.add_hook :initialize do |at|
  at.add_mapping(%r%^spec/acceptance/.*_spec.rb$%, true) { |filename, _|
    filename
  }

at.add_mapping(%r%^app/(models|controllers|helpers|lib)/.rb$%) { at.files_matching %r%^spec/acceptance/._spec.rb$% }

at.add_mapping(%r%^app/views/(.*)/.rb$%) { at.files_matching %r%^spec/acceptance/._spec.rb$% } end

the first one works: whenever a Steak spec is changed, it gets run again.

but the second and third don't. changing any source files under the /app subdirectories just gets ignored.

what's the correct way to get these mappings to work?

thanks Oliver


Solution

  • I just changed my .autotest file to add:

    Autotest.add_hook :initialize do |at|
      at.add_mapping(%r%^spec/acceptance/.*_spec.rb$%, true) { |filename, _|
        filename
      }
    
      at.add_mapping(%r%^app/(models|controllers|helpers|lib)/.*rb$%, true) {
        at.files_matching %r%^spec/acceptance/.*_spec.rb$%
      }
    
      at.add_mapping(%r%^app/views/(.*)$%, true) {
        at.files_matching %r%^spec/acceptance/.*_spec.rb$%
      }
    end
    

    And this is working but I don't know the collateral effects of invoking acceptance tests before others (the true flag on add_mapping)