Sha256: 04fafbfa24fc22f56901b5e1a6064324ab7b336a53db1b44d9632d617e745b32

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

RSpec.describe Onebox::Helpers do
  describe '.blank?' do
    it { expect(described_class.blank?("")).to be(true) }
    it { expect(described_class.blank?(" ")).to be(true) }
    it { expect(described_class.blank?("test")).to be(false) }
    it { expect(described_class.blank?(["test", "testing"])).to be(false) }
    it { expect(described_class.blank?([])).to be(true) }
    it { expect(described_class.blank?({})).to be(true) }
    it { expect(described_class.blank?({a: 'test'})).to be(false) }
    it { expect(described_class.blank?(nil)).to be(true) }
    it { expect(described_class.blank?(true)).to be(false) }
    it { expect(described_class.blank?(false)).to be(true) }
  end

  describe ".truncate" do
    let(:test_string) { "Chops off on spaces" }
    it { expect(described_class.truncate(test_string)).to eq(test_string) }
    it { expect(described_class.truncate(test_string,5)).to eq("Chops...") }
    it { expect(described_class.truncate(test_string,7)).to eq("Chops...") }
    it { expect(described_class.truncate(test_string,9)).to eq("Chops off...") }
    it { expect(described_class.truncate(test_string,10)).to eq("Chops off...") }
    it { expect(described_class.truncate(test_string,100)).to eq("Chops off on spaces") }
    it { expect(described_class.truncate(" #{test_string} ",6)).to eq(" Chops...") }
  end

  describe "fetch_response" do
    after(:each) do
      Onebox.options = Onebox::DEFAULTS
    end

    before do
      Onebox.options = { max_download_kb: 1 }
      fake("http://example.com/large-file", response("slides"))
    end

    it "raises an exception when responses are larger than our limit" do
      expect {
        described_class.fetch_response('http://example.com/large-file')
      }.to raise_error(Onebox::Helpers::DownloadTooLarge)
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
onebox-1.8.7 spec/lib/onebox/helpers_spec.rb
onebox-1.8.6 spec/lib/onebox/helpers_spec.rb
onebox-1.8.5 spec/lib/onebox/helpers_spec.rb
onebox-1.8.4 spec/lib/onebox/helpers_spec.rb
onebox-1.8.3 spec/lib/onebox/helpers_spec.rb
onebox-1.8.2 spec/lib/onebox/helpers_spec.rb
onebox-1.8.1 spec/lib/onebox/helpers_spec.rb
onebox-1.8.0 spec/lib/onebox/helpers_spec.rb
onebox-1.7.9 spec/lib/onebox/helpers_spec.rb
onebox-1.7.8 spec/lib/onebox/helpers_spec.rb
onebox-1.7.7 spec/lib/onebox/helpers_spec.rb
onebox-1.7.6 spec/lib/onebox/helpers_spec.rb