Sha256: 5b8380b81fd6b132426ef54f62279253081811bc2f07a0532703b9b6b2f77783

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe Wordless::CLIHelper do
  # def shell
  #   @shell ||= Thor::Shell::Basic.new
  # end
  
  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 eq("Download test")
    end
    
    it "returns true on success" do
      @cli.download(@valid_url, @tempfile.path).should eq true
    end
    
    it "returns false on failure" do
      @cli.download("http://an.invalid.url", @tempfile.path).should eq 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

3 entries across 3 versions & 1 rubygems

Version Path
wordless-0.2.1 spec/cli_helper_spec.rb
wordless-0.2.0 spec/cli_helper_spec.rb
wordless-0.1.0 spec/cli_helper_spec.rb