Sha256: 7dc2d062961d25f7ca5d1cfc7d921eb3124a55bd9a81a363459ede922d29f2c8

Contents?: true

Size: 701 Bytes

Versions: 3

Compression:

Stored size: 701 Bytes

Contents

# encoding: utf-8

require "ostruct"
require "shared/i18n"

describe Assertion do

  include_context "preloaded translations"

  it "works" do
    IsAdult = Assertion.about :name, :age do
      age.to_i >= 18
    end

    AdultOnly = Assertion.guards :user do
      IsAdult[name: user.name, age: user.age]
    end

    andrew = OpenStruct.new(name: "Andrew", age: 13, city: "Moscow")
    andriy = OpenStruct.new(name: "Andriy", age: 28, city: "Kiev")

    expect { AdultOnly[andrew] }.to raise_error Assertion::InvalidError
    expect(AdultOnly[andriy]).to eql andriy
  end

  after { Object.send :remove_const, :AdultOnly }
  after { Object.send :remove_const, :IsAdult   }

end # describe Assertion

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
assertion-0.2.5 spec/integration/guard_spec.rb
assertion-0.2.4 spec/integration/guard_spec.rb
assertion-0.2.3 spec/integration/guard_spec.rb