Sha256: 175ef441e0b30117e0dd1fff494088a2abbe9f5b9daf1539faad3edaa4ab07dc

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe LinkThumbnailer::Scrapers::Base do

  let(:document) { double('document') }
  let(:website)  { LinkThumbnailer::Models::Website.new }
  let(:instance) { described_class.new(document, website) }

  describe '#call' do

    let(:attr)    { :title }
    let(:value)   { 'foo' }
    let(:action)  { instance.call(attr) }

    before do
      instance.stub(:value).and_return(value)
    end

    it { expect { action }.to change { website.title }.from(nil).to(value) }

  end

  describe '#model_class' do

    let(:action) { instance.send(:model_class) }

    before do
      instance.stub(:attribute_name).and_return(attr)
    end

    context 'when internal class exists' do

      let(:attr) { :title }

      it { expect(action).to eq(::LinkThumbnailer::Models::Title) }

    end

    context 'when internal class does not exists' do

      let(:attr) { :foo }

      it { expect { action }.to raise_exception }

    end

  end

  describe '#modelize' do

    let(:node)        { double('node') }
    let(:text)        { 'foo' }
    let(:model_class) { double('model_class') }
    let(:action)      { instance.send(:modelize, node, text) }

    before do
      instance.stub(:model_class).and_return(model_class)
    end

    it 'instantiates a new model' do
      expect(model_class).to receive(:new).with(node, text)
      action
    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
link_thumbnailer-3.3.0 spec/scrapers/base_spec.rb
link_thumbnailer-3.2.1 spec/scrapers/base_spec.rb
link_thumbnailer-3.2.0 spec/scrapers/base_spec.rb
link_thumbnailer-3.1.2 spec/scrapers/base_spec.rb
link_thumbnailer-3.1.1 spec/scrapers/base_spec.rb
link_thumbnailer-3.1.0 spec/scrapers/base_spec.rb
link_thumbnailer-3.0.3 spec/scrapers/base_spec.rb
link_thumbnailer-3.0.2 spec/scrapers/base_spec.rb
link_thumbnailer-3.0.1 spec/scrapers/base_spec.rb
link_thumbnailer-3.0.0 spec/scrapers/base_spec.rb
link_thumbnailer-2.6.1 spec/scrapers/base_spec.rb
link_thumbnailer-2.6.0 spec/scrapers/base_spec.rb
link_thumbnailer-2.5.2 spec/scrapers/base_spec.rb
link_thumbnailer-2.5.1 spec/scrapers/base_spec.rb
link_thumbnailer-2.5.0 spec/scrapers/base_spec.rb