--------------------------------------------------------------------------------

Testing static HTML pages with Capybara

I find this useful for verifying builds from static site generators.

Method

Given a static html page

./index.html

<!DOCTYPE html>
<html>
<head>...</head>
<body>
  <div id="ponysaurus" />
  </div>
</body>
</html>

It can be tested with capybara by setting the rack app to a static file server (included with the Rack gem.)

./index_spec.rb

require 'rspec'
require 'rack/file'
require 'capybara/rspec'

describe 'my static site' do
  before(:all) { Capybara.app = Rack::File.new(__dir__) }

  describe 'index' do 
    before { visit '/index.html' }

    it 'has my awesome div' do
      page.should have_selector('div#ponysaurus')
    end
  end
end