Sha256: f0d652205a42f84550a9630bbdd5b11db0a347a0ed08362c0068b0e93d205526

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'
module Alf
  module Operator::NonRelational
    describe Defaults do
      
      let(:operator_class){ Defaults }
      it_should_behave_like("An operator class")
        
      subject{ operator.to_a }
  
      describe "when used without --strict" do
        
        let(:input) {[
          {:a => nil, :b => "b"},
        ]}
    
        let(:expected) {[
          {:a => 1, :b => "b", :c => "blue"},
        ]}
    
        describe "When factored with Lispy" do 
          let(:operator){ Lispy.defaults(input, :a => 1, :c => "blue") }
          it{ should == expected }
        end
    
        describe "When factored from commandline args" do
          let(:operator){ Defaults.run(%w{-- a 1 c 'blue'}) }
          before{ operator.pipe(input) }
          it{ should == expected }
        end
  
      end
        
      describe "when used with --strict" do
        
        let(:input) {[
          {:a => 3,   :b => "b", :c => "blue"},
          {:a => nil, :b => "b", :c => "blue"},
        ]}
    
        let(:expected) {[
          {:a => 3, :b => "b"},
          {:a => 1, :b => "b"},
        ]}
    
        describe "When factored with Lispy" do 
          let(:operator){ Lispy.defaults(input, {:a => 1, :b => "b"}, :strict => true) }
          it{ should == expected }
        end
    
      end
      
      describe "when used with tuple expressions" do
        let(:input) {[
          {:a => nil, :b => "b"},
        ]}
        let(:expected) {[
          {:a => "b", :b => "b"},
        ]}
        let(:operator){ 
          Lispy.defaults(input, {:a => TupleExpression.coerce("b")}) 
        }
        it{ should == expected }
      end
        
    end 
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alf-0.10.1 spec/unit/operator/non_relational/test_defaults.rb
alf-0.10.0 spec/unit/operator/non_relational/test_defaults.rb