exceptional 2.0.2 → 2.0.3

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/exceptional.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = %q{exceptional}
4
- s.version = "2.0.2"
4
+ s.version = "2.0.3"
5
5
  s.authors = ["Contrast"]
6
6
  s.summary = %q{Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service)}
7
7
  s.description = %q{Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service). Use it to find out about errors that happen in your live app. It captures lots of helpful information to help you fix the errors.}
data/init.rb CHANGED
@@ -1,20 +1,5 @@
1
1
  require 'exceptional'
2
2
 
3
- unless Object.const_defined?(:JSON)
4
- begin
5
- require 'json'
6
- rescue LoadError
7
- begin
8
- require 'json-ruby'
9
- rescue LoadError
10
- require 'json_pure'
11
- end
12
- end
13
- end
14
- unless Object.const_defined?(:JSON)
15
- raise "Could not load json gem; make sure you install one of json_pure, json-ruby, or the C-based json gem."
16
- end
17
-
18
3
  # If old plugin still installed then we don't want to install this one.
19
4
  # In production environments we should continue to work as before, but in development/test we should
20
5
  # advise how to correct the problem and exit
data/lib/exceptional.rb CHANGED
@@ -11,7 +11,7 @@ require 'exceptional/remote'
11
11
 
12
12
  module Exceptional
13
13
  PROTOCOL_VERSION = 5
14
- VERSION = '2.0.2'
14
+ VERSION = '2.0.3'
15
15
  CLIENT_NAME = 'getexceptional-rails-plugin'
16
16
 
17
17
  def self.logger
@@ -32,7 +32,16 @@ module Exceptional
32
32
  end
33
33
 
34
34
  def to_json
35
- to_hash.to_json
35
+ begin
36
+ to_hash.to_json
37
+ rescue NoMethodError
38
+ begin
39
+ require 'json'
40
+ return to_hash.to_json
41
+ rescue StandardError
42
+ raise StandardError.new("You need a json gem/library installed to send errors to Exceptional (Object.to_json not defined). \nInstall json_pure, yajl-ruby, json-jruby, or the c-based json gem")
43
+ end
44
+ end
36
45
  end
37
46
 
38
47
  def uniqueness_hash
@@ -1,6 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'digest/md5'
3
- require 'json'
4
3
 
5
4
  class Exceptional::FunkyError < StandardError
6
5
  def backtrace
@@ -8,13 +7,28 @@ class Exceptional::FunkyError < StandardError
8
7
  end
9
8
  end
10
9
 
10
+ describe Exceptional::ControllerExceptionData do
11
+ it "raises useful error when to_json isn't available on to_hash" do
12
+ begin
13
+ data = Exceptional::ExceptionData.new(Exceptional::FunkyError.new)
14
+ hash_without_json = {}
15
+ hash_without_json.stub!(:to_json).and_raise(NoMethodError)
16
+ data.stub!(:to_hash).and_return(hash_without_json)
17
+ data.to_json
18
+ fail 'expects to raise and error'
19
+ rescue StandardError => e
20
+ e.message.should =~ /to_json/
21
+ end
22
+ end
23
+ end
24
+
11
25
  describe Exceptional::ControllerExceptionData, 'when no request/controller/params' do
12
26
  before :each do
13
27
  ENV['LOGNAME'] = 'bob'
14
28
  ENV['SOMEVAR'] = 'something'
15
29
  ENV['HTTP_SOMETHING'] = 'should be stripped'
16
30
  ::RAILS_ENV = 'test' unless defined?(RAILS_ENV)
17
- Time.stub!(:now).and_return(Time.mktime(1970,1,1))
31
+ Time.stub!(:now).and_return(Time.mktime(1970, 1, 1))
18
32
  error = Exceptional::FunkyError.new('some message')
19
33
  @data = Exceptional::ControllerExceptionData.new(error)
20
34
  @hash = @data.to_hash
@@ -28,11 +42,12 @@ describe Exceptional::ControllerExceptionData, 'when no request/controller/param
28
42
  error_hash['occurred_at'].should == Time.now.strftime("%Y%m%d %H:%M:%S %Z")
29
43
  client_hash = @hash['client']
30
44
  client_hash['name'].should == Exceptional::CLIENT_NAME
31
- client_hash['version'].should == Exceptional::VERSION
45
+ client_hash['version'].should == Exceptional::VERSION
32
46
  client_hash['protocol_version'].should == Exceptional::PROTOCOL_VERSION
33
47
  end
34
48
 
35
49
  it "generates parseable json" do
50
+ require 'json'
36
51
  JSON.parse(@data.to_json)['exception']['exception_class'].should == 'Exceptional::FunkyError'
37
52
  end
38
53
 
@@ -53,13 +68,13 @@ end
53
68
 
54
69
  describe Exceptional::ControllerExceptionData, 'with request/controller/params' do
55
70
  class Exceptional::SomeController < ActionController::Base
56
- filter_parameter_logging :filter_me
71
+ filter_parameter_logging :filter_me
57
72
  end
58
-
73
+
59
74
  before :each do
60
75
  @controller = Exceptional::SomeController.new
61
76
  @request = ActionController::TestRequest.new({'action' => 'some_action' })
62
- @request.request_uri = '/some_path?var1=abc'
77
+ @request.request_uri = '/some_path?var1=abc'
63
78
  @request.stub!(:parameters).and_return({'var1' => 'abc', 'action' => 'some_action', 'filter_me' => 'private'})
64
79
  @request.stub!(:request_method).and_return(:get)
65
80
  @request.stub!(:remote_ip).and_return('1.2.3.4')
@@ -87,8 +102,8 @@ describe Exceptional::ControllerExceptionData, 'with request/controller/params'
87
102
  end
88
103
  end
89
104
  crazy = Crazy.new
90
- input = {'crazy' => crazy, :simple => '123', :some_hash => {'1' => '2'}, :array => ['1','2']}
91
- Exceptional::ControllerExceptionData.sanitize_hash(input).should == {'crazy' => crazy.to_s, :simple => '123', :some_hash => {'1' => '2'}, :array => ['1','2']}
105
+ input = {'crazy' => crazy, :simple => '123', :some_hash => {'1' => '2'}, :array => ['1', '2']}
106
+ Exceptional::ControllerExceptionData.sanitize_hash(input).should == {'crazy' => crazy.to_s, :simple => '123', :some_hash => {'1' => '2'}, :array => ['1', '2']}
92
107
  end
93
108
 
94
109
  it "to_strings regex because JSON.parse(/aa/.to_json) doesn't work" do
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'exceptional', 'integrati
3
3
 
4
4
  describe Exceptional, 'version number' do
5
5
  it "be available proramatically" do
6
- Exceptional::VERSION.should == '2.0.2'
6
+ Exceptional::VERSION.should == '2.0.3'
7
7
  end
8
8
  end
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptional
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contrast
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-04 00:00:00 +00:00
12
+ date: 2010-01-05 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15