test/unit/worker_test.rb in sanford-0.3.0 vs test/unit/worker_test.rb in sanford-0.4.0

- old
+ new

@@ -22,11 +22,11 @@ class BaseTest < SetupContextToRaiseExceptions include Sanford::Protocol::Test::Helpers desc "Sanford::Worker" setup do - @host_data = Sanford::HostData.new(TestHost) + @host_data = Sanford::HostData.new(TestHost).tap{|hd| hd.setup } @connection = FakeConnection.with_request('version', 'service', {}) @worker = Sanford::Worker.new(@host_data, @connection) end subject{ @worker } @@ -186,9 +186,27 @@ response = @connection.response assert_equal 987, response.status.code assert_equal "custom error!", response.status.message assert_equal nil, response.data + end + + end + + class WithBadResponseHashTest < BaseTest + desc "running a request that builds an object that can't be encoded" + setup do + @connection = FakeConnection.with_request('v1', 'echo', { :message => 'cant encode' }, true) + @worker = Sanford::Worker.new(@host_data, @connection) + end + + should "return the response that was halted" do + assert_raises(RuntimeError){ @worker.run } + response = @connection.response + + assert_equal 500, response.status.code + assert_equal "An unexpected error occurred.", response.status.message + assert_equal nil, response.data end end end