exceptioner 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ .rvmrc
@@ -0,0 +1,8 @@
1
+ = CHANGELOG
2
+
3
+ == 0.0.5 (13.01.2011)
4
+ * fixed environment variables formatting
5
+ * got rid of jeweler in favour of bundler
6
+ * provide String#camelize if not available already
7
+ * dispatch when rack.exception given
8
+ * tests for mail and jabber transports
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ exceptioner (0.0.5)
5
+ mail (~> 2.2)
6
+ xmpp4r (~> 0.5)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.0.3)
12
+ i18n (0.5.0)
13
+ mail (2.2.14)
14
+ activesupport (>= 2.3.6)
15
+ i18n (>= 0.4.0)
16
+ mime-types (~> 1.16)
17
+ treetop (~> 1.4.8)
18
+ mime-types (1.16)
19
+ mocha (0.9.10)
20
+ rake
21
+ polyglot (0.3.1)
22
+ rack (1.2.1)
23
+ rack-test (0.5.7)
24
+ rack (>= 1.0)
25
+ rake (0.8.7)
26
+ treetop (1.4.9)
27
+ polyglot (>= 0.3.1)
28
+ xmpp4r (0.5)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ exceptioner!
35
+ mail (~> 2.2)
36
+ mocha
37
+ rack-test
38
+ xmpp4r (~> 0.5)
data/Rakefile CHANGED
@@ -1,48 +1,13 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "exceptioner"
8
- gem.summary = %Q{Be notified about exceptions by various transports Email, Jabber, RSS. Choose the option you want}
9
- gem.description = %Q{The most common use is to use Exceptioner as rack middleware and send notifications when an exception occur in you web application. It may be used with Rails, Sinatra or any other rack citizen.
10
- Exceptioner may be also used with any ruby code you want. Just configure delivery methods and don't miss any exception.}
11
- gem.email = "michal@lomnicki.com.pl"
12
- gem.homepage = "http://github.com/mlomnicki/exceptioner"
13
- gem.authors = ["Michał Łomnicki"]
14
- gem.add_development_dependency "rspec", ">= 1.2.9"
15
- gem.add_dependency "mail", "~> 2.2"
16
- gem.add_dependency "xmpp4r", "~> 0.5"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- Jeweler::GemcutterTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
35
-
36
- task :spec => :check_dependencies
37
-
38
- task :default => :spec
39
-
40
- require 'rake/rdoctask'
41
- Rake::RDocTask.new do |rdoc|
42
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
-
44
- rdoc.rdoc_dir = 'rdoc'
45
- rdoc.title = "exceptioner #{version}"
46
- rdoc.rdoc_files.include('README*')
47
- rdoc.rdoc_files.include('lib/**/*.rb')
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ task :default => :test
6
+
7
+ desc 'Run Exceptioner unit tests.'
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
48
13
  end
@@ -1,79 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "exceptioner/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{exceptioner}
8
- s.version = "0.0.4"
6
+ s.name = "exceptioner"
7
+ s.version = Exceptioner::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michał Łomnicki"]
10
+ s.email = ["michal.lomnicki@gmail.com"]
11
+ s.homepage = "https://github.com/mlomnicki/exceptioner"
12
+ s.summary = "Stay notified of exceptions raised by your application. Choose from various notification methods like Email, Jabber or IRC"
13
+ s.description = "Exceptioner is meant to be for hoptoad, exception_notification or getexceptional. It's fully customizable and works with each kind of ruby application"
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Micha\305\202 \305\201omnicki"]
12
- s.date = %q{2010-12-16}
13
- s.description = %q{The most common use is to use Exceptioner as rack middleware and send notifications when an exception occur in you web application. It may be used with Rails, Sinatra or any other rack citizen.
14
- Exceptioner may be also used with any ruby code you want. Just configure delivery methods and don't miss any exception.}
15
- s.email = %q{michal@lomnicki.com.pl}
16
- s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".gitignore",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "exceptioner.gemspec",
28
- "init.rb",
29
- "lib/exceptioner.rb",
30
- "lib/exceptioner/action_controller.rb",
31
- "lib/exceptioner/core_ext/class/attribute.rb",
32
- "lib/exceptioner/core_ext/kernel/singleton_class.rb",
33
- "lib/exceptioner/core_ext/module/attribute_accessors.rb",
34
- "lib/exceptioner/core_ext/module/remove_method.rb",
35
- "lib/exceptioner/middleware.rb",
36
- "lib/exceptioner/notifier.rb",
37
- "lib/exceptioner/railtie.rb",
38
- "lib/exceptioner/transport/base.rb",
39
- "lib/exceptioner/transport/helper.rb",
40
- "lib/exceptioner/transport/jabber/jabber.rb",
41
- "lib/exceptioner/transport/mail/mail.rb",
42
- "lib/exceptioner/transport/templates/exception.erb",
43
- "lib/generators/exceptioner/USAGE",
44
- "lib/generators/exceptioner/install_generator.rb",
45
- "lib/generators/exceptioner/templates/exceptioner.rb",
46
- "spec/exceptioner_spec.rb",
47
- "spec/spec.opts",
48
- "spec/spec_helper.rb"
49
- ]
50
- s.homepage = %q{http://github.com/mlomnicki/exceptioner}
51
- s.rdoc_options = ["--charset=UTF-8"]
15
+ s.rubyforge_project = "exceptioner"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
52
20
  s.require_paths = ["lib"]
53
- s.rubygems_version = %q{1.3.6}
54
- s.summary = %q{Be notified about exceptions by various transports Email, Jabber, RSS. Choose the option you want}
55
- s.test_files = [
56
- "spec/exceptioner_spec.rb",
57
- "spec/spec_helper.rb"
58
- ]
59
21
 
60
- if s.respond_to? :specification_version then
61
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
- s.specification_version = 3
22
+ s.add_dependency("mail", ["~> 2.2"])
23
+ s.add_dependency("xmpp4r", ["~> 0.5"])
63
24
 
64
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
65
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
66
- s.add_runtime_dependency(%q<mail>, ["~> 2.2"])
67
- s.add_runtime_dependency(%q<xmpp4r>, ["~> 0.5"])
68
- else
69
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
70
- s.add_dependency(%q<mail>, ["~> 2.2"])
71
- s.add_dependency(%q<xmpp4r>, ["~> 0.5"])
72
- end
73
- else
74
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
75
- s.add_dependency(%q<mail>, ["~> 2.2"])
76
- s.add_dependency(%q<xmpp4r>, ["~> 0.5"])
77
- end
25
+ s.add_development_dependency("rack-test")
26
+ s.add_development_dependency("mocha")
78
27
  end
79
-
@@ -1,5 +1,7 @@
1
1
  require 'exceptioner/core_ext/class/attribute'
2
2
  require 'exceptioner/core_ext/module/attribute_accessors'
3
+ require 'exceptioner/core_ext/string/inflections'
4
+ require 'exceptioner/version'
3
5
  require 'exceptioner/railtie' if defined?(Rails::Railtie)
4
6
 
5
7
  module Exceptioner
@@ -8,6 +10,7 @@ module Exceptioner
8
10
 
9
11
  autoload :Middleware, 'exceptioner/middleware'
10
12
  autoload :ActionController, 'exceptioner/action_controller'
13
+ autoload :Notifier, 'exceptioner/notifier'
11
14
 
12
15
  module Transport
13
16
  autoload :Mail, 'exceptioner/transport/mail/mail'
@@ -0,0 +1,7 @@
1
+ class String
2
+
3
+ def camelize
4
+ gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
5
+ end unless method_defined?(:camelize)
6
+
7
+ end
@@ -9,11 +9,16 @@ module Exceptioner
9
9
 
10
10
  def call(env)
11
11
  begin
12
- @app.call(env)
12
+ response = @app.call(env)
13
13
  rescue Exception => exception
14
14
  Notifier.dispatch(exception, :controller => env['action_controller.instance'], :env => env)
15
15
  raise exception
16
16
  end
17
+ if env['rack.exception']
18
+ Notifier.dispatch(env['rack.exception'], :controller => env['action_controller.instance'], :env => env)
19
+ end
20
+
21
+ response
17
22
  end
18
23
 
19
24
  end
@@ -6,9 +6,9 @@ module Exceptioner::Transport
6
6
  unless env.empty?
7
7
  max_length = env.keys.max_by { |key| key.to_s.size }.size
8
8
  env.keys.sort.collect do |key|
9
- "* #{"%-*s: %s" % [max_length, key, env[key].to_s.strip[0..50]]}\n\t"
9
+ "* #{"%-*s: %s" % [max_length, key, env[key].to_s.strip[0..50]]}"
10
10
  end
11
- end
11
+ end.join("\n\t")
12
12
  end
13
13
 
14
14
  def title(text)
@@ -0,0 +1,3 @@
1
+ module Exceptioner
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'mocha'
3
+
4
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
5
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
6
+
7
+ require 'exceptioner'
8
+ require 'rack'
9
+ require 'mock_smtp'
10
+
11
+ class Test::Unit::TestCase
12
+
13
+ def get_exception
14
+ raise
15
+ rescue => exception
16
+ exception
17
+ end
18
+
19
+ def config
20
+ Exceptioner
21
+ end
22
+
23
+ def mail_system
24
+ MockSMTP
25
+ end
26
+
27
+ end
@@ -0,0 +1,50 @@
1
+ # Original mockup from ActionMailer
2
+ require 'net/smtp'
3
+ class MockSMTP
4
+
5
+ def self.deliveries
6
+ @@deliveries
7
+ end
8
+
9
+ def initialize
10
+ @@deliveries = []
11
+ end
12
+
13
+ def sendmail(body, from, to)
14
+ @@deliveries << Mail.new(:from => from, :to => to, :body => body)
15
+ end
16
+
17
+ def start(*args)
18
+ yield self
19
+ end
20
+
21
+ def self.clear_deliveries
22
+ @@deliveries = []
23
+ end
24
+
25
+ # in the standard lib: net/smtp.rb line 577
26
+ # a TypeError is thrown unless this arg is a
27
+ # kind of OpenSSL::SSL::SSLContext
28
+ def enable_tls(context = nil)
29
+ if context && context.kind_of?(OpenSSL::SSL::SSLContext)
30
+ true
31
+ elsif context
32
+ raise TypeError,
33
+ "wrong argument (#{context.class})! "+
34
+ "(Expected kind of OpenSSL::SSL::SSLContext)"
35
+ end
36
+ end
37
+
38
+ def enable_starttls_auto
39
+ true
40
+ end
41
+
42
+ end
43
+
44
+ class Net::SMTP
45
+ def self.new(*args)
46
+ MockSMTP.new
47
+ end
48
+ end
49
+
50
+
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+ require 'xmpp4r'
3
+
4
+ class NotifierTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ Exceptioner::Notifier.stubs(:dispatch_exception).returns(true)
8
+ config.mail.recipients = %w[michal@example.net]
9
+ config.jabber.jabber_id = %w[jabber@example.net]
10
+ config.jabber.password = 'secret'
11
+ config.jabber.recipients = %w[michal@example.net]
12
+ end
13
+
14
+ def test_deliver_exception_by_email
15
+ exception = get_exception
16
+ Exceptioner::Notifier.stubs(:transports).returns([:mail])
17
+ Exceptioner::Notifier.dispatch(exception)
18
+ assert_equal mail_system.deliveries.size, 1
19
+
20
+ end
21
+
22
+ def test_deliver_exception_by_jabber
23
+ exception = get_exception
24
+ Exceptioner::Notifier.stubs(:transports).returns([:jabber])
25
+ Jabber::Client.any_instance.expects(:connect).once
26
+ Jabber::Client.any_instance.expects(:auth).with(config.jabber.password).once
27
+ Jabber::Client.any_instance.expects(:send).once
28
+ Exceptioner::Notifier.dispatch(exception)
29
+ end
30
+
31
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class RackTest < Test::Unit::TestCase
4
+
5
+ def test_should_dispatch_exception
6
+ exception = get_exception
7
+ app = lambda { |env| raise exception }
8
+ environment = { 'key' => 'value' }
9
+
10
+ Exceptioner::Notifier.expects(:dispatch).with(exception, has_entry(:env, environment))
11
+
12
+ begin
13
+ stack = Exceptioner::Middleware.new(app)
14
+ stack.call(environment)
15
+ rescue Exception => raised
16
+ assert_equal exception, raised
17
+ else
18
+ flunk "Didn't raise an exception"
19
+ end
20
+
21
+ end
22
+
23
+ def test_should_assign_exception_to_rack_exception
24
+ exception = get_exception
25
+ response = [200, {}, ['hello world']]
26
+ environment = { 'key' => 'value' }
27
+ app = lambda do |env|
28
+ env['rack.exception'] = exception
29
+ response
30
+ end
31
+
32
+ Exceptioner::Notifier.expects(:dispatch).with(exception, has_entry(:env, environment))
33
+
34
+ stack = Exceptioner::Middleware.new(app)
35
+
36
+ actual_response = stack.call(environment)
37
+ assert_equal response, actual_response
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Micha\xC5\x82 \xC5\x81omnicki"
@@ -14,67 +14,81 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-16 00:00:00 +01:00
17
+ date: 2011-01-13 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
21
+ name: mail
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
- - - ">="
26
+ - - ~>
26
27
  - !ruby/object:Gem::Version
27
28
  segments:
28
- - 1
29
29
  - 2
30
- - 9
31
- version: 1.2.9
32
- type: :development
30
+ - 2
31
+ version: "2.2"
32
+ type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: mail
35
+ name: xmpp4r
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
38
39
  requirements:
39
40
  - - ~>
40
41
  - !ruby/object:Gem::Version
41
42
  segments:
42
- - 2
43
- - 2
44
- version: "2.2"
43
+ - 0
44
+ - 5
45
+ version: "0.5"
45
46
  type: :runtime
46
47
  version_requirements: *id002
47
48
  - !ruby/object:Gem::Dependency
48
- name: xmpp4r
49
+ name: rack-test
49
50
  prerelease: false
50
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
51
53
  requirements:
52
- - - ~>
54
+ - - ">="
53
55
  - !ruby/object:Gem::Version
54
56
  segments:
55
57
  - 0
56
- - 5
57
- version: "0.5"
58
- type: :runtime
58
+ version: "0"
59
+ type: :development
59
60
  version_requirements: *id003
60
- description: |-
61
- The most common use is to use Exceptioner as rack middleware and send notifications when an exception occur in you web application. It may be used with Rails, Sinatra or any other rack citizen.
62
- Exceptioner may be also used with any ruby code you want. Just configure delivery methods and don't miss any exception.
63
- email: michal@lomnicki.com.pl
61
+ - !ruby/object:Gem::Dependency
62
+ name: mocha
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ type: :development
73
+ version_requirements: *id004
74
+ description: Exceptioner is meant to be for hoptoad, exception_notification or getexceptional. It's fully customizable and works with each kind of ruby application
75
+ email:
76
+ - michal.lomnicki@gmail.com
64
77
  executables: []
65
78
 
66
79
  extensions: []
67
80
 
68
- extra_rdoc_files:
69
- - LICENSE
70
- - README.rdoc
81
+ extra_rdoc_files: []
82
+
71
83
  files:
72
84
  - .document
73
85
  - .gitignore
86
+ - CHANGELOG.rdoc
87
+ - Gemfile
88
+ - Gemfile.lock
74
89
  - LICENSE
75
90
  - README.rdoc
76
91
  - Rakefile
77
- - VERSION
78
92
  - exceptioner.gemspec
79
93
  - init.rb
80
94
  - lib/exceptioner.rb
@@ -83,6 +97,7 @@ files:
83
97
  - lib/exceptioner/core_ext/kernel/singleton_class.rb
84
98
  - lib/exceptioner/core_ext/module/attribute_accessors.rb
85
99
  - lib/exceptioner/core_ext/module/remove_method.rb
100
+ - lib/exceptioner/core_ext/string/inflections.rb
86
101
  - lib/exceptioner/middleware.rb
87
102
  - lib/exceptioner/notifier.rb
88
103
  - lib/exceptioner/railtie.rb
@@ -91,22 +106,28 @@ files:
91
106
  - lib/exceptioner/transport/jabber/jabber.rb
92
107
  - lib/exceptioner/transport/mail/mail.rb
93
108
  - lib/exceptioner/transport/templates/exception.erb
109
+ - lib/exceptioner/version.rb
94
110
  - lib/generators/exceptioner/USAGE
95
111
  - lib/generators/exceptioner/install_generator.rb
96
112
  - lib/generators/exceptioner/templates/exceptioner.rb
97
113
  - spec/exceptioner_spec.rb
98
114
  - spec/spec.opts
99
115
  - spec/spec_helper.rb
116
+ - test/helper.rb
117
+ - test/mock_smtp.rb
118
+ - test/notifier_test.rb
119
+ - test/rack_test.rb
100
120
  has_rdoc: true
101
- homepage: http://github.com/mlomnicki/exceptioner
121
+ homepage: https://github.com/mlomnicki/exceptioner
102
122
  licenses: []
103
123
 
104
124
  post_install_message:
105
- rdoc_options:
106
- - --charset=UTF-8
125
+ rdoc_options: []
126
+
107
127
  require_paths:
108
128
  - lib
109
129
  required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
110
131
  requirements:
111
132
  - - ">="
112
133
  - !ruby/object:Gem::Version
@@ -114,6 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
135
  - 0
115
136
  version: "0"
116
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
117
139
  requirements:
118
140
  - - ">="
119
141
  - !ruby/object:Gem::Version
@@ -122,11 +144,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
144
  version: "0"
123
145
  requirements: []
124
146
 
125
- rubyforge_project:
126
- rubygems_version: 1.3.6
147
+ rubyforge_project: exceptioner
148
+ rubygems_version: 1.3.7
127
149
  signing_key:
128
150
  specification_version: 3
129
- summary: Be notified about exceptions by various transports Email, Jabber, RSS. Choose the option you want
130
- test_files:
131
- - spec/exceptioner_spec.rb
132
- - spec/spec_helper.rb
151
+ summary: Stay notified of exceptions raised by your application. Choose from various notification methods like Email, Jabber or IRC
152
+ test_files: []
153
+
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.4