Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Created December 29, 2008 16:20
Show Gist options
  • Save henrypoydar/41299 to your computer and use it in GitHub Desktop.
Save henrypoydar/41299 to your computer and use it in GitHub Desktop.
A spec to make sure all view and partial template have specs
require File.dirname(__FILE__) + '/../spec_helper'
require 'find'
describe 'View template spec coverage' do
# Because the application is using Haml for all
# view and partial templates, a typo or indentation
# mistake in these templates will likely raise
# an exception. So in addition to integrated controller
# specs and existing view specs, it's important that
# every view and partial have at least a spec to render
# successfully.
before :each do
@test_for_template_spec = lambda do |file|
template = file.split('/app/views/')[1]
template_exists = File.exist?(File.dirname(__FILE__) + '/' + template.gsub('haml', 'haml_spec.rb'))
puts "Missing spec for #{template}" unless template_exists
template_exists.should be_true
end
end
it "should have a spec for each Haml view template in the application" do
Dir.glob(File.dirname(__FILE__) + '/../../app/views/**/[^_]*.html.haml').each do |view|
@test_for_template_spec.call(view)
end
end
it "should have a spec for each Haml partial template in the application" do
Dir.glob(File.dirname(__FILE__) + '/../../app/views/**/_*.html.haml').each do |partial|
@test_for_template_spec.call(partial)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment