Sha256: 409e1d176e6fec6c3e089943c463a48df9b1219a1c7d749c8ff56d1578676c19

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe LinkThumbnailer::Scrapers::Opengraph::Base do

  let(:node)      { double('node') }
  let(:document)  { double('document') }
  let(:instance)  { described_class.new(document) }

  describe '#applicable?' do

    let(:meta)    { [node, node] }
    let(:action)  { instance.applicable? }

    before do
      allow(instance).to receive(:meta).and_return(meta)
    end

    context 'when all node is an opengraph' do

      before do
        allow(instance).to receive(:opengraph_node?).and_return(true, true)
      end

      it { expect(action).to be_truthy }

    end

    context 'when any node is an opengraph' do

      before do
        allow(instance).to receive(:opengraph_node?).and_return(true, false)
      end

      it { expect(action).to be_truthy }

    end

    context 'when no node is an opengraph' do

      before do
        allow(instance).to receive(:opengraph_node?).and_return(false, false)
      end

      it { expect(action).to be_falsey }

    end

  end

  describe '#opengraph_node?' do

    let(:action) { instance.send(:opengraph_node?, node) }

    before do
      allow(node).to receive(:attribute).with('name').and_return(attribute_from_name)
    end

    context 'with attribute from name valid' do

      let(:attribute_from_name) { 'og:foo' }

      it { expect(action).to be_truthy }

    end

    context 'with attribute from name not valid' do

      let(:attribute_from_name) { 'foo' }

      before do
        allow(node).to receive(:attribute).with('property').and_return(attribute_from_property)
      end

      context 'and attribute from property valid' do

        let(:attribute_from_property) { 'og:bar' }

        it { expect(action).to be_truthy }

      end

      context 'and attribute from property not valid' do

        let(:attribute_from_property) { 'bar' }

        it { expect(action).to be_falsey }

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
link_thumbnailer-3.4.0 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.3.2 spec/scrapers/opengraph/base_spec.rb