lilypad 0.1.7 → 0.1.8

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/README.markdown CHANGED
@@ -10,33 +10,47 @@ Install
10
10
  sudo gem install lilypad --source http://gemcutter.org
11
11
  </pre>
12
12
 
13
- Use it
14
- ------
13
+ Rails
14
+ -----
15
+
16
+ In **config/environment.rb**:
15
17
 
16
18
  <pre>
17
19
  require 'rack/lilypad'
18
- use Rack::Lilypad, 'hoptoad_api_key_goes_here'
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
- To specify environment filters:
27
+ Sinatra
28
+ -------
22
29
 
23
30
  <pre>
24
- use Rack::Lilypad, 'hoptoad_api_key_goes_here' do |hoptoad|
25
- hoptoad.filters << %w(AWS_ACCESS_KEY AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
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
- In Rails, you will need to do this in the <code>Rails::Initializer.run</code> block in environment.rb:
39
+ Filters
40
+ -------
41
+
42
+ Don't send certain environment variables to Hoptoad.
30
43
 
31
44
  <pre>
32
- ENV['RACK_ENV'] = ENV['RAILS_ENV']
33
- config.middleware.use Rack::Lilypad, 'hoptoad_api_key_goes_here'
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
- Use the log option to see what is happening:
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
@@ -13,5 +13,5 @@ GEM_SPEC = Gem::Specification.new do |s|
13
13
  s.name = GEM_NAME
14
14
  s.platform = Gem::Platform::RUBY
15
15
  s.require_path = "lib"
16
- s.version = "0.1.7"
16
+ s.version = "0.1.8"
17
17
  end
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
- case response
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: #{response.class}\n\n#{response.body if response.respond_to? :body}\n\n#{@@last_response}"
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(to_string(value), :key => key)
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(to_string(value), :key => key)
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
- @@last_response = xml.target!
132
+ @@last_request = xml.target!
138
133
  end
139
134
 
140
135
  class <<self
141
- def last_response
142
- @@last_response
136
+ def last_request
137
+ @@last_request
143
138
  end
144
139
  end
145
140
 
@@ -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.should include('T1')
27
- notifier.filters.should include('T2')
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 if specified" do
31
- path = "#{SPEC}/fixtures/hoptoad.log"
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 = path
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
- File.exists?(path).should == true
37
- File.delete path
38
- File.exists?(path).should == false
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
- get "/raise" rescue nil
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.last_response)
71
+ doc = Nokogiri::XML(Rack::Lilypad::Hoptoad.last_request)
55
72
 
56
73
  errors = xsd.validate(doc)
57
74
  errors.each do |error|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lilypad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh