Sha256: 5a4438b16d8510f08b7a65e41ececa9e6c62e1f7c60dd649f243e82bf74217e2

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'
require 'nagios_parser/result'

describe NagiosParser::Result do
  let(:result) { described_class.new }

  it "sets a key value pair" do
    result['foo'] = 'bar'

    result['foo'].should == 'bar'
  end

  context "with multi_value option set" do
    context "and a single value for a multi value key" do
      it "returns a list with one value" do
        result = described_class.new(:multi_value => %w{foo})
        result['foo'] = 'bar'

        result['foo'].should == ['bar']
      end
    end

    context "and multiple values for a multi value key" do
      it "returns a list with all values" do
        result = described_class.new(:multi_value => %w{eek})
        result['eek'] = 'foo'
        result['eek'] = 'bar'

        result['eek'].should == ['foo', 'bar']
      end
    end
  end

  context "without multi_value options set" do
    context "and multiple values for the same key" do
      it "returns the last value" do
        result['baz'] = 'foo'
        result['baz'] = 'bar'

        result['baz'].should == 'bar'
      end
    end
  end

  describe "#to_hash" do
    it "returns a hash representation of the result" do
      result['foo'] = ['bar', 'baz']
      result['one'] = 1

      result.to_hash.should == {'foo' => ['bar', 'baz'], 'one' => 1}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nagios_parser-1.3.0 spec/nagios_parser/result_spec.rb