Sha256: 3cc708390066738f7c0fcc4115a6da4246e50033f826225732375133f9e7ceb9

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require 'rubygems'

require 'test/unit'

require 'rr'
class Test::Unit::TestCase
  include RR::Adapters::TestUnit
end

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

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

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
    stub(Toadhopper).post! {|*args| @error, @options, @header_options = *args }
    get "/theid"
  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

2 entries across 2 versions & 2 rubygems

Version Path
toolmantim-toadhopper-sinatra-0.7 test/test_report_error_to_hoptoad.rb
toadhopper-sinatra-0.7 test/test_report_error_to_hoptoad.rb