Rails: Test all your static pages for success and missing translations easily

on under developer
1 minute read

Out Of Date Warning

This article was published on 05/06/2013, this means the content may be out of date or no longer relevant.
You should verify that the technical information in this article is still up to date before relying upon it for your own purposes.

Testing static pages in Rspec/Rails can be easily done automatically by querying the public methods of the Controller object:

describe PagesController do
  specify "Browsing static pages" do
    actions = PagesController.public_instance_methods - ApplicationController.public_instance_methods
    actions.each do |action|
      get action
      response.should be_success
      # Bonus points: Check for missing translations
      if response.body.to_s[/translation missing: (.*)"/]
        fail "There are missing translations: #{$1}"

(As controller, integration or mixed test)

This way, you ensure: Your views compile, no missing translations on the page and the actions are visible to outside world.