<commit_before># encoding: utf-8

require 'spec_helper'

describe SQL::Fuzzer, '#each' do
  subject { described_class.new(ast) }

  let(:ast) { stub('ast').as_null_object }

  before do
    ast.should_receive(:to_ast)
  end

  context 'with a block' do
    it 'is a command method' do
      expect(subject.each {}).to be(subject)
    end

    it 'yields the ast' do
      expect { |block| subject.each(&block) }.to yield_with_args(ast)
    end
  end

  context 'without a block' do
    it 'returns an enumerator' do
      expect(subject.each).to be_instance_of(to_enum.class)
    end

    it 'yields the ast in #each' do
      expect { |block| subject.each.each(&block) }.to yield_with_args(ast)
    end
  end
end<commit_msg>Refactor SQL::Fuzzer#each specs to use command method shared spec<commit_after># encoding: utf-8

require 'spec_helper'

describe SQL::Fuzzer, '#each' do
  let(:object) { described_class.new(ast)   }
  let(:ast)    { stub('ast').as_null_object }

  before do
    ast.should_receive(:to_ast)
  end

  context 'with a block' do
    subject { object.each {} }

    it_should_behave_like 'a command method'

    it 'yields the ast' do
      expect { |block| object.each(&block) }.to yield_with_args(ast)
    end
  end

  context 'without a block' do
    subject { object.each }

    it 'returns an enumerator' do
      expect(subject).to be_instance_of(to_enum.class)
    end

    it 'yields the ast in #each' do
      expect { |block| subject.each(&block) }.to yield_with_args(ast)
    end
  end
end
{'fraction_non_alphanumeric': 0.11308349769888232, 'fraction_numerical': 0.0013149243918474688, 'mean_word_length': 3.181318681318681, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1988034', 'n_tokens_mistral': 544, 'n_tokens_neox': 521, 'n_words': 149}