Sha256: c7f94737f3f2749fa7fc0a04e29ed31d7cc404a5bb5cd17b7a7d9f7ca3cbff3b

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

shared_examples_for 'liftable' do
  it { should respond_to :compose_with_lifting }
  it { should respond_to :>= }
  it { should respond_to :<= }

  let(:x) { :foo }
  let(:y) { [1,2] }
  let(:z) { {:a => 1, :b => 2} }
  let(:g) { lambda{|x|
    if x.nil? || (x.respond_to?(:empty?) && x.empty?)
      raise "g called with nil arg"
    else
      (x.to_s * 2) + "_g"
    end
    }
  }

  it('" f >= g" returns function that does not call g if args is mzero'){
    (subject >= g).should be_a_kind_of Proc
  }

  it('"(f >= g).call(nil) returns nil and does not call g'){
    (subject >= g).call(nil).should be_nil
  }
  it('"(f >= g).call(x) should be g(f(x))'){
    (subject >= g).call(x).should == g.call(subject.to_proc.call(x))
  }
  it('"(f >= g).call([]) returns [] and does not call g'){
    (subject >= g).call([]).should == []
  }
  it('"(f >= g).call([1,2]) should be g(f([1,2]))'){
    (subject >= g).call(y).should == g.call(subject.to_proc.call(y))
  }
  it('"(f >= g).call({}) returns {} and does not call g'){
    (subject >= g).call({}).should == {}
  }
  it('"(f >= g).call({:a => 1,:b => 2}) should be g(f({:a => 1,  :b => 2}))'){
    (subject >= g).call(z).should == g.call(subject.to_proc.call(z))
  }

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lambda_driver-1.2.0 spec/shared/liftable.rb