Sha256: fc6622d3234e14f699bcb2eee52b10f27ea7af30a7e54136643e43d3ef2b517f

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

describe Wordless::CLIHelper do

  before :each do
    @cli = Wordless::CLI.new
  end

  context "::download" do
    before(:each) do
      @tempfile = Tempfile.new("download_test")
      @valid_url = "http://www.example.com/test"
      FakeWeb.register_uri(:get, @valid_url, :body => "Download test")
    end

    it "downloads a file to the specified location" do
      @cli.download(@valid_url, @tempfile.path)
      open(@tempfile.path).read.should == "Download test"
    end

    it "returns true on success" do
      @cli.download(@valid_url, @tempfile.path).should be_true
    end

    it "returns false on failure" do
      @cli.download("http://an.invalid.url", @tempfile.path).should be_false
    end

    after(:each) do
      @tempfile.close!
    end
  end

  context "::unzip" do
    it "unzips a file" do
      @cli.unzip(File.expand_path('spec/fixtures/zipped_file.zip'), 'tmp/unzip')
      File.exists?('tmp/unzip/zipped_file').should be_true
    end

    after(:each) do
      FileUtils.rm_rf('tmp/unzip') if File.directory? 'tmp/unzip'
    end
  end

  context "::error" do
    it "displays an error" do
      $stdout.should_receive(:puts).with("\e[31mI am an error\e[0m")
      @cli.error("I am an error")
    end
  end

  context "::success" do
    it "displays a success message" do
      $stdout.should_receive(:puts).with("\e[32mI am a success message\e[0m")
      @cli.success("I am a success message")
    end
  end

  context "::warning" do
    it "displays a warning" do
      $stdout.should_receive(:puts).with("\e[33mI am a warning\e[0m")
      @cli.warning("I am a warning")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wordless-0.3.0 spec/cli_helper_spec.rb