Sha256: cd26a4ca23e3cb7ab0f58a3f7b328672dbe5fe88a354a5ecb356ef6339acbb75

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require File.expand_path("../../../base", __FILE__)

require "vagrant/util/downloader"

describe Vagrant::Util::Downloader do
  let(:source) { "foo" }
  let(:destination) { "bar" }
  let(:exit_code) { 0 }

  let(:subprocess_result) do
    double("subprocess_result").tap do |result|
      result.stub(:exit_code => exit_code)
      result.stub(:stderr => "")
    end
  end

  subject { described_class.new(source, destination) }

  before :each do
    Vagrant::Util::Subprocess.stub(:execute).and_return(subprocess_result)
  end

  describe "#download!" do
    context "with a good exit status" do
      let(:exit_code) { 0 }

      it "downloads the file and returns true" do
        curl_options = ["--fail", "--location", "--max-redirs", "10", "--output", destination, source, {}]

        Vagrant::Util::Subprocess.should_receive(:execute).
          with("curl", *curl_options).
          and_return(subprocess_result)

        subject.download!.should be
      end
    end

    context "with a bad exit status" do
      let(:exit_code) { 1 }

      it "raises an exception" do
        curl_options = ["--fail", "--location", "--max-redirs", "10", "--output", destination, source, {}]

        Vagrant::Util::Subprocess.should_receive(:execute).
          with("curl", *curl_options).
          and_return(subprocess_result)

        expect { subject.download! }.
          to raise_error(Vagrant::Errors::DownloaderError)
      end
    end

    context "with a UI" do
      pending "tests for a UI"
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/test/unit/vagrant/util/downloader_test.rb
tnargav-1.2.3 test/unit/vagrant/util/downloader_test.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/test/unit/vagrant/util/downloader_test.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/test/unit/vagrant/util/downloader_test.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/test/unit/vagrant/util/downloader_test.rb
tnargav-1.2.2 test/unit/vagrant/util/downloader_test.rb