Skip to content

Instantly share code, notes, and snippets.

@krisleech
Last active June 23, 2020 09:01
Show Gist options
  • Save krisleech/99a92faec97d0d30fbd53d38eb37d1f2 to your computer and use it in GitHub Desktop.
Save krisleech/99a92faec97d0d30fbd53d38eb37d1f2 to your computer and use it in GitHub Desktop.
dry-Struct
require "bundler/inline"
gemfile(false) do
source "https://rubygems.org"
gem "dry-struct", '0.5'
gem "dry-types", '0.14'
gem 'rails_event_store-rspec', '1.0.0'
gem "pry-byebug"
gem 'activesupport'
end
require 'rspec/autorun'
require 'active_support/core_ext/object/try'
module Types
include Dry::Types.module
end
class Event < Dry::Struct
def data
to_h
end
def metadata
{}
end
end
class Address < Dry::Struct
attribute :name, Types::String.meta(omittable: true)
end
class MyEvent < Event
attribute :address, Address.meta(omittable: true)
end
RSpec.describe MyEvent do
it 'works' do
event = described_class.new(address: { name: 'foo' })
expect(event)
.to(be_an_event(described_class)
.with_data(address: { name: 'foo' }))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment