Sha256: 0fb65df026440eaee6b6d6e417058d3c1d91c3da079cfa794d4bf8a4869df876

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'
require 'goliath/rack/validation_error'

describe Goliath::Rack::ValidationError do
  it 'accepts an app' do
    lambda { Goliath::Rack::ValidationError.new('my app') }.should_not raise_error
  end

  describe 'with middleware' do
    before(:each) do
      @app = mock('app').as_null_object
      @ve = Goliath::Rack::ValidationError.new(@app)
    end

    it 'returns the apps status' do
      app_headers = {'Content-Type' => 'mine'}
      app_body = {'a' => 'b'}
      @app.should_receive(:call).and_return([200, app_headers, app_body])

      status, headers, body = @ve.call({})
      status.should == 200
      headers.should == app_headers
      body.should == app_body
    end

    it 'catches Goliath::Validation::Error' do
      @app.should_receive(:call).and_raise(Goliath::Validation::Error.new(401, 'my error'))
      lambda { @ve.call({}) }.should_not raise_error(Goliath::Validation::Error)
    end

    it 'returns an error response on exception' do
      @app.should_receive(:call).and_raise(Goliath::Validation::Error.new(401, 'my error'))
      status, headers, body = @ve.call({})

      status.should == 401
      headers.should == {}
      body.should == {:error => 'my error'}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
goliath-0.9.1 spec/unit/rack/validation_error_spec.rb