Sha256: 5ec5f8f1dbd59578da99f9335aeb2b45c97a8f32d2e8fb84ad30c8e0878ce8b9

Contents?: true

Size: 1.44 KB

Versions: 29

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe EroGetter do
  before do
    EroGetter.clean
  end

  let(:regex) { %r{http://example.com/\d+.html} }
  subject { @ero_getter }
  describe :class_methods do
    subject { EroGetter }
    describe :url_mapping do
      its(:url_mapping) { should == {} }
      context :add_mapping do
        before do
          @strategy = Class.new
          @regex = regex
          EroGetter.add_mapping(@regex, @strategy)
        end
        its(:url_mapping) { should == {@regex =>  @strategy} }
      end
    end
  end

  describe :instance_methods do
    let(:url) { 'http://example.com/0101010.html' }
    before do
      @strategy = Class.new
      @regex = regex
      EroGetter.add_mapping(@regex, @strategy)
      @ero_getter = EroGetter.new
    end

    describe :detect do
      context :match do
        it { subject.detect(url).should == @strategy }
      end
      context :mismatch do
        it { subject.detect(url.gsub(/com/, 'net')).should be_nil }
      end
    end

    describe :download do
      context :match do
        it "detect and run" do
          @instance = @strategy.new
          @strategy.should_receive(:new).with(url).and_return(@instance)
          @instance.should_receive(:run)
          subject.download(url)
        end
      end

      context :mismatch do
        it {
          lambda {
            subject.download(url.gsub(/com/, 'net'))
          }.should raise_error
        }
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ero_getter-1.7.0 spec/ero_getter_spec.rb
ero_getter-1.6.3 spec/ero_getter_spec.rb
ero_getter-1.6.2 spec/ero_getter_spec.rb
ero_getter-1.6.1 spec/ero_getter_spec.rb
ero_getter-1.6.0 spec/ero_getter_spec.rb
ero_getter-1.5.1 spec/ero_getter_spec.rb
ero_getter-1.5.0 spec/ero_getter_spec.rb
ero_getter-1.4.0 spec/ero_getter_spec.rb
ero_getter-1.3.9 spec/ero_getter_spec.rb
ero_getter-1.3.8 spec/ero_getter_spec.rb
ero_getter-1.3.7 spec/ero_getter_spec.rb
ero_getter-1.3.6 spec/ero_getter_spec.rb
ero_getter-1.3.5 spec/ero_getter_spec.rb
ero_getter-1.3.4 spec/ero_getter_spec.rb
ero_getter-1.3.3 spec/ero_getter_spec.rb
ero_getter-1.3.2 spec/ero_getter_spec.rb
ero_getter-1.3.1 spec/ero_getter_spec.rb
ero_getter-1.3.0 spec/ero_getter_spec.rb
ero_getter-1.2.0 spec/ero_getter_spec.rb
ero_getter-1.1.2 spec/ero_getter_spec.rb