Sha256: e73fecd54b3c1047f8b4b37808e90b040868f3c6b70b148f2337f79e51469a3d

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8
#
# This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "spec_helper"

describe Lazier::Configuration do
  class ConfigurationSpecSample < ::Lazier::Configuration
    property :readwrite, default: "1"
    property :required, required: true
    property :readonly, default: "2", readonly: true
  end

  describe "#property" do
    it "should correctly define property and get it defaults" do
      expect(ConfigurationSpecSample.new(required: 1).readwrite).to eq("1")
      expect(ConfigurationSpecSample.new(required: 1, readwrite: "3").readwrite).to eq("3")
      expect(ConfigurationSpecSample.new(required: 1).readonly).to eq("2")
      expect(ConfigurationSpecSample.new(required: 1, readonly: "4").readonly).to eq("4")
    end

    it "should not allow writing readonly properties" do
      reference = ConfigurationSpecSample.new(required: 1)

      expect { reference.readonly = "4" }.to raise_error(ArgumentError)
      expect(reference.readonly).to eq("2")
    end

    it "should blow up for require properties" do
      expect { ConfigurationSpecSample.new }.to raise_error(ArgumentError)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lazier-3.5.0 spec/lazier/configuration_spec.rb
lazier-3.4.2 spec/lazier/configuration_spec.rb
lazier-3.4.1 spec/lazier/configuration_spec.rb
lazier-3.4.0 spec/lazier/configuration_spec.rb
lazier-3.3.10 spec/lazier/configuration_spec.rb
lazier-3.3.9 spec/lazier/configuration_spec.rb
lazier-3.3.8 spec/lazier/configuration_spec.rb
lazier-3.3.7 spec/lazier/configuration_spec.rb