spec/matchete_spec.rb in matchete-0.2.0 vs spec/matchete_spec.rb in matchete-0.4.0

- old
+ new

@@ -2,10 +2,29 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'rspec' require 'matchete' describe Matchete do + it 'can use a pattern based on `either` helpers' do + class A + include Matchete + + on either(FalseClass, Proc), FalseClass, + def work(g, h) + g + end + + on FalseClass, NilClass, + def work(g, h) + :love + end + end + + expect(A.new.work(false, false)).to eq false + expect(A.new.work(false, nil)).to eq :love + end + it 'can be used to overload a method in a class' do class A include Matchete on Integer, @@ -128,9 +147,28 @@ :else end end expect(A.new.play(2.2)).to eq :else + end + + it 'can use a pattern based on `exact` helpers' do + class A + include Matchete + + on Integer, + def lala(a) + a - 2 + end + + on exact(Integer), + def lala(a) + a + end + end + + expect(A.new.lala(4)).to eq 2 + expect(A.new.lala(Integer)).to eq Integer end it 'can use a pattern based on existing predicate methods given as symbols' do class A include Matchete