toadhopper-sinatra 0.7 → 0.10

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.md CHANGED
@@ -16,21 +16,6 @@
16
16
  \ \ /\/\
17
17
  /\/\
18
18
 
19
- How?
20
-
21
- require 'sinatra/toadhopper'
22
-
23
- set :toadhopper, :api_key => "your hoptoad API key", :filters => /password/
24
-
25
- get "/" do
26
- raise "Kaboom!"
27
- end
28
-
29
- error do
30
- post_error_to_hoptoad!
31
- "Ouch, that hurt."
32
- end
33
-
34
- Install it via rubygems:
19
+ For usage see example.rb. To install:
35
20
 
36
21
  gem install toadhopper-sinatra
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ begin
17
17
  gem "yard"
18
18
  require 'yard'
19
19
  YARD::Rake::YardocTask.new do |t|
20
- t.options = ['-r', 'README.md', '--files', 'LICENSE'] # optional
20
+ t.options = ['-r', 'README.md', '--files', 'example.rb', 'LICENSE', 'example.rb'] # optional
21
21
  end
22
22
  rescue Gem::LoadError
23
23
  end
@@ -0,0 +1,14 @@
1
+ require 'sinatra'
2
+ require 'sinatra/toadhopper'
3
+
4
+ set :toadhopper, :api_key => "apikey", :filters => /password/
5
+
6
+ post "/register" do
7
+ session[:user_id] = 42
8
+ raise "Kaboom!"
9
+ end
10
+
11
+ error do
12
+ post_error_to_hoptoad!
13
+ "Ouch, that hurt."
14
+ end
@@ -3,31 +3,31 @@ require 'toadhopper'
3
3
 
4
4
  module Sinatra
5
5
  # The Toadhopper helper methods
6
- module Toadhopper
6
+ module ToadHopper
7
+ VERSION = "0.10"
7
8
  # Reports the current sinatra error to Hoptoad
8
9
  def post_error_to_hoptoad!
9
- options.toadhopper.each_pair {|k, v| ::Toadhopper.__send__("#{k}=", v)} if options.respond_to?(:toadhopper)
10
- unless ::Toadhopper.api_key
11
- STDERR.puts "WARNING: Ignoring hoptoad notification - :api_key not set"
12
- return
10
+ unless options.toadhopper && options.toadhopper[:api_key]
11
+ STDERR.puts "ToadHopper api key not set, e.g. set :toadhopper, :api_key => 'my api key'"
13
12
  end
14
- ::Toadhopper.post!(
13
+ toadhopper = ToadHopper(options.toadhopper[:api_key])
14
+ toadhopper.filters = options.toadhopper[:filters] if options.toadhopper[:filters]
15
+ toadhopper.post!(
15
16
  env['sinatra.error'],
16
17
  {
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
- }
18
+ :url => request.url,
19
+ :request => request,
20
+ :session => session.to_hash,
21
+ :environment => ENV.to_hash,
22
+ :framework_env => options.environment.to_s,
23
+ :project_root => options.root,
24
+ :notifier_name => (notifier_name = "toadhopper-sinatra"),
25
+ :notifier_version => VERSION,
26
+ :notifier_url => 'http://github.com/toolmantim/toadhopper-sinatra'
27
27
  },
28
- {'X-Hoptoad-Client-Name' => 'toadhopper-sinatra'}
28
+ {'X-Hoptoad-Client-Name' => notifier_name}
29
29
  )
30
30
  end
31
31
  end
32
- helpers Toadhopper
32
+ helpers ToadHopper
33
33
  end
@@ -0,0 +1,67 @@
1
+ require 'test/unit'
2
+
3
+ require 'rr'
4
+ class Test::Unit::TestCase
5
+ include RR::Adapters::TestUnit
6
+ end
7
+
8
+ require 'rack/test'
9
+
10
+ toadhopper_dir = "#{File.dirname(__FILE__)}/../toadhopper"
11
+ raise "#{toadhopper_dir} does not exist" unless File.directory?(toadhopper_dir)
12
+ $:.unshift "#{toadhopper_dir}/lib"
13
+
14
+ $:.unshift "#{File.dirname(__FILE__)}/lib"
15
+
16
+ require "#{File.dirname(__FILE__)}/example"
17
+
18
+ Sinatra::Application.set :environment, :production
19
+
20
+ class Sinatra::ToadHopper::TestExample < Test::Unit::TestCase
21
+
22
+ include Rack::Test::Methods
23
+
24
+ def app; Sinatra::Application end
25
+
26
+ def setup
27
+ app.set :environment, :production
28
+
29
+ @toadhopper = ::ToadHopper.new("")
30
+ stub(::ToadHopper).new do |api_key|
31
+ @api_key = api_key
32
+ @toadhopper
33
+ end
34
+ stub(@toadhopper).post! do |*args|
35
+ @error, @options, @header = *args
36
+ end
37
+
38
+ post "/register", :name => "Billy", :password => "Bob"
39
+ end
40
+
41
+ def test_api_key_set
42
+ assert_equal "apikey", @api_key
43
+ end
44
+ def test_filter_set
45
+ assert_equal [/password/], @toadhopper.filters
46
+ end
47
+ def test_reported_error
48
+ assert_equal RuntimeError, @error.class
49
+ assert_equal "Kaboom!", @error.message
50
+ end
51
+
52
+ def test_options
53
+ assert_equal ENV.to_hash, @options[:environment]
54
+ assert_equal "http://example.org/register", @options[:url]
55
+ assert @options[:request]
56
+ assert @options[:request].respond_to?(:params)
57
+ assert @options[:framework_env] = "production"
58
+ assert @options[:project_root] = app.root
59
+ assert @options[:session] = {:user_id => 42}
60
+ assert @options[:notifier_name] = "toadhopper-sinatra"
61
+ end
62
+
63
+ def test_header_options
64
+ assert_equal "toadhopper-sinatra", @header['X-Hoptoad-Client-Name']
65
+ end
66
+
67
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toadhopper-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.7"
4
+ version: "0.10"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Lucas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-17 00:00:00 +10:00
12
+ date: 2010-01-21 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,9 +18,9 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: "0.6"
23
+ version: 0.9.4
24
24
  version:
