Sha256: 8f683ed014a06ce4e3ad09735c7097b271514ef499ee33572d78df056d2171cb

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe 'expect_json' do
	it 'should ensure correct json values' do
		mock_get('simple_get')
		get '/simple_get'
		expect_json({name: "Alex", age: 32 })
	end

	it 'should fail when incorrect json is tested' do
		mock_get('simple_get')
		get '/simple_get'
		expect{expect_json({bad: "data"})}.to raise_error		
	end
	
	it 'should allow simple path and verify only that path' do
		mock_get('simple_path_get')
		get '/simple_path_get'
		expect_json('address', {street: "Area 51", city: "Roswell", state: "NM"})
	end
	
	it 'should allow full object graph' do
		mock_get('simple_path_get')
		get '/simple_path_get'
		expect_json({name: "Alex", address: {street: "Area 51", city: "Roswell", state: "NM"}})
	end

	it 'should allow nested paths' do
		mock_get('simple_nested_path')
		get '/simple_nested_path'
		expect_json('address.coordinates', {lattitude: 33.3872, longitutde: 104.5281} )		
	end

	it 'should index into array and test against specific element' do 
		mock_get('array_with_index')
		get '/array_with_index'
		expect_json('cars.0', {make: "Tesla", model: "Model S"})
	end
	
	it 'should test against all elements in the array' do 
		mock_get('array_with_index')
		get '/array_with_index'
		expect_json('cars.?', {make: "Tesla", model: "Model S"})
		expect_json('cars.?', {make: "Lamborghini", model: "Aventador"})
	end

	it 'should invoke proc passed in' do
		mock_get('simple_get')
		get '/simple_get'
		expect_json({name: -> (name){expect(name.length).to eq(4)}})
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
airborne-0.0.19 spec/airborne/expect_json_spec.rb