Sha256: e7b04e21cd0b96b96cb2ac487a14acc53c6760b3394ebc41540cb85199e0cf94

Contents?: true

Size: 1020 Bytes

Versions: 4

Compression:

Stored size: 1020 Bytes

Contents

require 'json'
require 'sinatra'

class SampleApp < Sinatra::Application
  before do
    content_type 'application/json'
  end

  get '/' do
    { foo: 'bar' }.to_json
  end
end

Airborne.configure do |config|
  config.rack_app = SampleApp
end

describe 'rack app' do
  it 'should allow requests against a sinatra app' do
    get '/'
    expect_json_types(foo: :string)
  end

  it 'should ensure correct values from sinatra app' do
    get '/'
    expect { expect_json_types(foo: :int) }.to raise_error
  end

  it 'Should set json_body even when not using the airborne http requests' do
    Response = Struct.new(:body, :headers)
    @response = Response.new({ foo: 'bar' }.to_json)
    expect(json_body).to eq(foo: 'bar')
  end

  it 'Should work with consecutive requests' do
    Response = Struct.new(:body, :headers)
    @response = Response.new({ foo: 'bar' }.to_json)
    expect(json_body).to eq(foo: 'bar')

    @response = Response.new({ foo: 'boo' }.to_json)
    expect(json_body).to eq(foo: 'boo')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
airborne-0.1.20 spec/airborne/rack/rack_sinatra_spec.rb
airborne-0.1.19 spec/airborne/rack/rack_sinatra_spec.rb
airborne-0.1.18 spec/airborne/rack/rack_sinatra_spec.rb
airborne-0.1.17 spec/airborne/rack/rack_sinatra_spec.rb