25
25
  description: Post Hoptoad notifications from Sinatra
26
26
  email: t.lucas@toolmantim.com
@@ -29,16 +29,19 @@ executables: []
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
- - Readme.md
32
+ - README.md
33
+ - LICENSE
33
34
  files:
34
35
  - README.md
35
36
  - Rakefile
36
37
  - LICENSE
37
38
  - lib/sinatra/toadhopper.rb
38
- - test/test_report_error_to_hoptoad.rb
39
- - Readme.md
39
+ - example.rb
40
+ - test_example.rb
40
41
  has_rdoc: true
41
42
  homepage: http://github.com/toolmantim/toadhopper-sinatra
43
+ licenses: []
44
+
42
45
  post_install_message:
43
46
  rdoc_options: []
44
47
 
@@ -59,9 +62,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
62
  requirements: []
60
63
 
61
64
  rubyforge_project: th-sinatra
62
- rubygems_version: 1.3.1
65
+ rubygems_version: 1.3.5
63
66
  signing_key:
64
- specification_version: 2
67
+ specification_version: 3
65
68
  summary: Post Hoptoad notifications from Sinatra
66
69
  test_files: []
67
70
 
data/Readme.md DELETED
@@ -1,36 +0,0 @@
1
- [Hoptoad](http://www.hoptoadapp.com/) meets [Sinatra](http://www.sinatrarb.com/).
2
-
3
- _____ ,
4
- / \______ |\ __
5
- | o | \____ | | |--| __
6
- /\_____/ \___ |/ | | |~'
7
- / \ /|_ () () |
8
- |_______/ \ //| \ |\ ()
9
- \______ _ ___ \ | \|_ | | \
10
- /\_// / \ | \_|_/ () |
11
- // //______/ /___/ | |
12
- /\/\/\ \ / \ \ @' ()
13
- \ \ \ \
14
- \ \ \ \
15
- \ \ \ \
16
- \ \ /\/\
17
- /\/\
18
-
19
- How?
20
-
21
- require 'sinatra/toadhopper'
22
-
23
- set :toadhopper, :api_key => "your hoptoad API key", :filters => /password/
24
-
25
- get "/" do
26
- raise "Kaboom!"
27
- end
28
-
29
- error do
30
- post_error_to_hoptoad!
31
- "Ouch, that hurt."
32
- end
33
-
34
- Install it via rubygems:
35
-
36
- gem install toadhopper-sinatra
@@ -1,71 +0,0 @@
1
- require 'rubygems'
2
-
3
- require 'test/unit'
4
-
5
- require 'rr'
6
- class Test::Unit::TestCase
7
- include RR::Adapters::TestUnit
8
- end
9
-
10
- require 'sinatra/base'
11
- require 'rack/test'
12
-
13
- $:.unshift File.dirname(__FILE__) + "/../lib"
14
- require 'sinatra/toadhopper'
15
-
16
- class TestReportErrorToHoptoad < Test::Unit::TestCase
17
-
18
- class AppThatGoesBoom < Sinatra::Base
19
-
20
- helpers Sinatra::Toadhopper
21
-
22
- set :raise_errors, false
23
- set :sessions, true
24
-
25
- set :toadhopper, :api_key => "apikey", :filters => /afilter/
26
-
27
- get "/:id" do
28
- session["id"] = "sessionid"
29
- raise "Kaboom!"
30
- end
31
-
32
- error do
33
- post_error_to_hoptoad!
34
- "Ouch, that hurt."
35
- end
36
- end
37
-
38
- include Rack::Test::Methods
39
-
40
- def app; AppThatGoesBoom end
41
-
42
- def setup
43
- stub(Toadhopper).post! {|*args| @error, @options, @header_options = *args }
44
- get "/theid"
45
- end
46
-
47
- def test_api_key_set
48
- assert_equal "apikey", Toadhopper.api_key
49
- end
50
- def test_filter_set
51
- assert_equal [/afilter/], Toadhopper.filters
52
- end
53
-
54
- def test_reported_error
55
- assert_equal RuntimeError, @error.class
56
- assert_equal "Kaboom!", @error.message
57
- end
58
-
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])
65
- end
66
-
67
- def test_header_options
68
- assert_equal "toadhopper-sinatra", @header_options['X-Hoptoad-Client-Name']
69
- end
70
-
71
- end