Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Added tests for Hoptoad session handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Apr 9, 2009
1 parent e292e3b commit 1cde635
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/controller_test.rb
@@ -1,5 +1,23 @@
require File.dirname(__FILE__) + '/helper'

def expect_session_data_for(controller)
# NOTE: setting expectations on the controller is not a good idea here,
# because the controller is the unit we're trying to test. However, as all
# exception-related behavior is mixed into the controller itsef, we have
# little choice. Delegating notifier methods from the controller to a
# Sender could make this easier to maintain and test.

@controller.expects(:send_to_hoptoad).with do |params|
assert params.respond_to?(:to_hash), "The notifier needs a hash"
notice = params[:notice]
assert_not_nil notice, "No notice passed to the notifier"
assert_not_nil notice[:session][:key], "No session key was set"
assert_not_nil notice[:session][:data], "No session data was set"
true
end
@controller.stubs(:rescue_action_in_public_without_hoptoad)
end

def should_notify_normally
should "have inserted its methods into the controller" do
assert @controller.methods.include?("inform_hoptoad")
Expand Down Expand Up @@ -79,6 +97,15 @@ def should_notify_normally

assert_equal(:serializable_data, @controller.send(:clean_notice, raw_notice))
end

should "send session data to hoptoad when the session has @data" do
expect_session_data_for(@controller)
@request = ActionController::TestRequest.new
@request.action = 'do_raise'
@request.session.instance_variable_set("@data", { :message => 'Hello' })
@response = ActionController::TestResponse.new
@controller.process(@request, @response)
end
end

def should_auto_include_catcher
Expand Down

0 comments on commit 1cde635

Please sign in to comment.