Why don't spec/controller/pages_controller_spec.rb tests get triggered when I modify html.erb pages?

250 views Asked by At

Summary of question: Is autotest supposed to 'trigger' any of my /pages_controller_spec.rb tests when I change any of the pages referenced in the file?

Example: I have a test in the spec/controller/pages_controller_spec.rb file that tests for the title of a specific page - e.g. about.html.erb - but when I edit that file (the about file), none of my autotests trigger. All tests pass if I reload autotest or run a manual 'rspec spec/' - they just aren't triggering automatically, which is what I want.


This appears to be by design, because when I run autotest -v, it shows that there are no tests associated with the individual pages in question - excerpt:

...
No tests matched app/views/pages/contact.html.erb
No tests matched app/views/pages/help.html.erb
No tests matched app/views/pages/home.html.erb
...

All of my tests run green btw, and autotest + spork/etc triggers just fine when I edit files where I have a specific _spec file associated with it (e.g. the above file in my example & app/controllers/pages_controller.rb). It's just these html.erb files that are bothering me really.

So I guess my real question boils down to this: is this user error or does autotest really ignore these related html.erb files? Do I have to write explicit tests to hit these files if I want them tested? This seems wrong to me because I could completely break my tests by removing lines/etc from the html.erb file (but NOT changing the base pages_controller.rb file), and in that case autotest wouldn't trigger a test..


Environment details, etc:

I'm running rails 3.0.1 with ZenTest/autotest and Spork. This problem exists both with and without Spork running, so I'm guessing it's not relevant, but here is my Gemfile nevertheless:

  source 'http://rubygems.org'

  gem 'rails', '3.0.1'
  gem 'sqlite3-ruby', :require => 'sqlite3'

  group :development do
    gem 'rspec-rails'
  end

  group :test do
    gem 'rspec-rails'
    gem 'webrat', '0.7.1'
    gem 'test_notifier'
    gem 'spork', '~> 0.9.0.rc'
  end

This is Ubuntu 10.1 using a simple Kate/Terminal "IDE" if it matters. But again I think this is a configuration question and not an environment issue or bug.

1

There are 1 answers

0
raidfive On

It is my understanding that autotest doesn't not run when you make changes to views. You can add a configuration option though to add the specific path to be monitored. Here is an example from the RSpec github wiki for adding support for integration tests:

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