Sha256: 44cd8e1821f08c7d9ad54bdda89731d613d3cec732173a9e26769fa10307a41f

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require 'assert/default_view'
require 'assert/runner'
require 'assert/suite'
require 'assert/utils'

module Assert

  class Config

    def self.settings(*items)
      items.each do |item|
        define_method(item) do |*args|
          if !(value = args.size > 1 ? args : args.first).nil?
            instance_variable_set("@#{item}", value)
          end
          instance_variable_get("@#{item}")
        end
      end
    end

    settings :view, :suite, :runner
    settings :test_dir, :test_helper, :test_file_suffixes
    settings :changed_proc, :pp_proc, :use_diff_proc, :run_diff_proc
    settings :runner_seed, :changed_only, :changed_ref, :pp_objects
    settings :capture_output, :halt_on_fail, :profile, :verbose, :list, :debug

    def initialize(settings = nil)
      @suite  = Assert::Suite.new(self)
      @view   = Assert::DefaultView.new(self, $stdout)
      @runner = Assert::Runner.new(self)

      @test_dir    = "test"
      @test_helper = "helper.rb"
      @test_file_suffixes = ['_tests.rb', '_test.rb']

      @changed_proc  = Assert::U.git_changed_proc
      @pp_proc       = Assert::U.stdlib_pp_proc
      @use_diff_proc = Assert::U.default_use_diff_proc
      @run_diff_proc = Assert::U.syscmd_diff_proc

      # option settings
      @runner_seed    = begin; srand; srand % 0xFFFF; end.to_i
      @changed_only   = false
      @changed_ref    = ''
      @pp_objects     = false
      @capture_output = false
      @halt_on_fail   = true
      @profile        = false
      @verbose        = false
      @list           = false
      @debug          = false

      self.apply(settings || {})
    end

    def apply(settings)
      settings.keys.each do |name|
        if !settings[name].nil? && self.respond_to?(name.to_s)
          self.send(name.to_s, settings[name])
        end
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
assert-2.15.0 lib/assert/config.rb