lib/assert/view.rb in assert-2.15.0 vs lib/assert/view.rb in assert-2.15.1

- old
+ new

@@ -1,12 +1,15 @@ require 'assert/config' +require 'assert/config_helpers' require 'assert/suite' require 'assert/view_helpers' module Assert - module View + class View + include Assert::ConfigHelpers + include Assert::ViewHelpers # this method is used to bring in custom user-specific views # require views by passing either a full path to the view ruby file # or passing the name of a view installed in ~/.assert/views @@ -24,89 +27,70 @@ msg << " Did you install it in `~/.assert/views`?" if !view_name.match(/\A\//) warn msg end end - class Base - include Assert::ViewHelpers + # setup options and their default values - # setup options and their default values + option 'styled', false + option 'pass_styles' # none + option 'fail_styles' # none + option 'error_styles' # none + option 'skip_styles' # none + option 'ignore_styles' # none - option 'styled', false - option 'pass_styles' # none - option 'fail_styles' # none - option 'error_styles' # none - option 'skip_styles' # none - option 'ignore_styles' # none + option 'pass_abbrev', '.' + option 'fail_abbrev', 'F' + option 'ignore_abbrev', 'I' + option 'skip_abbrev', 'S' + option 'error_abbrev', 'E' - option 'pass_abbrev', '.' - option 'fail_abbrev', 'F' - option 'ignore_abbrev', 'I' - option 'skip_abbrev', 'S' - option 'error_abbrev', 'E' + attr_reader :config - attr_reader :config + def initialize(config, output_io) + @config , @output_io, = config, output_io + @output_io.sync = true if @output_io.respond_to?(:sync=) + end - def initialize(config, output_io) - @config , @output_io, = config, output_io - @output_io.sync = true if @output_io.respond_to?(:sync=) - end + def view; self; end - def view - self - end + def is_tty? + !!@output_io.isatty + end - def is_tty? - !!@output_io.isatty - end + # Callbacks - 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 + # define callback handlers to output information. These will be called + # by the test runner. - # Callbacks + # 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 - # 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. + def before_load(test_files); end + def after_load; end + def on_start; end + def before_test(test); end + def on_result(result); end + def after_test(test); end + def on_finish; end + def on_interrupt(err); end - def fire(callback, *args) - self.send(callback, *args) - end + # IO capture - # 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 - - def before_load(test_files); end - def after_load; end - def on_start; end - def before_test(test); end - def on_result(result); end - def after_test(test); end - def on_finish; end - def on_interrupt(err); end - - # IO capture - - def puts(*args); @output_io.puts(*args); end - def print(*args); @output_io.print(*args); end - - end + def puts(*args); @output_io.puts(*args); end + def print(*args); @output_io.print(*args); end end end