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
    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
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
Add one more spec to test Hash against have_json matcher
Add one more spec to test Hash against have_json matcher