Sha256: 0606a5f4b82090436f70d6021887ad8be3777590f59682b0c00f5ae8b501d668

Contents?: true

Size: 1.41 KB

Versions: 14

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe LinkThumbnailer::Graders::Length do

  let(:config)      { double('config') }
  let(:description) { double('description') }
  let(:instance)    { described_class.new(description) }

  before do
    instance.stub(:config).and_return(config)
  end

  describe '#call' do

    let(:action) { instance.call(0) }

    context 'when text is too short' do

      before do
        instance.stub(:too_short?).and_return(true)
      end

      it { expect(action).to eq(-Float::INFINITY) }

    end

    context 'when text is not too short' do

      before do
        instance.stub(:too_short?).and_return(false)
        instance.stub(:text).and_return(text)
      end

      context 'when text length is greater than 400' do

        let(:text) { 'f' * 400 }

        it { expect(action).to eq(3) }

      end

      context 'when text length is less than 300' do

        let(:text) { 'f' * 299 }

        it { expect(action).to eq(2) }

      end

    end

  end

  describe '#too_short?' do

    let(:action) { instance.send(:too_short?) }

    before do
      instance.stub_chain(:config, :description_min_length).and_return(10)
      instance.stub(:text).and_return(text)
    end

    context 'when true' do

      let(:text) { 'f' * 9 }

      it { expect(action).to be_true }

    end

    context 'when false' do

      let(:text) { 'f' * 10 }

      it { expect(action).to be_false }

    end

  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
link_thumbnailer-2.4.0 spec/graders/length_spec.rb
link_thumbnailer-2.3.2 spec/graders/length_spec.rb
link_thumbnailer-2.3.1 spec/graders/length_spec.rb
link_thumbnailer-2.3.0 spec/graders/length_spec.rb
link_thumbnailer-2.2.3 spec/graders/length_spec.rb
link_thumbnailer-2.2.2 spec/graders/length_spec.rb
link_thumbnailer-2.2.1 spec/graders/length_spec.rb
link_thumbnailer-2.2.0 spec/graders/length_spec.rb
link_thumbnailer-2.1.0 spec/graders/length_spec.rb
link_thumbnailer-2.0.4 spec/graders/length_spec.rb
link_thumbnailer-2.0.3 spec/graders/length_spec.rb
link_thumbnailer-2.0.2 spec/graders/length_spec.rb
link_thumbnailer-2.0.1 spec/graders/length_spec.rb
link_thumbnailer-2.0.0 spec/graders/length_spec.rb