Sha256: 2e753f8944354fcd96af931b304256b9841b4649a411fa57d85c9e5f775e4bff

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'
require 'goliath/rack/formatters/plist'

describe Goliath::Rack::Formatters::PLIST do
  # this sucks, but I had install problems with nokogiri-plist
  # and I would rather not use an alternative library that requires libxml or rexml
  before(:all) do
    class Object
      def to_plist(*args) "plist: #{to_s}" end
    end
  end

  after(:all) do
    class Object
      undef to_plist
    end
  end

  it 'accepts an app' do
    expect { Goliath::Rack::Formatters::PLIST.new('my app') }.not_to raise_error
  end

  describe 'with a formatter' do
    before(:each) do
      @app = double('app').as_null_object
      @m = Goliath::Rack::Formatters::PLIST.new(@app)
    end

    it 'formats the body into plist if content-type is plist' do
      expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/x-plist'}, {:a => 1, :b => 2}])

      status, header, body = @m.call({})
      expect(body).to eq(["plist: {:a=>1, :b=>2}"])
    end

    it "doesn't format to plist if the type is not plist" do
      expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
      status, header, body = @m.call({})
      expect(status).to eq(200)
      expect(header).to eq({'Content-Type' => 'application/xml'})

      expect(body[:a]).to eq(1)
    end

    it 'returns the status and headers' do
      expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])

      status, header, body = @m.call({})
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
goliath-1.0.7 spec/unit/rack/formatters/plist_spec.rb
goliath-1.0.6 spec/unit/rack/formatters/plist_spec.rb