Sha256: fbbfe8e617d592a2f8db4b42e1f876f83d7cd7380f2f87d565195923fcd780ec
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
require 'spec_helper' require 'service_template/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 ServiceTemplate::JsonError object' do json_error = ServiceTemplate::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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
service_template-0.5.0 | spec/grape_extensions/error_formatter_spec.rb |