karmi (owner)

Revisions

gist: 185207 Download_button fork
public
Public Clone URL: git://gist.github.com/185207.git
Embed All Files: show embed
google_analytics_checker.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class GoogleAnalyticsCheckerTest < Test::Unit::TestCase
 
  # With Shoulda...
  context "Google Analytics code" do
 
    # from the layouts directory...
    Dir.entries( Rails.root.join('app/views/layouts').to_s ).
        # ... let's get all html.erb files, not partials
        select { |f| f =~ /^[^_].+\.erb$/ }.
        each do |layout|
          basename = File.basename( Rails.root.join('app/views/layouts', layout) )
 
          # ... and define test methods
          should "be present in layout #{basename}" do
            content = File.read(Rails.root.join('app/views/layouts', layout))
            # ... that check for some patterns which include Google Analytics code.
            assert_match(/var pageTracker|render :partial => .+ga|render :partial => .+google/, content)
          end
 
        end
 
    end
  
end