<commit_before>require 'webmock/rspec'
require_relative 'support/helper'
require 'courtfinder/client'

describe Courtfinder::Client::HousingPossession do
  before { WebMock.disable_net_connect! }

  let(:result) do
    [{ "name" => "Cambridge County Court and Family Court",
       "address" =>
       { "town" => "Cambridge",
         "address_lines" =>
         ["Cambridge County Court and Family Court Hearing Centre",
          "197 East Road"],
         "type" => "Postal",
         "postcode" => "CB1 1BA",
         "county" => "Cambridgeshire"
       }
     }]
  end
  let(:client) { Courtfinder::Client::HousingPossession.new }

  def full_url postcode
    "#{Courtfinder::SERVER}#{Courtfinder::Client::HousingPossession::PATH}#{postcode}"
  end

  def stub_with postcode
    stub_request(:get, full_url(postcode))
      .to_return(:body => fixture('result.json'),
                 :headers => {:content_type => 'application/json; charset=utf-8'})
  end

  def blank_result postcode
    stub_request(:get, full_url(postcode))
      .to_return(:status => 200,
                 :body => '[]',
                 :headers => {})
  end

  describe '.get' do
    before { stub_with postcode }

    context 'when given postcode with no spaces' do
      let(:postcode) { 'sg80lt' }

      it 'should return the court address' do
        expect(client.get(postcode)).to eql result
      end
    end

    context 'when given postcode with spaces' do
      let(:postcode) { 'SG8 0LT' }

      it 'should return the court address' do
        expect(client.get(postcode)).to eql result
      end
    end

    context 'when invalid postcode is provided' do
      let(:postcode) { 'fake' }
      before { blank_result postcode }

      it 'should return an error' do
        expect(client.get(postcode)).to eql []
      end
    end<commit_msg>Updated an example description<commit_after>require 'webmock/rspec'
require_relative 'support/helper'
require 'courtfinder/client'

describe Courtfinder::Client::HousingPossession do
  before { WebMock.disable_net_connect! }

  let(:result) do
    [{ "name" => "Cambridge County Court and Family Court",
       "address" =>
       { "town" => "Cambridge",
         "address_lines" =>
         ["Cambridge County Court and Family Court Hearing Centre",
          "197 East Road"],
         "type" => "Postal",
         "postcode" => "CB1 1BA",
         "county" => "Cambridgeshire"
       }
     }]
  end
  let(:client) { Courtfinder::Client::HousingPossession.new }

  def full_url postcode
    "#{Courtfinder::SERVER}#{Courtfinder::Client::HousingPossession::PATH}#{postcode}"
  end

  def stub_with postcode
    stub_request(:get, full_url(postcode))
      .to_return(:body => fixture('result.json'),
                 :headers => {:content_type => 'application/json; charset=utf-8'})
  end

  def blank_result postcode
    stub_request(:get, full_url(postcode))
      .to_return(:status => 200,
                 :body => '[]',
                 :headers => {})
  end

  describe '.get' do
    before { stub_with postcode }

    context 'when given postcode with no spaces' do
      let(:postcode) { 'sg80lt' }

      it 'should return the court address' do
        expect(client.get(postcode)).to eql result
      end
    end

    context 'when given postcode with spaces' do
      let(:postcode) { 'SG8 0LT' }

      it 'should return the court address' do
        expect(client.get(postcode)).to eql result
      end
    end

    context 'when invalid postcode is provided' do
      let(:postcode) { 'fake' }
      before { blank_result postcode }

      it 'should return a blank array' do
        expect(client.get(postcode)).to eql []
      end
    end
{'fraction_non_alphanumeric': 0.12236058473199783, 'fraction_numerical': 0.007038440714672442, 'mean_word_length': 2.6766169154228856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4968776', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1098, 'n_words': 291}