Skip to content

Instantly share code, notes, and snippets.

@adelahayepm
Created April 15, 2021 12:53
Show Gist options
  • Save adelahayepm/ec4e3f9e5e2eb0e5b6c2c1149589f907 to your computer and use it in GitHub Desktop.
Save adelahayepm/ec4e3f9e5e2eb0e5b6c2c1149589f907 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module FactoryBot
module Syntax
module Default
class DSL
def spira_factory(name, options = {}, &block)
factory(name, options) do
instance_eval do
initialize_with do
RDF::Graph.new.tap do |g|
Spira.using_repository(g) do
new(attributes).save!
end
end
end
instance_eval(&block) if block
end
end
end
end
end
end
end
module MyApp
class User < ::Spira::Base
configure base_uri: 'http://example.org/user'
property :bob, predicate: RDF::Vocab::DC.title, type: String
end
end
FactoryBot.define do
spira_factory :user, class: MyApp::User do
name { 'Bob' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment