Skip to content

Latest commit

 

History

History
98 lines (68 loc) · 1.87 KB

README.md

File metadata and controls

98 lines (68 loc) · 1.87 KB

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: '[email protected]'
      }
    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.