Sha256: f70c955d5c68b81f5335ed14f72de7ef31947eea74ca7eb4a266e25d59af1247

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'
require 'ronin/fuzzing/repeater'

describe Fuzzing::Repeater do
  describe "#initialize" do
    subject { described_class }

    context "when lengths is an Integer" do
      it "should coerce lengths to an Enumerable" do
        repeator = subject.new(10)

        expect(repeator.lengths).to be_kind_of(Enumerable)
      end
    end

    context "when lengths is not Enumerable or an Integer" do
      it "should raise a TypeError" do
        expect {
          subject.new(Object.new)
        }.to raise_error(TypeError)
      end
    end
  end

  describe "#each" do
    let(:repeatable) { 'A' }

    context "when lengths was an Integer" do
      let(:length) { 10 }

      subject { described_class.new(length) }

      it "should yield one repeated value" do
        values = subject.each(repeatable).to_a
        
        expect(values).to eq([repeatable * length])
      end
    end

    context "when lengths was Enumerable" do
      let(:lengths) { (1..4) }

      subject { described_class.new(lengths) }

      it "should yield repeated values for each length" do
        values = subject.each(repeatable).to_a

        expect(values).to eq([
          repeatable * 1,
          repeatable * 2,
          repeatable * 3,
          repeatable * 4
        ])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ronin-support-0.5.2 spec/fuzzing/repeater_spec.rb