<commit_before># encoding: UTF-8

require "spec_helper"

describe "WeatherHacker::Client" do
  before do
    @client = WeatherHacker::Client.new
    @zipcode = "690-0261"
  end

  describe "#get_weather" do
    before do
      @result = @client.get_weather(@zipcode)
    end

    it "get parsed weather data in Hash" do
      [Hash, NilClass].should be_include @result.class
    end

    it "has weather" do
      @result["weather"].should =~ /[晴曇雨]/
    end

    it "has max and min temperature" do
      @result["temperature"].has_key?("max").should be_true
      @result["temperature"].has_key?("min").should be_true
    end
  end

  describe "#update_area_table" do
    it "has not table before call" do
      @client.instance_variable_get(:@id_by_city).should be_nil
      @client.instance_variable_get(:@pref_by_city).should be_nil
    end

    it "has area table after call" do
      @client.send(:update_area_table)
      @client.send(:id_by_city).keys.size.should_not == 0
      @client.send(:pref_by_city).keys.size.should_not == 0
    end
  end

  describe "#city_id_by_zipcode" do
    it "return city_id" do
      city_id = @client.send(:city_id_by_zipcode, @zipcode)
      city_id.should be_kind_of Integer
    end
  end
end<commit_msg>Refacor: abstract specs to DRY<commit_after># encoding: UTF-8

require "spec_helper"

describe "WeatherHacker::Client" do
  before do
    @client = WeatherHacker::Client.new
    @zipcode = "690-0261"
  end

  describe "#get_weather" do
    before do
      @result = @client.get_weather(@zipcode)
    end

    it "get parsed weather data in Hash" do
      [Hash, NilClass].should be_include @result.class
    end

    it "has weather" do
      @result["weather"].should =~ /[晴曇雨]/
    end

    it "has max and min temperature" do
      @result["temperature"].has_key?("max").should be_true
      @result["temperature"].has_key?("min").should be_true
    end
  end

  shared_examples_for "having area table" do
    it "has area table" do
      @client.send(:id_by_city).keys.size.should_not == 0
      @client.send(:pref_by_city).keys.size.should_not == 0
    end
  end

  shared_examples_for "not having area table" do
    it "has not area table" do
      @client.instance_variable_get(:@id_by_city).should be_nil
      @client.instance_variable_get(:@pref_by_city).should be_nil
    end
  end

  describe "#id_by_city" do
    context "before call" do
      it_behaves_like "not having area table"
    end

    context "after call" do
      before { @client.send(:id_by_city) }
      it_behaves_like "having area table"
    end
  end

  describe "#pref_by_city" do
    context "before call" do
      it_behaves_like "not having area table"
    end

    context "after call" do
      before { @client.send(:pref_by_city) }
      it_behaves_like "having area table"
    end
  end

  describe "#city_id_by_zipcode" do
    it "return city_id" do
      city_id = @client.send(:city_id_by_zipcode, @zipcode)
      city_id.should be_kind_of Integer
    end
  end

  describe "#id_by_pref" do
    it "is cached in instance variable" do
      @client.instance_variable_get(:@id_by_pref).should be_nil
      @client.send(:id_by_pref)
      @client.instance_variable_get(:@id_by_pref).should be_kind_of Hash

      @client.should_not_receive(:pref_by_city)
      @client.send(:id_by_pref)
    end

    it "return table of id by pref" do
      @client.send(:id_by_pref).should be_kind_of Hash
    end
  end

  describe "#parse_area_table" do
    context "when passed malformed hash response" do
      it do
        expect {
          @client.send(:parse_area_table, {:unexpected => :hash})
        }.to raise_error(WeatherHacker::Client::ParseError)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10261244276865068, 'fraction_numerical': 0.00538647993536224, 'mean_word_length': 3.0768386388583973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4421279', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1245, 'n_words': 313}