Sha256: aab2cdaba2efb7bafb1741b028b6a73c570dd9764a70b644fbf6ab788f8f4d81

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

module BlueprintsBoy
  # Contains configuration of blueprints. Instance of this is yielded in Blueprints.enable block.
  # @example Configuring through Blueprints.enable block
  #   Blueprints.enable do |config|
  #     config.prebuild = :user, :profile
  #   end
  # @example Configuring directly
  #   Blueprints.config.transactions = false
  class Configuration
    # Allows passing custom filename pattern in case blueprints are held in place other than spec/blueprint, test/blueprint, blueprint.
    attr_reader :filenames
    # Allows passing scenarios that should be prebuilt and available in all tests. Works similarly to fixtures.
    attr_accessor :prebuild
    # Allows passing custom root folder to use in case of non rails project. Defaults to Rails.root or current folder if Rails is not defined.
    attr_reader :root
    # By default blueprints runs each test in it's own transaction. This may sometimes be not desirable so this options allows to turn this off.
    attr_accessor :transactions
    # Define global blueprints that are prebuilt in all tests
    attr_reader :global

    # Initializes new Configuration object with default attributes.
    # By defaults filename patterns are: blueprint.rb and blueprint/*.rb in spec, test and root directories.
    # Also by default prebuildable blueprints list is empty, transactions are enabled and root is set to Rails.root or current directory.
    def initialize
      self.filenames = [nil, "spec", "test"].map do |dir|
        ['blueprints.rb', 'blueprints/*.rb'].map do |pattern|
          File.join([dir, pattern].compact)
        end
      end
      @prebuild = []
      @transactions = true
      @root = defined?(Rails) ? Rails.root : Pathname.pwd
      @global = []
    end

    def filenames=(value)
      @filenames = Array(value).flatten.collect { |path| Pathname.new(path) }
    end

    def root=(value)
      @root = Pathname.new(value)
    end

    def global=(value)
      @global = Array(value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blueprints_boy-1.0.0 lib/blueprints_boy/configuration.rb