Cabot
Version: 0.1.3
FactoryBot alternative for Trailblazer
Getting started
Add following to Gemfile:
$ gem 'cabot'and run:
$ bundle installConfiguration
Create a new directory to store all defined cabot parameters in spec/cabot
spec
└── cabot
├── index.rb
├── show.rb
├── create.rb
└── update.rbAnd 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 }
endCalling 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
endConfiguration
| 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
endLicense
This project is licensed under the MIT License.