Sha256: 59049d4dd5ee0f3027df86c20e3519c40579d00c9c618dbadca62620b87f5693

Contents?: true

Size: 996 Bytes

Versions: 16

Compression:

Stored size: 996 Bytes

Contents

require "spec_helper"

describe Pliny::CanonicalLogLineHelpers do
  class TestCanonicalLogLine
    include Pliny::CanonicalLogLineHelpers

    log_field :field_float, Float
    log_field :field_integer, Integer
    log_field :field_string, String
  end

  it "allows a field to be set" do
    line = TestCanonicalLogLine.new
    line.field_string = "foo"
  end

  it "allows nils to be set" do
    line = TestCanonicalLogLine.new
    line.field_string = nil
  end

  it "rejects values that are of the wrong type" do
    line = TestCanonicalLogLine.new
    e = assert_raises ArgumentError do
      line.field_string = true
    end
    assert_equal "Expected field_string to be type String (was TrueClass)",
      e.message
  end

  it "produces a hash with #to_h" do
    line = TestCanonicalLogLine.new
    line.field_float = 3.14
    line.field_integer = 42
    line.field_string = "foo"
    assert_equal({ field_float: 3.14, field_integer: 42, field_string: "foo" },
      line.to_h)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pliny-1.1.0 spec/canonical_log_line_helpers_spec.rb
pliny-1.0.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.32.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.31.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.30.1 spec/canonical_log_line_helpers_spec.rb
pliny-0.30.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.29.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.28.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.27.1 spec/canonical_log_line_helpers_spec.rb
pliny-0.27.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.26.2 spec/canonical_log_line_helpers_spec.rb
pliny-0.26.1 spec/canonical_log_line_helpers_spec.rb
pliny-0.26.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.25.1 spec/canonical_log_line_helpers_spec.rb
pliny-0.25.0 spec/canonical_log_line_helpers_spec.rb
pliny-0.24.0 spec/canonical_log_line_helpers_spec.rb