Sha256: 2e22abe134624b453842c411223ba773a06b36913ea9927be6d3c49c5a9b83df

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

describe APIMatchers::ResponseBody::HaveJson do
  describe "actual.should have_json" do
    context 'when pass' do
      it 'equal json' do
        ['Petshop', 'Dogs'].to_json.should have_json(['Petshop', 'Dogs'])
      end

      it 'compares with Hash too' do
        { 'offers' => [10, 90] }.to_json.should have_json({ 'offers' => [10,90] })
      end
    end

    context 'when fails' do
      it 'different json' do
        expect {
          ['Petshop', 'Cats'].to_json.should have_json(['Petshop', 'Dogs'])
        }.to fail_with(%Q{expect to have json: '["Petshop","Cats"]'. Got: '["Petshop", "Cats"]'.})
      end
    end
  end

  describe "actual.should_not have_json" do
    context 'when pass' do
      it 'different json' do
        ['Petshop', 'Cats'].to_json.should_not have_json(['Petshop', 'Dogs'])
      end
    end

    context 'when fails' do
      it 'equal json' do
        expect {
          ['Petshop', 'Cats'].to_json.should_not have_json(['Petshop', 'Cats'])
        }.to fail_with(%Q{expect to NOT have json: '["Petshop","Cats"]'.})
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
api_matchers-0.4.0 spec/api_matchers/response_body/have_json_spec.rb