<commit_before>require "spec_helper"
require "fileutils"
require "webmock/rspec"

module Photomosaic
  describe ImageDownloader do
    let(:tmpdir) do
      File.expand_path("../tmp", File.dirname(__FILE__))
    end

    let(:downloader) do
      described_class.new(tmpdir)
    end

    describe "#download_images" do
      let(:image_list) do
        [
         "http://example.com/image01.jpg",
         "http://example.com/image02.jpg",
         "http://example.com/notfound.jpg"
        ]
      end

      before do
        stub_request(:get, %r(http://example\.com/image0\d\.jpg))
          .to_return(status: 200, body: "hoge")<commit_msg>Ensure to create instance with the specified directory<commit_after>require "spec_helper"
require "fileutils"
require "webmock/rspec"

module Photomosaic
  describe ImageDownloader do
    let(:tmpdir) do
      File.expand_path("../tmp", File.dirname(__FILE__))
    end

    let(:downloader) do
      described_class.new(tmpdir)
    end

    describe "#initialize" do
      context "with save directory" do
        it "should set the specified directory to @save_dir" do
          downloader = described_class.new(tmpdir)
          expect(downloader.instance_variable_get(:@save_dir)).to eq tmpdir
        end
      end

      context "without save directory" do
        it "should set temporary directory to @save_dir" do
          downloader = described_class.new
          expect(downloader.instance_variable_get(:@save_dir)).to match(/photomosaic/)
        end
      end
    end

    describe "#download_images" do
      let(:image_list) do
        [
         "http://example.com/image01.jpg",
         "http://example.com/image02.jpg",
         "http://example.com/notfound.jpg"
        ]
      end

      before do
        stub_request(:get, %r(http://example\.com/image0\d\.jpg))
          .to_return(status: 200, body: "hoge")
{'fraction_non_alphanumeric': 0.11548696114954764, 'fraction_numerical': 0.008515167642362959, 'mean_word_length': 2.4814814814814814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7475013', 'n_tokens_mistral': 591, 'n_tokens_neox': 569, 'n_words': 124}