Sha256: 770a0d35bf983060119240a16826b7a769d42a721e27da698230ab8e681ea676

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'yaml'
require_relative 'spec_helper'
require_relative '../lib/lovely_rufus'

describe LovelyRufus do
  describe '.wrap' do
    it 'wraps the passed String to 72 characters by default' do
      short = 'all right: stop, collaborate and listen'
      long  = short + ' – Ice is back with a brand new invention'
      wrap  = <<-end.dedent
        all right: stop, collaborate and listen
        – Ice is back with a brand new invention
      end
      LovelyRufus.wrap(short).must_equal "#{short}\n"
      LovelyRufus.wrap(long).must_equal wrap
    end

    it 'wraps the passed String to the given number of characters' do
      input = 'something grabs a hold of me tightly; ' \
        'flow like a harpoon – daily and nightly'
      LovelyRufus.wrap(input, width: 40).must_equal <<-end.dedent
        something grabs a hold of me tightly;
        flow like a harpoon – daily and nightly
      end
      LovelyRufus.wrap(input, width: 21).must_equal <<-end.dedent
        something grabs
        a hold of me tightly;
        flow like a harpoon
        – daily and nightly
      end
    end

    it 'rewraps a String from zero' do
      broken = <<-end.dedent
        turn off
        the lights and I’ll glow
      end
      wrapped = LovelyRufus.wrap(broken)
      wrapped.must_equal "turn off the lights and I’ll glow\n"
    end

    it 'supports all the example use-cases' do
      path = File.expand_path('lovely_rufus/text_wrapper_spec.yml', __dir__)
      YAML.load_file(path).each do |spec|
        width = spec.fetch('width') { 72 }
        wrap  = "#{spec['output']}\n"
        LovelyRufus.wrap(spec['input'], width: width).must_equal wrap
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lovely_rufus-0.2.0 spec/lovely_rufus_spec.rb