Class: Erudite::Executable

Inherits:
Object
  • Object
show all
Defined in:
lib/erudite/executable.rb

Overview

Parses, runs, and outputs examples.

Class Method Summary collapse

Class Method Details

.format_example(example) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/erudite/executable.rb', line 10

def self.format_example(example)
  if example.pass?
    format_passing_example(example)
  else
    format_failing_example(example)
  end
end

.format_failing_example(example) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/erudite/executable.rb', line 22

def self.format_failing_example(example)
  <<-TXT
- FAIL
  Source: #{example.source}
  Expected:
Output: #{example.expected.output.inspect}
Result: #{example.expected.result.inspect}
  Actual:
Output: #{example.actual.output.inspect}
Result: #{example.actual.result.inspect}
  TXT
end

.format_passing_example(_example) ⇒ Object



18
19
20
# File 'lib/erudite/executable.rb', line 18

def self.format_passing_example(_example)
  '- PASS'
end

.run(io) ⇒ Object



6
7
8
# File 'lib/erudite/executable.rb', line 6

def self.run(io)
  Parser.parse(io).each { |example| puts format_example(example) }
end