Version: 0.1.3
FactoryBot alternative for Trailblazer
Add following to Gemfile:
$ gem 'cabot'
and run:
$ bundle install
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 }
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
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
This project is licensed under the MIT License.