lilypad 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +24 -10
- data/gemspec.rb +1 -1
- data/lib/rack/lilypad.rb +9 -14
- data/spec/rack/lilypad_spec.rb +27 -10
- metadata +1 -1
data/README.markdown
CHANGED
@@ -10,33 +10,47 @@ Install
|
|
10
10
|
sudo gem install lilypad --source http://gemcutter.org
|
11
11
|
</pre>
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
Rails
|
14
|
+
-----
|
15
|
+
|
16
|
+
In **config/environment.rb**:
|
15
17
|
|
16
18
|
<pre>
|
17
19
|
require 'rack/lilypad'
|
18
|
-
|
20
|
+
|
21
|
+
Rails::Initializer.run do |config|
|
22
|
+
ENV['RACK_ENV'] = ENV['RAILS_ENV']
|
23
|
+
config.middleware.use Rack::Lilypad, 'hoptoad_api_key_goes_here'
|
24
|
+
end
|
19
25
|
</pre>
|
20
26
|
|
21
|
-
|
27
|
+
Sinatra
|
28
|
+
-------
|
22
29
|
|
23
30
|
<pre>
|
24
|
-
|
25
|
-
|
31
|
+
require 'rack/lilypad'
|
32
|
+
|
33
|
+
class MyApp < Sinatra::Application
|
34
|
+
enable :raise_errors # not necessary for Sinatra::Base
|
35
|
+
use Rack::Lilypad, 'hoptoad_api_key_goes_here'
|
26
36
|
end
|
27
37
|
</pre>
|
28
38
|
|
29
|
-
|
39
|
+
Filters
|
40
|
+
-------
|
41
|
+
|
42
|
+
Don't send certain environment variables to Hoptoad.
|
30
43
|
|
31
44
|
<pre>
|
32
|
-
|
33
|
-
|
45
|
+
use Rack::Lilypad, 'hoptoad_api_key_goes_here' do |hoptoad|
|
46
|
+
hoptoad.filters << %w(AWS_ACCESS_KEY AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
|
47
|
+
end
|
34
48
|
</pre>
|
35
49
|
|
36
50
|
Debug
|
37
51
|
-----
|
38
52
|
|
39
|
-
|
53
|
+
See what you are sending and receiving from Hoptoad.
|
40
54
|
|
41
55
|
<pre>
|
42
56
|
use Rack::Lilypad, 'hoptoad_api_key_goes_here' do |hoptoad|
|
data/gemspec.rb
CHANGED
data/lib/rack/lilypad.rb
CHANGED
@@ -52,8 +52,8 @@ module Rack
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def log(msg)
|
56
|
-
::File.open(@log, 'a') { |f| f.write(msg) } if @log
|
55
|
+
def log(*msg)
|
56
|
+
::File.open(@log, 'a') { |f| f.write(msg.compact.join("\n\n")) } if @log
|
57
57
|
end
|
58
58
|
|
59
59
|
def post(exception, env)
|
@@ -70,12 +70,11 @@ module Rack
|
|
70
70
|
http.post uri.path, xml(exception, env), headers
|
71
71
|
rescue TimeoutError => e
|
72
72
|
end
|
73
|
-
|
74
|
-
when Net::HTTPSuccess then
|
73
|
+
if response == Net::HTTPSuccess
|
75
74
|
env['hoptoad.notified'] = true
|
76
75
|
log "Hoptoad Success: #{response.class}"
|
77
76
|
else
|
78
|
-
log "Hoptoad Failure:
|
77
|
+
log "Hoptoad Failure:", (response.body rescue nil), @@last_request
|
79
78
|
end
|
80
79
|
end
|
81
80
|
end
|
@@ -84,10 +83,6 @@ module Rack
|
|
84
83
|
%w(staging production).include?(ENV['RACK_ENV'])
|
85
84
|
end
|
86
85
|
|
87
|
-
def to_string(obj)
|
88
|
-
obj.respond_to?(:strip) ? obj : obj.inspect
|
89
|
-
end
|
90
|
-
|
91
86
|
def xml(exception, env)
|
92
87
|
environment = filter(ENV.to_hash.merge(env))
|
93
88
|
request = Rack::Request.new(env)
|
@@ -117,14 +112,14 @@ module Rack
|
|
117
112
|
if request.params.any?
|
118
113
|
r.params do |p|
|
119
114
|
request.params.each do |key, value|
|
120
|
-
p.var(
|
115
|
+
p.var(value.to_s, :key => key)
|
121
116
|
end
|
122
117
|
end
|
123
118
|
end
|
124
119
|
if environment.any?
|
125
120
|
r.tag!('cgi-data') do |c|
|
126
121
|
environment.each do |key, value|
|
127
|
-
c.var(
|
122
|
+
c.var(value.to_s, :key => key)
|
128
123
|
end
|
129
124
|
end
|
130
125
|
end
|
@@ -134,12 +129,12 @@ module Rack
|
|
134
129
|
s.tag! 'environment-name', ENV['RACK_ENV'] || 'development'
|
135
130
|
end
|
136
131
|
end
|
137
|
-
@@
|
132
|
+
@@last_request = xml.target!
|
138
133
|
end
|
139
134
|
|
140
135
|
class <<self
|
141
|
-
def
|
142
|
-
@@
|
136
|
+
def last_request
|
137
|
+
@@last_request
|
143
138
|
end
|
144
139
|
end
|
145
140
|
|
data/spec/rack/lilypad_spec.rb
CHANGED
@@ -22,20 +22,31 @@ describe Rack::Lilypad do
|
|
22
22
|
it "should yield a configuration object to the block when created" do
|
23
23
|
notifier = Rack::Lilypad.new(@app, '') do |app|
|
24
24
|
app.filters << %w(T1 T2)
|
25
|
+
app.log = 'T3'
|
25
26
|
end
|
26
|
-
notifier.filters.
|
27
|
-
notifier.filters.
|
27
|
+
notifier.filters.include?('T1').should == true
|
28
|
+
notifier.filters.include?('T2').should == true
|
29
|
+
notifier.log.should == 'T3'
|
28
30
|
end
|
29
31
|
|
30
|
-
it "should write to a log
|
31
|
-
|
32
|
+
it "should write to a log file on success and failure" do
|
33
|
+
log = "#{SPEC}/fixtures/hoptoad.log"
|
32
34
|
notifier = Rack::Lilypad.new(@app, '') do |app|
|
33
|
-
app.log =
|
35
|
+
app.log = log
|
34
36
|
end
|
37
|
+
|
38
|
+
notifier.call(@env) rescue nil
|
39
|
+
|
40
|
+
File.exists?(log).should == true
|
41
|
+
File.read(log).should =~ /Hoptoad Success/
|
42
|
+
File.delete(log)
|
43
|
+
|
44
|
+
@http.stub!(:post).and_return false
|
35
45
|
notifier.call(@env) rescue nil
|
36
|
-
|
37
|
-
File.
|
38
|
-
File.
|
46
|
+
|
47
|
+
File.exists?(log).should == true
|
48
|
+
File.read(log).should =~ /Hoptoad Failure/
|
49
|
+
File.delete(log)
|
39
50
|
end
|
40
51
|
|
41
52
|
it "should post an error to Hoptoad" do
|
@@ -48,10 +59,16 @@ describe Rack::Lilypad do
|
|
48
59
|
end
|
49
60
|
|
50
61
|
it "should transfer valid XML to Hoptoad" do
|
51
|
-
|
62
|
+
# Test complex environment variables
|
63
|
+
@env['rack.hash_test'] = { :test => true }
|
64
|
+
@env['rack.object_test'] = Object.new
|
65
|
+
|
66
|
+
notifier = Rack::Lilypad.new(@app, '')
|
67
|
+
notifier.call(@env) rescue nil
|
52
68
|
|
69
|
+
# Validate XML
|
53
70
|
xsd = Nokogiri::XML::Schema(File.read(SPEC + '/fixtures/hoptoad_2_0.xsd'))
|
54
|
-
doc = Nokogiri::XML(Rack::Lilypad::Hoptoad.
|
71
|
+
doc = Nokogiri::XML(Rack::Lilypad::Hoptoad.last_request)
|
55
72
|
|
56
73
|
errors = xsd.validate(doc)
|
57
74
|
errors.each do |error|
|