<commit_before>require 'spec_helper'

describe Image do
  it { should have_and_belong_to_many(:templates) }
  it { should respond_to :is_official }
  it { should respond_to :is_trusted }
  it { should respond_to :star_count }

  describe '.search_remote_index' do

    let(:query) { { term: 'some_term' } }

    let(:remote_image) do
      double(:remote_image,
        id: 'foo/bar',
        info: { description: 'fizz', is_official: true, is_trusted: true })
    end

    before do
      Docker::Image.stub(:search).and_return([remote_image])
    end

    it 'searches the remote Docker index' do
      Docker::Image.should_receive(:search).with(query).and_return([remote_image])
      Image.search_remote_index(query)
    end

    it 'returns a list of Image models' do
      images = Image.search_remote_index(query)

      expect(images).to be_kind_of(Array)
      expect(images).to have(1).items
      expect(images.first.repository).to eql(remote_image.id)
    end
  end

  describe '.all_local' do

    let(:local_image) do
      double(:local_image,
        info: { 'RepoTags' => ['foo/bar'] })
    end

    before do
      Docker::Image.stub(:all).and_return([])
    end

    it 'searches the local Docker index' do
      Docker::Image.should_receive(:all).and_return([])
      Image.all_local<commit_msg>Switching should_receive to expect syntax<commit_after>require 'spec_helper'

describe Image do
  it { should have_and_belong_to_many(:templates) }
  it { should respond_to :is_official }
  it { should respond_to :is_trusted }
  it { should respond_to :star_count }

  describe '.search_remote_index' do

    let(:query) { { term: 'some_term' } }

    let(:remote_image) do
      double(:remote_image,
        id: 'foo/bar',
        info: { description: 'fizz', is_official: true, is_trusted: true })
    end

    before do
      Docker::Image.stub(:search).and_return([remote_image])
    end

    it 'searches the remote Docker index' do
      expect(Docker::Image).to receive(:search).with(query).and_return([remote_image])
      Image.search_remote_index(query)
    end

    it 'returns a list of Image models' do
      images = Image.search_remote_index(query)

      expect(images).to be_kind_of(Array)
      expect(images).to have(1).items
      expect(images.first.repository).to eql(remote_image.id)
    end
  end

  describe '.all_local' do

    let(:local_image) do
      double(:local_image,
        info: { 'RepoTags' => ['foo/bar'] })
    end

    before do
      Docker::Image.stub(:all).and_return([])
    end

    it 'searches the local Docker index' do
      expect(Docker::Image).to receive(:all).and_return([])
      Image.all_local
{'fraction_non_alphanumeric': 0.11852963240810202, 'fraction_numerical': 0.0007501875468867217, 'mean_word_length': 3.22662440570523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2328389', 'n_tokens_mistral': 891, 'n_tokens_neox': 861, 'n_words': 193}