Sha256: a9fdfd941e315644f16a832cbe52a81dfa5a6d8088f9e79144ec73a8bc305c45

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'
require 'command_mapper/option_value'
require 'command_mapper/types/num'
require 'command_mapper/types/list'

describe CommandMapper::OptionValue do
  describe "#validate" do
    let(:type) { Types::Num.new }

    subject { described_class.new(type: type) }

    context "when the option value is not required" do
      subject do
        described_class.new(type: type, required: false)
      end

      context "and given a value of true" do
        it "must return true" do
          expect(subject.validate(true)).to be(true)
        end
      end
    end

    context "otherwise" do
      it "must validate the value using #type.validate" do
        expect(subject.validate('1234')).to be(true)
        expect(subject.validate('foo')).to eq(
          [false, "contains non-numeric characters (\"foo\")"]
        )
      end
    end
  end

  describe "#format" do
    let(:type) { Types::List.new }

    subject { described_class.new(type: type) }

    let(:value) { [1,2,3] }

    it "must call the #type.format" do
      expect(subject.format(value)).to eq(type.format(value))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
command_mapper-0.3.2 spec/option_value_spec.rb
command_mapper-0.3.1 spec/option_value_spec.rb
command_mapper-0.3.0 spec/option_value_spec.rb
command_mapper-0.2.1 spec/option_value_spec.rb