Sha256: 18b371dcc31aedc44ead9f631d589afcae8a77e9e0fa089863273e183cbc6cba

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8

require 'elipsa'

shared_examples_for :elipsa do
  subject { return_value }
  its(:length) { should be <= length }
  it { should eq expected }
end

describe Elipsa do
  context '#elipsa' do
    let(:length) { 20 }
    let(:params) { {length: length} }
    let(:return_value) { Elipsa::elipsa(input, params)}

    context 'a short string' do
      let(:input) { 'a short string' }
      let(:expected) { input }

      it_should_behave_like :elipsa
    end

    context 'word-boundary' do
      let(:input) { 'a longer string that goes over the limit' }
      let(:expected) { 'a longer string...' }

      it_should_behave_like :elipsa
    end

    context 'mid-large-word' do
      let(:input) { 'supercalifragilisticexpialidocious' }
      let(:expected) { 'supercalifragilis...' }

      it_should_behave_like :elipsa
    end

    context 'exact length' do
      let(:input) { 'at twenty characters' }
      let(:expected) { input }

      it_should_behave_like :elipsa
    end

    context 'one less' do
      let(:input) { 'nineteen characters' }
      let(:expected) { input }

      it_should_behave_like :elipsa
    end

    context 'trim punctuation' do
      let(:input) { 'Let\'s go fly a kite, up to the highest height'  }
      #                                  ^ this comma should not be included
      let(:length) { 24 }
      let(:expected) { 'Let\'s go fly a kite...' }

      it_should_behave_like :elipsa
    end

    context 'alternate symbol' do
      before(:each) { params.merge!(symbol: '…') }

      let(:input) { 'lorem ipsum dolor sit' }
      # with default symbol '...', this would be 'lorem ipsum...'
      let(:expected) { 'lorem ipsum dolor…' }

      it_should_behave_like :elipsa
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elipsa-1.0.0 spec/elipsa_spec.rb