Sha256: 5b65fe2966886104b26aaf12138c12d495165f4dd4b3d179c3ed5156f61c7f6a

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe 'expect_json_types' do
  it 'should detect current type' do
    mock_get('simple_get')
    get '/simple_get'
    expect_json_types(name: :string, age: :int)
  end

  it 'should fail when incorrect json types tested' do
    mock_get('simple_get')
    get '/simple_get'
    expect { expect_json_types(bad: :bool) }.to raise_error(ExpectationNotMetError)
  end

  it 'should not fail when optional property is not present' do
    mock_get('simple_get')
    get '/simple_get'
    expect_json_types(name: :string, age: :int, optional: :bool_or_null)
  end

  it 'should allow full object graph' do
    mock_get('simple_path_get')
    get '/simple_path_get'
    expect_json_types({name: :string, address: { street: :string, city: :string, state: :string }})
  end

  it 'should check all types in a simple array' do
    mock_get('array_of_values')
    get '/array_of_values'
    expect_json_types(grades: :array_of_ints)
  end

  it 'should ensure all valid types in a simple array' do
    mock_get('array_of_values')
    get '/array_of_values'
    expect { expect_json_types(bad: :array_of_ints) }.to raise_error(ExpectationNotMetError)
  end

  it 'should allow empty array' do
    mock_get('array_of_values')
    get '/array_of_values'
    expect_json_types(emptyArray: :array_of_ints)
  end

  it 'should be able to test for a nil type' do
    mock_get('simple_get')
    get '/simple_get'
    expect_json_types(name: :string, age: :int, address: :null)
  end

  it 'Should throw bad type error' do
    mock_get('simple_get')
    get '/simple_get'
    expect { expect_json_types(name: :foo) }.to raise_error(ExpectationError, "Expected type foo\nis an invalid type")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
airborne-0.2.3 spec/airborne/expectations/expect_json_types_spec.rb
airborne-0.2.2 spec/airborne/expectations/expect_json_types_spec.rb
airborne-0.2.1 spec/airborne/expectations/expect_json_types_spec.rb
airborne-0.2.0 spec/airborne/expectations/expect_json_types_spec.rb