errplane 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +2 -1
  2. data/.rspec +2 -0
  3. data/.travis.yml +22 -0
  4. data/README.md +2 -10
  5. data/Rakefile +19 -31
  6. data/errplane.gemspec +5 -9
  7. data/gemfiles/Gemfile.rails-2.3.x +8 -0
  8. data/gemfiles/Gemfile.rails-2.3.x.lock +60 -0
  9. data/gemfiles/{rails_3.2.gemfile → Gemfile.rails-3.0.x} +2 -2
  10. data/gemfiles/Gemfile.rails-3.0.x.lock +82 -0
  11. data/gemfiles/{rails_3.1.gemfile → Gemfile.rails-3.1.x} +2 -1
  12. data/gemfiles/Gemfile.rails-3.1.x.lock +94 -0
  13. data/gemfiles/{rails_3.0.gemfile → Gemfile.rails-3.2.x} +2 -1
  14. data/gemfiles/Gemfile.rails-3.2.x.lock +92 -0
  15. data/lib/errplane.rb +15 -10
  16. data/lib/errplane/backtrace.rb +38 -0
  17. data/lib/errplane/black_box.rb +8 -5
  18. data/lib/errplane/capistrano.rb +0 -1
  19. data/lib/errplane/configuration.rb +30 -22
  20. data/lib/errplane/errplane_chef_handler.rb +2 -4
  21. data/lib/errplane/logger.rb +11 -0
  22. data/lib/errplane/rails/air_traffic_controller.rb +2 -1
  23. data/lib/errplane/rails/middleware/hijack_render_exception.rb +5 -2
  24. data/lib/errplane/railtie.rb +0 -9
  25. data/lib/errplane/transmitter.rb +19 -11
  26. data/lib/errplane/version.rb +1 -1
  27. data/lib/rails/generators/errplane/templates/initializer.rb +0 -3
  28. data/spec/app/rails2.rb +38 -0
  29. data/spec/app/{rails.rb → rails3.rb} +0 -3
  30. data/spec/integration/exceptions_spec.rb +27 -9
  31. data/spec/rails2/README +243 -0
  32. data/spec/rails2/Rakefile +10 -0
  33. data/spec/rails2/app/controllers/application_controller.rb +10 -0
  34. data/spec/rails2/app/controllers/widgets_controller.rb +5 -0
  35. data/spec/rails2/app/helpers/application_helper.rb +3 -0
  36. data/spec/rails2/app/helpers/widgets_helper.rb +1 -0
  37. data/spec/rails2/config/boot.rb +114 -0
  38. data/spec/rails2/config/database.yml +3 -0
  39. data/spec/rails2/config/environment.rb +33 -0
  40. data/spec/rails2/config/environments/development.rb +17 -0
  41. data/spec/rails2/config/environments/production.rb +28 -0
  42. data/spec/{internal/public/favicon.ico → rails2/config/environments/test.rb} +0 -0
  43. data/spec/rails2/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/rails2/config/initializers/cookie_verification_secret.rb +7 -0
  45. data/spec/{internal → rails2}/config/initializers/errplane.rb +0 -0
  46. data/spec/rails2/config/initializers/inflections.rb +10 -0
  47. data/spec/rails2/config/initializers/mime_types.rb +5 -0
  48. data/spec/rails2/config/initializers/new_rails_defaults.rb +21 -0
  49. data/spec/rails2/config/initializers/session_store.rb +15 -0
  50. data/spec/rails2/config/locales/en.yml +5 -0
  51. data/spec/rails2/config/routes.rb +3 -0
  52. data/spec/rails2/lib/tasks/rspec.rake +144 -0
  53. data/spec/rails2/log/development.log +0 -0
  54. data/spec/rails2/log/production.log +0 -0
  55. data/spec/rails2/log/server.log +0 -0
  56. data/spec/rails2/log/test.log +785 -0
  57. data/spec/rails2/public/404.html +30 -0
  58. data/spec/rails2/public/422.html +30 -0
  59. data/spec/rails2/public/500.html +30 -0
  60. data/spec/rails2/public/favicon.ico +0 -0
  61. data/spec/rails2/public/images/rails.png +0 -0
  62. data/spec/rails2/public/index.html +275 -0
  63. data/spec/rails2/public/javascripts/application.js +2 -0
  64. data/spec/rails2/public/javascripts/controls.js +963 -0
  65. data/spec/rails2/public/javascripts/dragdrop.js +973 -0
  66. data/spec/rails2/public/javascripts/effects.js +1128 -0
  67. data/spec/rails2/public/javascripts/prototype.js +4320 -0
  68. data/spec/rails2/public/robots.txt +5 -0
  69. data/spec/rails2/script/about +4 -0
  70. data/spec/rails2/script/autospec +6 -0
  71. data/spec/rails2/script/console +3 -0
  72. data/spec/rails2/script/dbconsole +3 -0
  73. data/spec/rails2/script/destroy +3 -0
  74. data/spec/rails2/script/generate +3 -0
  75. data/spec/rails2/script/performance/benchmarker +3 -0
  76. data/spec/rails2/script/performance/profiler +3 -0
  77. data/spec/rails2/script/plugin +3 -0
  78. data/spec/rails2/script/runner +3 -0
  79. data/spec/rails2/script/server +3 -0
  80. data/spec/rails2/script/spec +10 -0
  81. data/spec/rails2/test/performance/browsing_test.rb +9 -0
  82. data/spec/rails2/test/test_helper.rb +38 -0
  83. data/spec/spec_helper.rb +27 -16
  84. data/spec/suite.sh +39 -0
  85. data/spec/unit/backtrace_spec.rb +62 -0
  86. data/spec/unit/black_box_spec.rb +3 -3
  87. data/spec/unit/configuration_spec.rb +29 -0
  88. data/spec/unit/errplane_spec.rb +24 -15
  89. data/specs.watchr +21 -0
  90. metadata +194 -90
  91. data/gemfiles/rails_2.3.gemfile +0 -6
  92. data/gemfiles/rails_2.3.gemfile.lock +0 -148
  93. data/gemfiles/rails_3.0.gemfile.lock +0 -148
  94. data/gemfiles/rails_3.1.gemfile.lock +0 -148
  95. data/gemfiles/rails_3.2.gemfile.lock +0 -121
  96. data/lib/errplane/rails/udp_logger.rb +0 -54
  97. data/lib/errplane/syslogproto.rb +0 -7
  98. data/lib/errplane/syslogproto/common.rb +0 -81
  99. data/lib/errplane/syslogproto/logger.rb +0 -24
  100. data/lib/errplane/syslogproto/packet.rb +0 -107
  101. data/lib/errplane/syslogproto/parser.rb +0 -51
  102. data/spec/internal/app/controllers/application_controller.rb +0 -2
  103. data/spec/internal/app/controllers/widgets_controller.rb +0 -9
  104. data/spec/internal/config/database.yml +0 -3
  105. data/spec/internal/config/routes.rb +0 -3
  106. data/spec/internal/db/combustion_test.sqlite +0 -0
  107. data/spec/internal/db/schema.rb +0 -3
  108. data/spec/internal/log/.gitignore +0 -1
