Sha256: 087e58ae5835ed1583cda3d98282003cfe6d778bb646a63708f69161854c6a6c

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Squall do
  describe "VERSION" do
    it "has a valid format" do
      Squall::VERSION.should match /\d+/
    end
  end

  describe "#config" do
    it "yields a configuration with a block" do
      Squall.should_receive(:config).and_yield(Squall::Config.new)
      Squall.config { |c| c }
    end

    it "returns the config after yield" do
      Squall.reset_config
      Squall.config { |c| c }.should == {}
      Squall.config.should == {}
    end


    it "returns the config without a block" do
      Squall.reset_config
      Squall.config.should == {}
    end

    it "sets the base URI" do
      Squall.config { |c| c.base_uri 'hi'}
      Squall.config.should_not be_empty
      Squall.config[:base_uri] == 'hi'
    end
  end

  describe "#reset" do
    it "resets the configuration to defaults" do
      Squall.config.should_not be_empty
      Squall.reset_config
      Squall.config.should be_empty
    end
  end

  describe "#config_file" do
    it "defaults to ~/.squall" do
      File.should_receive(:join).with(ENV['HOME'], '.squall.yml').and_return("/path/to/file")
      File.stub(:exists?).and_return(true)
      YAML.stub(:load_file).and_return({})
      Squall.config_file
    end

    it "returns an error if the file doesn't exist" do
      expect { Squall.config_file '/tmp/missing.yml'}.to raise_error(ArgumentError, "Config file doesn't exist '/tmp/missing.yml'")
    end

    it "loads the yaml" do
      File.stub(:exists?).and_return(true)
      config = {'username' => 'test', 'password' => 'pass', 'base_uri' => 'http://example.com'}
      YAML.should_receive(:load_file).with('/tmp/exists.yml').and_return(config)
      Squall.config_file '/tmp/exists.yml'
      Squall.config.should include(:username => config['username'], :password => config['password'], :base_uri => config['base_uri'])
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
squall-1.3.0 spec/squall_spec.rb
squall-1.2.1beta1 spec/squall_spec.rb
squall-1.2.0beta1 spec/squall_spec.rb
squall-1.1.0 spec/squall_spec.rb