Sha256: 325ac36ff3f1063fc4387007402d5938a3c9c2c2b5c52a22fda0ed7b141f3047

Contents?: true

Size: 774 Bytes

Versions: 2

Compression:

Stored size: 774 Bytes

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

describe Shortener::ShortenerHelper, type: :helper do
  describe '#short_url' do
    let(:destination) { Faker::Internet.url }
    before do
      expect(Shortener::ShortenedUrl).to receive(:generate).with(destination, nil).and_return(shortened_url)
    end

    context 'short url was generated' do
      let(:shortened_url) { instance_double('ShortenedUrl', unique_key: '12345') }

      it "shortens the url" do
        expect(helper.short_url(destination)).to eq "http://test.host/12345"
      end
    end

    context 'short url could not be generated' do
      let(:shortened_url) { nil }

      it 'returns the original url' do
        expect(helper.short_url(destination)).to eq destination
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shortener-0.4.1 spec/helpers/shortener_helper_spec.rb
shortener-0.4.0 spec/helpers/shortener_helper_spec.rb