Class: Fix::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/fix/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(front_object, seed: Random.new_seed, color: true, stdout: STDOUT, stderr: STDERR) ⇒ Test

Returns a new instance of Test.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fix/test.rb', line 7

def initialize front_object, seed: Random.new_seed, color: true, stdout: STDOUT, stderr: STDERR
  @options = { color: color, stdout: stdout, stderr: stderr }
  @options.fetch(:stdout).puts about "Run options: --seed #{seed}"

  random = Random.new seed
  expectations = ExpectationSet.instance.to_a.shuffle(random: random)

  start_time = Time.now
  @results = expectations.map do |expectation|
    log expectation.evaluate front_object
  end
  @total_time = Time.now - start_time

  @options.fetch(:stdout).puts about "\nFinished in #{@total_time} seconds."
  @options.fetch(:stdout).puts statistics

  freeze
end

Instance Attribute Details

#total_timeObject (readonly)

Returns the value of attribute total_time.



5
6
7
# File 'lib/fix/test.rb', line 5

def total_time
  @total_time
end

Instance Method Details

#fail?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fix/test.rb', line 30

def fail?
  !pass?
end

#pass?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/fix/test.rb', line 26

def pass?
  @results.all? {|result| state(result) == :success }
end

#statisticsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fix/test.rb', line 34

def statistics
  errors    = @results.select {|result| state(result) == :error   }
  failures  = @results.select {|result| state(result) == :failure }

  color = if errors.any?
    :error
  elsif failures.any?
    :failure
  else
    :success
  end

  __send__ color, [
    "#{@results.length} tests",
    "#{failures.length} failures",
    "#{errors.length} errors"
  ].join(', ')
end