Sha256: 5699680d2c918187be8633f215d8abcb6932795460a1a60ed66e0006292d4ba1

Contents?: true

Size: 1.83 KB

Versions: 5

Compression:

Stored size: 1.83 KB

Contents

require 'simplecov'
SimpleCov.start

require 'tmpdir'
require 'rbatch/config'

describe RBatch::Config do
  before :all do
  end

  before :each do
    @path = File.join(Dir.tmpdir , rand.to_s)
  end
  
  after :each do
    FileUtils.rm @path if File.exists? @path
  end
  
  it "read" do
    open( @path  , "w" ){|f| f.write("key: value")}
    expect(RBatch::Config.new(@path)["key"]).to eq "value"
  end
  
  it "key is Symbol" do
    open( @path  , "w" ){|f| f.write(":key: value")}
    expect(RBatch::Config.new(@path)[:key]).to eq "value"
  end
  
  it "raise error when config does not exist" do
    expect {
      RBatch::Config.new(@path)["hoge"]
    }.to raise_error(RBatch::ConfigException)
    expect {
      RBatch::Config.new(@path).to_h
    }.to raise_error(RBatch::ConfigException)
    expect {
      RBatch::Config.new(@path).to_s
    }.to raise_error(RBatch::ConfigException)
  end
  
  it "read config twice" do
    open( @path  , "w" ){|f| f.write("key: value")}
    expect(RBatch::Config.new(@path)["key"]).to eq "value"
    expect(RBatch::Config.new(@path)["key"]).to eq "value"
  end
  
  it "raise error when read value which key does not exist" do
    open( @path  , "w" ){|f| f.write("key: value")}
    expect {
      RBatch::Config.new(@path)["not_exist"]
    }.to raise_error(RBatch::ConfigException)
  end
  
  it "raise error when read value which key mistake String for Symbol" do
    open( @path  , "w" ){|f| f.write("key: value")}
    expect {
      RBatch::Config.new(@path)[:key]
    }.to raise_error(RBatch::ConfigException)
  end
  
  it "raise error when read value which key mistake Symbol for String" do
    open( @path  , "w" ){|f| f.write(":key: value")}
    expect {
      RBatch::Config.new(@path)["key"]
    }.to raise_error(RBatch::ConfigException)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbatch-2.1.6 spec/rbatch/config_spec.rb
rbatch-2.1.5 spec/rbatch/config_spec.rb
rbatch-2.1.4 spec/rbatch/config_spec.rb
rbatch-2.1.3 spec/rbatch/config_spec.rb
rbatch-2.1.2 spec/rbatch/config_spec.rb