toadhopper-sinatra 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/test*.rb']
6
+ t.verbose = true
7
+ end
8
+
9
+ begin
10
+ gem "sr-mg", "<= 0.0.5"
11
+ require "mg"
12
+ MG.new("toadhopper-sinatra.gemspec")
13
+ rescue LoadError
14
+ end
@@ -0,0 +1,18 @@
1
+ A Sinatra plugin for [Hoptoad](http://www.hoptoadapp.com/) error reporting that uses the toadhopper gem.
2
+
3
+ You configure the Toadhopper gem as-per usual, this plugin simply adds a `report_error_to_hoptoad!` method.
4
+
5
+ ## Example
6
+
7
+ require 'sinatra/toadhopper'
8
+
9
+ set :toadhopper, :api_key => "YOURAPIKEY"
10
+
11
+ get "/" do
12
+ raise "Kaboom!"
13
+ end
14
+
15
+ error do
16
+ post_error_to_hoptoad!
17
+ "Ouch, that hurt."
18
+ end
@@ -0,0 +1,26 @@
1
+ require 'sinatra/base'
2
+ require 'toadhopper'
3
+
4
+ module Sinatra
5
+ module Toadhopper
6
+ # Reports the current sinatra error to Hoptoad.
7
+ def post_error_to_hoptoad!
8
+ unless api_key = options.respond_to?(:toadhopper) && options.toadhopper[:api_key]
9
+ STDERR.puts "WARNING: Ignoring post_error_to_hoptoad! - :api_key not set"
10
+ return
11
+ end
12
+ ::Toadhopper.api_key = api_key
13
+ ::Toadhopper.post!(
14
+ env['sinatra.error'],
15
+ {
16
+ :parameters => params,
17
+ :url => request.url,
18
+ :cgi_data => request.env,
19
+ :environment_vars => ENV,
20
+ :session_data => session.to_hash
21
+ }
22
+ )
23
+ end
24
+ end
25
+ helpers Toadhopper
26
+ end
@@ -0,0 +1,85 @@
1
+ require 'rubygems'
2
+
3
+ require 'test/unit'
4
+ require 'sinatra/base'
5
+ require 'rack/test'
6
+ require 'toadhopper/test/methods'
7
+
8
+ $:.unshift File.dirname(__FILE__) + "/../lib"
9
+ require 'sinatra/toadhopper'
10
+
11
+ class TestReportErrorToHoptoad < Test::Unit::TestCase
12
+
13
+ class AppThatGoesBoom < Sinatra::Base
14
+
15
+ helpers Sinatra::Toadhopper
16
+
17
+ set :raise_errors, false
18
+ set :sessions, true
19
+
20
+ set :toadhopper, :api_key => "apikey"
21
+
22
+ get "/:id" do
23
+ session["id"] = "sessionid"
24
+ raise "Kaboom!"
25
+ end
26
+
27
+ error do
28
+ post_error_to_hoptoad!
29
+ "Ouch, that hurt."
30
+ end
31
+ end
32
+
33
+ include Rack::Test::Methods
34
+ include Toadhopper::Test::Methods
35
+
36
+ def app; AppThatGoesBoom end
37
+
38
+ def setup
39
+ stub_toadhopper_post!
40
+ get "/theid"
41
+ @error, @options, @header_options = last_toadhopper_post_arguments
42
+ end
43
+
44
+ def test_api_key_set
45
+ assert_equal "apikey", Toadhopper.api_key
46
+ end
47
+
48
+ def test_reported_error
49
+ assert_equal RuntimeError, @error.class
50
+ assert_equal "Kaboom!", @error.message
51
+ end
52
+
53
+ def test_options
54
+ assert_equal({"id" => "theid"}, @options[:parameters])
55
+ assert_equal last_request.url, @options[:url]
56
+ assert_equal last_request.env, @options[:cgi_data]
57
+ assert_equal ENV, @options[:environment_vars]
58
+ assert_equal({"id" => "sessionid"}, @options[:session_data])
59
+ end
60
+
61
+ end
62
+
63
+ class TestFailsSilentWithoutApiKey < Test::Unit::TestCase
64
+
65
+ class AppWithoutApiKey < Sinatra::Base
66
+ helpers Sinatra::Toadhopper
67
+ set :raise_errors, false
68
+ get("/") { raise "Kaboom!" }
69
+ error do
70
+ post_error_to_hoptoad!
71
+ "Error"
72
+ end
73
+ end
74
+
75
+ include Rack::Test::Methods
76
+ include Toadhopper::Test::Methods
77
+
78
+ def app; AppWithoutApiKey end
79
+
80
+ def test_doesnt_raise_an_error
81
+ stub_toadhopper_post!
82
+ assert_nothing_raised { get "/" }
83
+ end
84
+
85
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toadhopper-sinatra
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Tim Lucas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-16 00:00:00 +10:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: toadhopper
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.4"
24
+ version:
25
+ description: Post Hoptoad notifications from Sinatra
26
+ email: t.lucas@toolmantim.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - Readme.md
33
+ files:
34
+ - Readme.md
35
+ - Rakefile
36
+ - lib/sinatra/toadhopper.rb
37
+ - test/test_report_error_to_hoptoad.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/toolmantim/toadhopper-sinatra
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.1
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Post Hoptoad notifications from Sinatra
64
+ test_files: []
65
+