Sha256: 758988a13782d04ba769c5300fd5f1d6c27c1697d6359c26a30f14f649c13da1

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe TorrentSearch::Services::Download do
  Given(:path){File.join(Dir.pwd, 'spec/tmp')}
  Given(:torrent){OpenStruct.new(href: 'http://asdf.com', filename: 'asdf')}
  Given(:created_file){File.join(path, "#{torrent.filename}.torrent")}
  Given(:view){double 'view'}

  subject{described_class.new(path, torrent)}

  before :each do
    FileUtils.rm created_file, force: true
  end

  describe '#perform' do
    When{subject.perform view}

    context 'with 200 success' do
      Given{stub_request(:any, "asdf.com").to_return(status: 200, body: 'abc')}
      Given{view.should receive(:success)}
      Then{a_request(:get, "asdf.com").should have_been_made.once}
      And{File.read(created_file).should eq 'abc'}
    end

    context 'with 404 not found' do
      Given{stub_request(:any, "asdf.com").to_return(status: 404)}
      Given{view.should receive(:failure)}
      Then{a_request(:get, "asdf.com").should have_been_made.once}
      And{File.exists?(created_file).should be_false}
    end

    context 'with 500 error' do
      Given{stub_request(:any, "asdf.com").to_return(status: 500)}
      Given{view.should receive(:failure)}
      Then{a_request(:get, "asdf.com").should have_been_made.once}
      And{File.exists?(created_file).should be_false}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
torrent_search-0.0.3 spec/lib/torrent_search/services/download_spec.rb
torrent_search-0.0.2 spec/lib/torrent_search/services/download_spec.rb