Code Monkey home page Code Monkey logo

cabot's Introduction

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.

cabot's People

Contributors

sheff3rd avatar n4g1b4t0r3000 avatar

Stargazers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.