Sha256: 7b1d4febac4e0152034767908da6eb0b8440ee3dc036a4b488088ea5e413dad0

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

describe TorrentSearch::Controllers::Search do

  Given(:view){double 'view'}

  subject{described_class.new(view)}

  describe '#search' do
    Given(:search_terms){'asdf'}
    Given(:options){{}}
    Given(:scraper_double){double 'scraper'}

    Given{TorrentSearch::Trackers::KickAss::Scraper.should_receive(:new).with(search_terms, options).and_return(scraper_double)}
    Given{scraper_double.should_receive(:search).and_return(search_result)}

    When{subject.search(search_terms, options)}

    context 'with no search result' do
      Given(:search_result){[]}

      context 'with invalid command then quit' do
        Given{view.stub(:action?).and_return(:d, :q)}
        Given{view.stub(:invalid_command!)}

        Given{TorrentSearch::CLI.should_receive(:quit)}
        Then{}
      end

      context 'with search again then quit' do
        Given(:new_search_terms){'fdsa'}

        Given{view.stub(:action?).and_return(:s, :q)}
        Given{view.stub(:search_terms?).and_return(new_search_terms)}

        Given{TorrentSearch::Trackers::KickAss::Scraper.should_receive(:new).with(new_search_terms, options).and_return(scraper_double)}
        Given{scraper_double.should_receive(:search).and_return(search_result)}
        Given{TorrentSearch::CLI.should_receive(:quit)}
        Then{}
      end
    end

    context 'with search result' do
      Given(:search_result){[OpenStruct.new(name: '', size:'', seeders: '', leechers:'')]}

      describe 'download' do
        Given{view.stub(:action?).and_return(:d)}

        Given(:download_double){double 'download'}
        Given{TorrentSearch::Controllers::Download.should_receive(:new).with(search_result).and_return(download_double)}
        Given{download_double.should_receive :download}
        Then{}
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
torrent_search-0.0.3 spec/lib/torrent_search/controllers/search_spec.rb
torrent_search-0.0.2 spec/lib/torrent_search/controllers/search_spec.rb