Sha256: 5c32868834e7aa0e0e7635f522c8418ffea9659cca17a950e4b8df0485b3edd5

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

require_relative '../spec_helper'

describe 'Predicates' do
  it 'should allow regex matching' do
    expect(sequence('Stacy').find(matches(/Stac/))).to eq(some('Stacy'))
    expect(sequence('Raymond').find(matches(/NotAwesome/))).to eq(none)
  end

  it 'should allow is' do
    expect(sequence('Stuff').find(is('Stuff'))).to eq(some('Stuff'))
    expect(sequence('Stuff').find(equal_to?('Stuff'))).to eq(some('Stuff'))
    expect(sequence('Stuff').find(is('Nothing'))).to eq(none)
  end

  class Person
    attr_reader :name
    attr_reader :age

    def initialize(name, age)
      @name = name
      @age = age
    end
  end
  raymond = Person.new('Raymond', 41)
  mathilda = Person.new('Mathilda', 4)
  age = ->(person) { person.age }

  it 'should allow where' do
    expect(sequence(raymond, mathilda).filter(where(age, greater_than(40)))).to eq(sequence(raymond))
  end

  it 'should be able to negate other predicates using is_not' do
    expect(sequence(raymond).filter(where(age, is_not(greater_than(40))))).to eq(empty)
  end

  it 'should allow predicates to be composed using logical operations (AND/OR)' do
    expect(sequence(1,2,3,4,5).filter(greater_than(2).and(odd))).to eq(sequence(3,5))
    expect(sequence(1,2,3,4,5).filter(greater_than(2).or(odd))).to eq(sequence(1,3,4,5))
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
totally_lazy-0.1.62 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.61 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.60 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.59 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.58 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.57 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.56 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.55 spec/totally_lazy/predicates_spec.rb
totally_lazy-0.1.54 spec/totally_lazy/predicates_spec.rb