toolmantim-toadhopper-sinatra 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile ADDED
@@ -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
data/Readme.md ADDED
@@ -0,0 +1,18 @@
1
+ Post [Hoptoad](http://www.hoptoadapp.com/) notifications from Sinatra
2
+
3
+ require 'sinatra/toadhopper'
4
+
5
+ set :toadhopper, :api_key => "your hoptoad API key"
6
+
7
+ get "/" do
8
+ raise "Kaboom!"
9
+ end
10
+
11
+ error do
12
+ post_error_to_hoptoad!
13
+ "Ouch, that hurt."
14
+ end
15
+
16
+ You can install it via rubygems:
17
+
18
+ gem install toadhopper-sinatra
@@ -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,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toolmantim-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-05-16 00:00:00 -07: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
+ licenses:
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project: th-sinatra
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Post Hoptoad notifications from Sinatra
65
+ test_files: []
66
+