toolmantim-toadhopper-sinatra 0.3 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/{Readme.md → README.md} +0 -0
- data/Rakefile +1 -1
- data/lib/sinatra/toadhopper.rb +14 -10
- data/test/test_report_error_to_hoptoad.rb +15 -38
- metadata +5 -4
data/{Readme.md → README.md}
RENAMED
File without changes
|
data/Rakefile
CHANGED
data/lib/sinatra/toadhopper.rb
CHANGED
@@ -6,9 +6,7 @@ module Sinatra
|
|
6
6
|
module Toadhopper
|
7
7
|
# Reports the current sinatra error to Hoptoad
|
8
8
|
def post_error_to_hoptoad!
|
9
|
-
if options.respond_to?(:toadhopper)
|
10
|
-
options.toadhopper.each_pair {|k, v| ::Toadhopper.__send__("#{k}=", v)}
|
11
|
-
end
|
9
|
+
options.toadhopper.each_pair {|k, v| ::Toadhopper.__send__("#{k}=", v)} if options.respond_to?(:toadhopper)
|
12
10
|
unless ::Toadhopper.api_key
|
13
11
|
STDERR.puts "WARNING: Ignoring hoptoad notification - :api_key not set"
|
14
12
|
return
|
@@ -16,14 +14,20 @@ module Sinatra
|
|
16
14
|
::Toadhopper.post!(
|
17
15
|
env['sinatra.error'],
|
18
16
|
{
|
19
|
-
:
|
20
|
-
:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
:environment => ENV,
|
18
|
+
:request => {
|
19
|
+
:params => params,
|
20
|
+
:rails_root => options.root,
|
21
|
+
:url => request.url
|
22
|
+
},
|
23
|
+
:session => {
|
24
|
+
:key => 42, # Doesn't apply to Rack sessions
|
25
|
+
:data => session
|
26
|
+
}
|
27
|
+
},
|
28
|
+
{'X-Hoptoad-Client-Name' => 'toadhopper-sinatra'}
|
25
29
|
)
|
26
30
|
end
|
27
31
|
end
|
28
32
|
helpers Toadhopper
|
29
|
-
end
|
33
|
+
end
|
@@ -1,23 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
3
|
require 'test/unit'
|
4
|
+
|
5
|
+
require 'rr'
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
include RR::Adapters::TestUnit
|
8
|
+
end
|
9
|
+
|
4
10
|
require 'sinatra/base'
|
5
11
|
require 'rack/test'
|
6
|
-
require 'toadhopper/test/methods'
|
7
12
|
|
8
13
|
$:.unshift File.dirname(__FILE__) + "/../lib"
|
9
14
|
require 'sinatra/toadhopper'
|
10
15
|
|
11
|
-
# Stub the Toadhopper posting
|
12
|
-
|
13
|
-
def Toadhopper.post!(*args)
|
14
|
-
instance_variable_set(:@last_post_arguments, args)
|
15
|
-
end
|
16
|
-
|
17
|
-
def Toadhopper.last_post_arguments
|
18
|
-
instance_variable_get(:@last_post_arguments)
|
19
|
-
end
|
20
|
-
|
21
16
|
class TestReportErrorToHoptoad < Test::Unit::TestCase
|
22
17
|
|
23
18
|
class AppThatGoesBoom < Sinatra::Base
|
@@ -45,8 +40,8 @@ class TestReportErrorToHoptoad < Test::Unit::TestCase
|
|
45
40
|
def app; AppThatGoesBoom end
|
46
41
|
|
47
42
|
def setup
|
43
|
+
stub(Toadhopper).post! {|*args| @error, @options, @header_options = *args }
|
48
44
|
get "/theid"
|
49
|
-
@error, @options, @header_options = Toadhopper.last_post_arguments
|
50
45
|
end
|
51
46
|
|
52
47
|
def test_api_key_set
|
@@ -60,35 +55,17 @@ class TestReportErrorToHoptoad < Test::Unit::TestCase
|
|
60
55
|
assert_equal RuntimeError, @error.class
|
61
56
|
assert_equal "Kaboom!", @error.message
|
62
57
|
end
|
63
|
-
|
64
|
-
def test_options
|
65
|
-
assert_equal({"id" => "theid"}, @options[:parameters])
|
66
|
-
assert_equal last_request.url, @options[:url]
|
67
|
-
assert_equal last_request.env, @options[:cgi_data]
|
68
|
-
assert_equal ENV, @options[:environment_vars]
|
69
|
-
assert_equal({"id" => "sessionid"}, @options[:session_data])
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
58
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
error do
|
81
|
-
post_error_to_hoptoad!
|
82
|
-
"Error"
|
83
|
-
end
|
59
|
+
def test_options
|
60
|
+
assert_equal ENV, @options[:environment]
|
61
|
+
assert_equal "http://example.org/theid", @options[:request][:url]
|
62
|
+
assert_equal({"id" => "theid"}, @options[:request][:params])
|
63
|
+
assert_equal nil, @options[:request][:rails_root]
|
64
|
+
assert_equal({:key => 42, :data => {"id" => "sessionid"}}, @options[:session])
|
84
65
|
end
|
85
66
|
|
86
|
-
|
87
|
-
|
88
|
-
def app; AppWithoutApiKey end
|
89
|
-
|
90
|
-
def test_doesnt_raise_an_error
|
91
|
-
assert_nothing_raised { get "/" }
|
67
|
+
def test_header_options
|
68
|
+
assert_equal "toadhopper-sinatra", @header_options['X-Hoptoad-Client-Name']
|
92
69
|
end
|
93
70
|
|
94
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toolmantim-toadhopper-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.7"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Lucas
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: "0.
|
23
|
+
version: "0.6"
|
24
24
|
version:
|
25
25
|
description: Post Hoptoad notifications from Sinatra
|
26
26
|
email: t.lucas@toolmantim.com
|
@@ -29,9 +29,10 @@ executables: []
|
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
|
-
-
|
32
|
+
- README.md
|
33
|
+
- LICENSE
|
33
34
|
files:
|
34
|
-
-
|
35
|
+
- README.md
|
35
36
|
- Rakefile
|
36
37
|
- LICENSE
|
37
38
|
- lib/sinatra/toadhopper.rb
|