Sha256: 5bcc96cfba28d38b5a982ee2960c0a03af58fb9f8009c90106559384d273264a

Contents?: true

Size: 1.94 KB

Versions: 19

Compression:

Stored size: 1.94 KB

Contents

require_relative 'active_record'

module Lopata
  # Helpers for FactoryBot usage in tests.
  #
  # Make helpers available in scenarios by
  #
  #     require 'lopata/factory_bot'
  #
  # Automatically adds ActiveRecord helpers.
  # @see Lopata::ActiveRecord
  #
  # Allows to create ActiveRecord object by FactoryBot definitions.
  # All the objects created by FactoryBot helpers will be destroyed automatically
  # at the end of scenario.
  # @see Lopata::ActiveRecord::Methods#cleanup
  #
  # @example
  #
  #     # Configure db connection at config/environments/qa.yml like rails:
  #     # db:
  #     #   adapter: postgresql
  #     #   host: your.database.host
  #     #   username: username
  #     #   password: password
  #     #   database: database
  #     require 'active_record'
  #     require 'factory_bot'
  #     require 'lopata/facotory_bot'
  #
  #     class User < ActiveRecord::Base; end
  #
  #     FactoryBot.define do
  #       factory :user do
  #         username { 'testuser' }
  #       end
  #     end
  #
  #     Lopata.define 'User creation' do
  #       setup do
  #         @user = create(:user)
  #       end
  #       # No cleanup needed - @user will be destroyed automatically
  #       # cleanup :user
  #
  #       it 'works' do
  #         expect(@user).to_not be_nil
  #       end
  #     end
  #
  module FactoryBot
    # To be included in Lopata::Scenario
    module Methods
      # Wrapper for FactoryBot#create
      # Calls the FactoryBot#create with given paramters and returns it result.
      # Additionally store the created object for destroying at the end of scenario.
      # @see Lopata::ActiveRecord::Methods#cleanup
      def create(*params)
        cleanup_later ::FactoryBot.create(*params)
      end
    end

    # To be included in Lopata::ScenarioBuilder
    module DSL
    end
  end
end

Lopata::Scenario.include Lopata::FactoryBot::Methods
Lopata::ScenarioBuilder.include Lopata::FactoryBot::DSL

::FactoryBot.find_definitions

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lopata-0.1.32 lib/lopata/factory_bot.rb
lopata-0.1.31 lib/lopata/factory_bot.rb
lopata-0.1.30 lib/lopata/factory_bot.rb
lopata-0.1.29 lib/lopata/factory_bot.rb
lopata-0.1.28 lib/lopata/factory_bot.rb
lopata-0.1.27 lib/lopata/factory_bot.rb
lopata-0.1.26 lib/lopata/factory_bot.rb
lopata-0.1.25 lib/lopata/factory_bot.rb
lopata-0.1.24 lib/lopata/factory_bot.rb
lopata-0.1.23 lib/lopata/factory_bot.rb
lopata-0.1.22 lib/lopata/factory_bot.rb
lopata-0.1.21 lib/lopata/factory_bot.rb
lopata-0.1.20 lib/lopata/factory_bot.rb
lopata-0.1.19 lib/lopata/factory_bot.rb
lopata-0.1.18 lib/lopata/factory_bot.rb
lopata-0.1.17 lib/lopata/factory_bot.rb
lopata-0.1.16 lib/lopata/factory_bot.rb
lopata-0.1.15 lib/lopata/factory_bot.rb
lopata-0.1.14 lib/lopata/factory_bot.rb