Sha256: b04241965ce656c34b438f5553b596009fd658157d9c49085433090548d73fc3
Contents?: true
Size: 1.1 KB
Versions: 4
Compression:
Stored size: 1.1 KB
Contents
require 'spec_helper' require 'napa/grape_extensions/error_formatter' describe Grape::ErrorFormatter::Json do context '#call' do it 'returns an api_error for plain error messages' do error = Grape::ErrorFormatter::Json.call('test message', nil) parsed = JSON.parse(error) expect(parsed['error']['code']).to eq('api_error') expect(parsed['error']['message']).to eq('test message') end it 'returns a specified error when given a Napa::JsonError object' do json_error = Napa::JsonError.new(:foo, 'bar') error = Grape::ErrorFormatter::Json.call(json_error, nil) parsed = JSON.parse(error) expect(parsed['error']['code']).to eq('foo') expect(parsed['error']['message']).to eq('bar') end it 'adds the backtrace with rescue_option[:backtrace] specified' do error = Grape::ErrorFormatter::Json.call('', 'backtrace', rescue_options: {backtrace: true}) parsed = JSON.parse(error) expect(parsed['backtrace']).to eq('backtrace') end end end
Version data entries
4 entries across 4 versions & 1 rubygems