Project

cabot

0.0
No commit activity in last 3 years
No release in over 3 years
FatoryBot alternative for trailblazer
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Cabot

Version: 0.1.3

FactoryBot alternative for Trailblazer

Getting started

Add following to Gemfile:

$ gem 'cabot'

and run:

$ bundle install

Configuration

Create a new directory to store all defined cabot parameters in spec/cabot

spec
  └── cabot
      ├── index.rb
      ├── show.rb
      ├── create.rb
      └── update.rb

And then load newly created files

# rails_helper.rb

Dir[Rails.root.join('spec/cabot/**/*.rb')].each { |f| require f }

Usage

Cabot is trailblazer alternative for factory_bot It's being used to create operation result in the spec

  let(:current_user) { Cabot::Create.(:user).model }
  let(:result) { Cabot::Create.(:comment, current_user: current_user)

  before do
    let(:seriailizer) { result.serializer }
  end

Calling Cabot::Create.(:user) will automatically call User::Create.(params: Cabot::Parameters::Create.send(:account)) with predefined parameters

# spec/cabot/create.rb

module Cabot::Parameters
  module Create
    def self.comment
      {
        body: ''
      }
    end

    def self.user
      {
        name: 'John Doe',
        email: 'john_doe@mail.com'
      }
    end
  end
end

Configuration

Option Description Default
symbolize_key Symbolize key or not when calling result[:model] and result[:serializer] true
# config/initializers/cabot.rb
Cabot.configure do |config|
  config.symbolize_keys = false
end

License

This project is licensed under the MIT License.