data/lib/errplane.rb CHANGED
@@ -2,10 +2,14 @@ require 'net/http'
2
2
  require 'net/https'
3
3
  require 'rubygems'
4
4
 
5
+ require "json" unless Hash.respond_to?(:to_json)
6
+
5
7
  require "errplane/version"
8
+ require "errplane/logger"
6
9
  require "errplane/black_box"
7
10
  require "errplane/configuration"
8
11
  require "errplane/transmitter"
12
+ require "errplane/backtrace"
9
13
  require "errplane/rack"
10
14
 
11
15
  require "errplane/railtie" if defined? Rails::Railtie
@@ -13,6 +17,8 @@ require "errplane/sinatra" if defined? Sinatra::Request
13
17
 
14
18
  module Errplane
15
19
  class << self
20
+ include Logger
21
+
16
22
  attr_writer :configuration
17
23
  attr_accessor :transmitter
18
24
 
@@ -28,14 +34,14 @@ module Errplane
28
34
  def transmit_unless_ignorable(e, env)
29
35
  begin
30
36
  black_box = assemble_black_box_for(e, env)
31
- configuration.logger.info("\nTransmitter: #{transmitter.inspect}") if configuration.debug?
32
- configuration.logger.info("\nBlack Box: #{black_box.to_json}") if configuration.debug?
33
- configuration.logger.info("\nIgnorable Exception? #{ignorable_exception?(e)}") if configuration.debug?
34
- configuration.logger.info("\nEnvironment: #{ENV.to_hash}") if configuration.debug?
37
+ log :info, "Transmitter: #{transmitter.inspect}"
38
+ log :info, "Black Box: #{black_box.to_json}"
39
+ log :info, "Ignorable Exception? #{ignorable_exception?(e)}"
40
+ log :info, "Environment: #{ENV.to_hash}"
35
41
 
36
42
  transmitter.relay(black_box) unless ignorable_exception?(e)
37
43
  rescue => e
38
- configuration.logger.info("[Errplane] Something went terribly wrong. Exception failed to take off. 2-" + e.inspect)
44
+ configuration.logger.info("[Errplane] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}")
39
45
  end
40
46
  end
41
47
 
@@ -47,13 +53,12 @@ module Errplane
47
53
  assemble_black_box_for(e, env)
48
54
  end
49
55
 
50
- configuration.logger.info("\nTransmitter: #{transmitter.inspect}") if configuration.debug?
51
- configuration.logger.info("\nBlack Box: #{black_box.to_json}") if configuration.debug?
52
- configuration.logger.info("\nIgnorable Exception? #{ignorable_exception?(e)}") if configuration.debug?
53
- configuration.logger.info("\nEnvironment: #{ENV.to_hash}") if configuration.debug?
56
+ log :info, "Transmitter: #{transmitter.inspect}"
57
+ log :info, "Black Box: #{black_box.to_json}"
58
+ log :info, "Environment: #{ENV.to_hash}"
54
59
  transmitter.relay(black_box)
55
60
  rescue => e
56
- configuration.logger.info("[Errplane] Something went terribly wrong. Exception failed to take off. 1-" + e.inspect)
61
+ configuration.logger.info("[Errplane] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}")
57
62
  end
58
63
  end
59
64
 
@@ -0,0 +1,38 @@
1
+ module Errplane
2
+ class Backtrace
3
+ class Line
4
+ FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}.freeze
5
+
6
+ attr_reader :file
7
+ attr_reader :number
8
+ attr_reader :method
9
+
10
+ def initialize(line)
11
+ _, @file, @number, @method = line.match(FORMAT).to_a
12
+ end
13
+
14
+ def to_s
15
+ "#{file}:#{number} in `#{method}'"
16
+ end
17
+
18
+ def inspect
19
+ "<Line: #{to_s}>"
20
+ end
21
+ end
22
+
23
+ attr_reader :lines
24
+
25
+ def initialize(backtrace)
26
+ @lines = backtrace.each.collect do |line|
27
+ Errplane.configuration.backtrace_filters.each do |filter|
28
+ line = filter.call(line)
29
+ end
30
+ Line.new(line)
31
+ end
32
+ end
33
+
34
+ def inspect
35
+ "<Backtrace: " + lines.collect { |line| line.to_s }.join(", ") + ">"
36
+ end
37
+ end
38
+ end
@@ -7,6 +7,7 @@ module Errplane
7
7
  attr_reader :controller
8
8
  attr_reader :action
9
9
  attr_reader :request_url
10
+ attr_reader :user_agent
10
11
  attr_reader :custom_data
11
12
 
12
13
  def initialize(params = {})
@@ -16,11 +17,12 @@ module Errplane
16
17
  @controller = params[:controller]
17
18
  @action = params[:action]
18
19
  @request_url = params[:request_url]
20
+ @user_agent = params[:user_agent]
19
21
  @custom_data = params[:custom_data] || {}
20
22
  end
21
23
 
22
24
  def to_json
23
- paylaod = {
25
+ payload = {
24
26
  :time => Time.now.to_i,
25
27
  :application_name => Errplane.configuration.application_name,
26
28
  :application_root => Errplane.configuration.application_root,
@@ -38,10 +40,10 @@ module Errplane
38
40
 
39
41
  Errplane.configuration.add_custom_exception_data(self)
40
42
 
41
- paylaod[:request_data] = request_data if @controller || @action || !params.empty?
42
- paylaod[:hash] = hash if hash
43
+ payload[:request_data] = request_data if @controller || @action || !params.empty?
44
+ payload[:hash] = hash if hash
43
45
 
44
- paylaod.to_json
46
+ payload.to_json
45
47
  end
46
48
 
47
49
  def reporter
@@ -58,7 +60,8 @@ module Errplane
58
60
  :session_data => @session_data,
59
61
  :controller => @controller,
60
62
  :action => @action,
61
- :request_url => @request_url
63
+ :request_url => @request_url,
64
+ :user_agent => @user_agent
62
65
  }
63
66
  end
64
67
  end
@@ -1,5 +1,4 @@
1
1
  require 'errplane'
2
- require 'json'
3
2
 
4
3
  Capistrano::Configuration.instance(:must_exist).load do
5
4
  after 'deploy', 'deploy:notify_errplane'
@@ -6,7 +6,6 @@ module Errplane
6
6
  attr_accessor :application_id
7
7
  attr_accessor :application_name
8
8
  attr_accessor :application_root
9
- attr_accessor :syslogd_port
10
9
 
11
10
  attr_accessor :logger
12
11
  attr_accessor :rails_environment
@@ -16,16 +15,34 @@ module Errplane
16
15
  attr_accessor :language_version
17
16
  attr_accessor :ignored_exceptions
18
17
  attr_accessor :ignored_environments
18
+ attr_accessor :ignored_user_agents
19
+ attr_accessor :backtrace_filters
20
+
19
21
  attr_accessor :environment_variables
20
22
 
21
23
  attr_accessor :debug
24
+ attr_accessor :reraise_global_exceptions
22
25
 
23
26
  DEFAULTS = {
24
27
  :api_host => "api.errplane.com",
25
28
  :app_host => "app.errplane.com",
26
29
  :ignored_exceptions => %w{ActiveRecord::RecordNotFound
27
30
  ActionController::RoutingError},
28
- :ignored_environments => %w{development test cucumber selenium}
31
+ :ignored_environments => %w{development test cucumber selenium},
32
+ :ignored_user_agents => %w{GoogleBot},
33
+ :backtrace_filters => [
34
+ lambda { |line| line.gsub(/^\.\//, "") },
35
+ lambda { |line|
36
+ return line if Errplane.configuration.application_root.to_s.empty?
37
+ line.gsub(/#{Errplane.configuration.application_root}/, "[APP_ROOT]")
38
+ },
39
+ lambda { |line|
40
+ if defined?(Gem) && !Gem.path.nil? && !Gem.path.empty?
41
+ Gem.path.each { |path| line = line.gsub(/#{path}/, "[GEM_ROOT]") }
42
+ end
43
+ line
44
+ }
45
+ ]
29
46
  }
30
47
 
31
48
  def initialize
@@ -33,36 +50,27 @@ module Errplane
33
50
  @app_host = DEFAULTS[:app_host]
34
51
  @ignored_exceptions = DEFAULTS[:ignored_exceptions].dup
35
52
  @ignored_environments = DEFAULTS[:ignored_environments].dup
53
+ @ignored_user_agents = DEFAULTS[:ignored_user_agents].dup
54
+ @backtrace_filters = DEFAULTS[:backtrace_filters].dup
36
55
  @debug = false
56
+ @rescue_global_exceptions = false
37
57
  end
38
58
 
39
59
  def debug?
40
60
  !!@debug
41
61
  end
42
62
 
43
- def ignore_current_environment?
44
- self.ignored_environments.include?(self.rails_environment)
63
+ def reraise_global_exceptions?
64
+ !!@reraise_global_exceptions
45
65
  end
46
66
 
47
- def get_logport
48
- puts "Acquiring port information from errplane"
49
- http = initialize_http_connection
50
- response = begin
51
- url = "/api/v1/syslogds.txt?api_key=#{@api_key}"
52
- http.get(url)
53
- rescue Exception => e
54
- puts e
55
- end
56
-
67
+ def ignore_user_agent?(incoming_user_agent)
68
+ return false if self.ignored_user_agents.nil?
69
+ self.ignored_user_agents.any? {|agent| incoming_user_agent =~ /#{agent}/}
70
+ end
57
71
 
58
- case response
59
- when Net::HTTPSuccess
60
- # Success
61
- response.body
62
- else
63
- # Failure
64
- ""
65
- end
72
+ def ignore_current_environment?
73
+ self.ignored_environments.include?(self.rails_environment)
66
74
  end
67
75
 
68
76
  def define_custom_exception_data(&block)
@@ -50,16 +50,14 @@ class ErrplaneChefHandler < Chef::Handler
50
50
  end
51
51
 
52
52
  def setup_errplane
53
- raise ArgumentError.new("You must specify Errplane api key") unless api_key
53
+ raise ArgumentError.new("You must provide an Errplane API key") unless api_key
54
54
  Errplane.configure do |config|
55
55
  config.api_key = api_key
56
56
  config.application_id = "chef"
57
57
  config.application_name = "chef"
58
- # config.syslogd_port = "4445"
59
58
  config.logger = Chef::Log
60
- #config.logger = Logger.new(STDOUT)
61
59
  config.debug = false
62
60
  config.rails_environment = @environment
63
61
  end
64
62
  end
65
- end
63
+ end
@@ -0,0 +1,11 @@
1
+ module Errplane
2
+ module Logger
3
+ PREFIX = "[Errplane] "
4
+
5
+ private
6
+ def log(level, message)
7
+ return if level != :error && !Errplane.configuration.debug?
8
+ Errplane.configuration.logger.send(level, PREFIX + message) if Errplane.configuration.logger
9
+ end
10
+ end
11
+ end
@@ -7,7 +7,8 @@ module Errplane
7
7
  :session_data => errplane_session_data,
8
8
  :controller => params[:controller],
9
9
  :action => params[:action],
10
- :request_url => errplane_request_url
10
+ :request_url => errplane_request_url,
11
+ :user_agent => request.env["HTTP_USER_AGENT"]
11
12
  }
12
13
  end
13
14
 
@@ -9,8 +9,11 @@ module Errplane
9
9
  def render_exception_with_errplane(env, e)
10
10
  controller = env["action_controller.instance"]
11
11
  Errplane.configuration.logger.info("Controller: #{controller}")
12
- Errplane.configuration.logger.info("Request Data: #{controller.try(:errplane_request_data)}")
13
- Errplane.transmit_unless_ignorable(e, controller.try(:errplane_request_data))
12
+ request_data = controller.try(:errplane_request_data) || {}
13
+ Errplane.configuration.logger.info("Request Data: #{request_data}")
14
+ unless Errplane.configuration.ignore_user_agent?(request_data[:user_agent])
15
+ Errplane.transmit_unless_ignorable(e, request_data)
16
+ end
14
17
  render_exception_without_errplane(env, e)
15
18
  end
16
19
  end
@@ -11,11 +11,6 @@ module Errplane
11
11
  exit
12
12
  end
13
13
 
14
- Errplane.configuration.syslogd_port = Errplane.configuration.get_logport
15
- if(Errplane.configuration.syslogd_port && Errplane.configuration.syslogd_port.to_s != "")
16
- require 'errplane/rails/udp_logger'
17
- end
18
-
19
14
  Errplane.configure do |config|
20
15
  config.ignored_environments = []
21
16
  end
@@ -80,10 +75,6 @@ module Errplane
80
75
  config.framework_version = ::Rails::VERSION::STRING
81
76
  end
82
77
 
83
- if(Errplane.configuration.syslogd_port && Errplane.configuration.syslogd_port.to_s != "")
84
- require 'errplane/rails/udp_logger'
85
- end
86
-
87
78
  ActiveSupport.on_load(:action_controller) do
88
79
  require 'errplane/rails/air_traffic_controller'
89
80
  include Errplane::Rails::AirTrafficController
@@ -1,5 +1,16 @@
1
1
  module Errplane
2
2
  class Transmitter
3
+ include Errplane::Logger
4
+
5
+ HTTP_ERRORS = [ EOFError,
6
+ Errno::ECONNREFUSED,
7
+ Errno::ECONNRESET,
8
+ Errno::EINVAL,
9
+ Net::HTTPBadResponse,
10
+ Net::HTTPHeaderSyntaxError,
11
+ Net::ProtocolError,
12
+ Timeout::Error ].freeze
13
+
3
14
  def initialize(params = {})
4
15
  end
5
16
 
@@ -8,20 +19,17 @@ module Errplane
8
19
  data = black_box.to_json
9
20
  response = begin
10
21
  url = "/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/#{Errplane.configuration.rails_environment}#{"/deploy" if deployment}?api_key=#{Errplane.configuration.api_key}"
11
- Errplane.configuration.logger.info("\nURL: #{url}") if Errplane.configuration.debug?
12
- Errplane.configuration.logger.info("\nData: #{data.inspect}") if Errplane.configuration.debug?
13
- response = http.post(url, data)
14
- Errplane.configuration.logger.info("\nException Response: #{response.inspect}") if Errplane.configuration.debug?
15
- response
16
- rescue Exception => e
17
- # e
22
+ log :info, "URL: #{url}"
23
+ log :info, "Data: #{data.inspect}"
24
+ http.post(url, data)
25
+ rescue *HTTP_ERRORS => e
26
+ log :error, "HTTP error contacting Errplane API! #{e.class}: #{e.message}"
18
27
  end
19
28
 
20
- case response
21
- when Net::HTTPSuccess
22
- # Success
29
+ if response.is_a?(Net::HTTPSuccess)
30
+ log :info, "Request Succeeded: #{response.inspect}"
23
31
  else
24
- # Failure
32
+ log :error, "Request Failed: #{response.inspect}"
25
33
  end
26
34
  end
27
35
 
@@ -1,3 +1,3 @@
1
1
  module Errplane
2
- VERSION = "0.3.7"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,7 +1,4 @@
1
1
  Errplane.configure do |config|
2
2
  config.api_key = "<%= api_key %>"
3
3
  config.application_id = "<%= application_id %>"
4
- #uncomment this if you want to push rails logs to errplane also
5
- #config.syslogd_port = "<%= Errplane.configuration.get_logport %>"
6
4
  end
7
-
@@ -0,0 +1,38 @@
1
+ RAILS_ROOT = File.dirname(__FILE__)
2
+
3
+ module Rails
4
+ class << self
5
+ def vendor_rails?; return false; end
6
+ end
7
+ end
8
+
9
+ Rails::Initializer.run do |config|
10
+ # config.time_zone = 'UTC'
11
+ # config.cache_classes = true
12
+ # config.whiny_nils = true
13
+ # config.action_controller.consider_all_requests_local = true
14
+ # config.action_controller.perform_caching = false
15
+ # config.action_view.cache_template_loading = true
16
+ # config.action_controller.allow_forgery_protection = false
17
+ # config.action_mailer.delivery_method = :test
18
+ config.frameworks = [ :action_controller, :active_resource ]
19
+ config.action_controller.session = { :key => "_myapp_session", :secret => "1234567890abcdef1234567890abcdef" }
20
+ end
21
+
22
+ ActionController::Base.cookie_verifier_secret = '1234567890abcdef1234567890abcdef'
23
+ ActionController::Base.session = {
24
+ :key => '_myapp_session',
25
+ :secret => '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
26
+ }
27
+
28
+ Errplane.configure do |config|
29
+ config.api_key = "f123-e456-d789c012"
30
+ config.application_id = "b12r8c72"
31
+ config.ignored_environments = []
32
+ end
33
+
34
+ class ApplicationController < ActionController::Base; end
35
+ class WidgetsController < ApplicationController
36
+ def index; render :nothing => true; end
37
+ def new; return 1/0; end
38
+ end
@@ -15,9 +15,6 @@ end
15
15
  Errplane.configure do |config|
16
16
  config.api_key = "f123-e456-d789c012"
17
17
  config.application_id = "b12r8c72"
18
- config.logger = Logger.new(STDOUT)
19
- config.debug = true
20
- config.ignored_environments = []
21
18
  end
22
19
 
23
20
  class ApplicationController < ActionController::Base; end
@@ -1,24 +1,42 @@
1
- require File.dirname(__FILE__) + "/integration_helper"
1
+ require File.expand_path(File.dirname(__FILE__) + "/integration_helper")
2
2
 
3
- feature "exception handling" do
3
+ describe "exception handling" do
4
4
  before do
5
5
  Errplane.configure do |config|
6
6
  config.ignored_environments = %w{development}
7
7
  end
8
+
9
+ FakeWeb.last_request = nil
10
+ FakeWeb.clean_registry
11
+ @request_path = "/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
12
+ @request_url = "http://api.errplane.com#{@request_path}"
13
+ FakeWeb.register_uri(:post, @request_url, :body => "", :status => ["200", "OK"])
8
14
  end
9
15
 
10
16
  describe "in an action that raises an exception" do
11
- scenario "should make an HTTP call to the API" do
12
- stub_request(:post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012").to_return(status: 200)
13
- visit new_widget_path
14
- assert_requested :post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
17
+ it "should make an HTTP call to the API" do
18
+ get "/widgets/new"
19
+ FakeWeb.last_request.should_not be_nil
20
+ FakeWeb.last_request.path.should == @request_path
21
+ FakeWeb.last_request.method.should == "POST"
15
22
  end
16
23
  end
17
24
 
18
25
  describe "in an action that does not raise an exception" do
19
- scenario "should not make an HTTP call to the API" do
20
- visit widgets_path
21
- assert_not_requested :post, "#{Errplane.configuration.api_host}/api/v1/applications/#{Errplane.configuration.application_id}/exceptions/test?api_key=f123-e456-d789c012"
26
+ it "should not make an HTTP call to the API" do
27
+ get "/widgets"
28
+ FakeWeb.last_request.should be_nil
29
+ end
30
+ end
31
+
32
+ describe "for an ignored user agent" do
33
+ it "should not make an HTTP call to the API" do
34
+ Errplane.configure do |config|
35
+ config.ignored_user_agents = %w{Googlebot}
36
+ end
37
+ get "/widgets/new", {}, { "HTTP_USER_AGENT" => "Googlebot/2.1" }
38
+ FakeWeb.last_request.should be_nil
22
39
  end
23
40
  end
24
41
  end
42
+