Class: Assert::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/assert/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = nil) ⇒ Config

Returns a new instance of Config.


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/assert/config.rb', line 29

def initialize(settings = nil)
  @view   = Assert::DefaultView.new(self, $stdout)
  @suite  = Assert::DefaultSuite.new(self)
  @runner = Assert::DefaultRunner.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    = (env_runner_seed || random_runner_seed).to_i
  @changed_only   = false
  @changed_ref    = ""
  @single_test    = ""
  @pp_objects     = false
  @capture_output = false
  @halt_on_fail   = true
  @profile        = false
  @verbose        = false
  @list           = false
  @debug          = false

  apply(settings || {})
end

Class Method Details

.settings(*items) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# File 'lib/assert/config.rb', line 11

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

Instance Method Details

#apply(settings) ⇒ Object


59
60
61
62
63
64
65
66
# File 'lib/assert/config.rb', line 59

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

#env_runner_seedObject


82
83
84
# File 'lib/assert/config.rb', line 82

def env_runner_seed
  ENV["SEED"]
end

#random_runner_seedObject


86
87
88
89
90
91
92
# File 'lib/assert/config.rb', line 86

def random_runner_seed
  @random_runner_seed ||=
    begin
      srand
      srand % 0xFFFF
    end
end

#single_test?Boolean

Returns:

  • (Boolean)

68
69
70
# File 'lib/assert/config.rb', line 68

def single_test?
  !single_test.empty?
end

#single_test_file_lineObject


72
73
74
75
76
# File 'lib/assert/config.rb', line 72

def single_test_file_line
  @single_test_file_line ||= Assert::FileLine.parse(
    File.expand_path(single_test, Dir.pwd),
  )
end

#single_test_file_pathObject


78
79
80
# File 'lib/assert/config.rb', line 78

def single_test_file_path
  single_test_file_line&.file
end