Sha256: 2d433f7f52a0058bb21e6fc7ed4c4edf8fa57985bbdc6c2b8cbb00b47e49baf1

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

require 'spec_helper'

module APIMatchers::Core
  describe FindInJSON do
    describe "#find" do
      context 'when node exists' do
        it "should return the value of the expected key" do
          FindInJSON.new('product' => 'gateway').find(node: 'product').should eql 'gateway'
        end

        it "should return the value of the deep expected key in the json" do
          FindInJSON.new('transaction' => { 'error' => { 'code' => '999' } }).find(node: 'code').should eql '999'
        end
      end

      context 'when node do not exists' do
        it "should return nil if don't find the expected node" do
          expect{ FindInJSON.new('product' => 'pabx').find(node: 'developers').should raise_error( ::APIMatchers::Core::Exceptions::KeyNotFound ) }
        end

        it "should return nil if don't find the expected node in the deep JSON" do
          expect{ FindInJSON.new('transaction' => { 'id' => 150, 'error' => {} }).find(node: 'code').should raise_error( ::APIMatchers::Core::Exceptions::KeyNotFound ) }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
api_matchers-0.4.0 spec/api_matchers/core/find_in_json_spec.rb
api_matchers-0.3.0 spec/api_matchers/core/find_in_json_spec.rb
api_matchers-0.2.0 spec/api_matchers/core/find_in_json_spec.rb
api_matchers-0.1.1 spec/api_matchers/core/find_in_json_spec.rb