Sha256: e1196a3aac3f4c230824c44ff89889c8ba967028864f3d360b5d59771c201770

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'rubygems'

require 'test/unit'
require 'sinatra/base'
require 'rack/test'

$:.unshift File.dirname(__FILE__) + "/../lib"
require 'sinatra/toadhopper'

# Stub the Toadhopper posting

def Toadhopper.post!(*args)
  instance_variable_set(:@last_post_arguments, args)
end

def Toadhopper.last_post_arguments
  instance_variable_get(:@last_post_arguments)
end

class TestReportErrorToHoptoad < Test::Unit::TestCase
  
  class AppThatGoesBoom < Sinatra::Base

    helpers Sinatra::Toadhopper

    set :raise_errors, false
    set :sessions, true

    set :toadhopper, :api_key => "apikey", :filters => /afilter/

    get "/:id" do
      session["id"] = "sessionid"
      raise "Kaboom!"
    end

    error do
      post_error_to_hoptoad!
      "Ouch, that hurt."
    end
  end
  
  include Rack::Test::Methods

  def app; AppThatGoesBoom end

  def setup
    get "/theid"
    @error, @options, @header_options = Toadhopper.last_post_arguments
  end

  def test_api_key_set
    assert_equal "apikey", Toadhopper.api_key
  end
  def test_filter_set
    assert_equal [/afilter/], Toadhopper.filters
  end

  def test_reported_error
    assert_equal RuntimeError, @error.class
    assert_equal "Kaboom!", @error.message
  end
  
  def test_options
    assert_equal ENV, @options[:environment]
    assert_equal "http://example.org/theid", @options[:request][:url]
    assert_equal({"id" => "theid"}, @options[:request][:params])
    assert_equal nil, @options[:request][:rails_root]
    assert_equal({:key => 42, :data => {"id" => "sessionid"}}, @options[:session])
  end
  
  def test_header_options
    assert_equal "toadhopper-sinatra", @header_options['X-Hoptoad-Client-Name']
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toadhopper-sinatra-0.6 test/test_report_error_to_hoptoad.rb