Class: Assert::View::Base

Inherits:
Object
  • Object
show all
Includes:
Assert::ViewHelpers
Defined in:
lib/assert/view.rb

Direct Known Subclasses

DefaultView

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assert::ViewHelpers

included

Constructor Details

#initialize(config, output_io) ⇒ Base

Returns a new instance of Base.



49
50
51
52
# File 'lib/assert/view.rb', line 49

def initialize(config, output_io)
  @config , @output_io, = config, output_io
  @output_io.sync = true if @output_io.respond_to?(:sync=)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



47
48
49
# File 'lib/assert/view.rb', line 47

def config
  @config
end

Instance Method Details

#after_loadObject



95
# File 'lib/assert/view.rb', line 95

def after_load;              end

#after_test(test) ⇒ Object



99
# File 'lib/assert/view.rb', line 99

def after_test(test);        end

#ansi_styled_msg(msg, result_or_sym) ⇒ Object



62
63
64
65
66
67
# File 'lib/assert/view.rb', line 62

def ansi_styled_msg(msg, result_or_sym)
  return msg if !self.is_tty? || !self.styled
  code = Assert::ViewHelpers::Ansi.code_for(*self.send("#{result_or_sym.to_sym}_styles"))
  return msg if code.empty?
  code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
end

#before_load(test_files) ⇒ Object

available callbacks from the runner:

  • ‘before_load`: called at the beginning, before the suite is loaded

  • ‘after_load`: called after the suite is loaded, just before `on_start`

    functionally equivalent to `on_start`
    
  • ‘on_start`: called when a loaded test suite starts running

  • ‘before_test`: called before a test starts running

    the test is passed as an arg
    
  • ‘on_result`: called when a running tests generates a result

    the result is passed as an arg
    
  • ‘after_test`: called after a test finishes running

    the test is passed as an arg
    
  • ‘on_finish`: called when the test suite is finished running

  • ‘on_interrupt`: called when the test suite is interrupted while running

    the interrupt exception is passed as an arg
    


94
# File 'lib/assert/view.rb', line 94

def before_load(test_files); end

#before_test(test) ⇒ Object



97
# File 'lib/assert/view.rb', line 97

def before_test(test);       end

#fire(callback, *args) ⇒ Object

define callback handlers to output information. handlers are instance_eval’d in the scope of the view instance. any stdout is captured and sent to the io stream.



75
76
77
# File 'lib/assert/view.rb', line 75

def fire(callback, *args)
  self.send(callback, *args)
end

#is_tty?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/assert/view.rb', line 58

def is_tty?
  !!@output_io.isatty
end

#on_finishObject



100
# File 'lib/assert/view.rb', line 100

def on_finish;               end

#on_interrupt(err) ⇒ Object



101
# File 'lib/assert/view.rb', line 101

def on_interrupt(err);       end

#on_result(result) ⇒ Object



98
# File 'lib/assert/view.rb', line 98

def on_result(result);       end

#on_startObject



96
# File 'lib/assert/view.rb', line 96

def on_start;                end


106
# File 'lib/assert/view.rb', line 106

def print(*args); @output_io.print(*args); end

#puts(*args) ⇒ Object

IO capture



105
# File 'lib/assert/view.rb', line 105

def puts(*args); @output_io.puts(*args); end

#viewObject



54
55
56
# File 'lib/assert/view.rb', line 54

def view
  self
end