Sha256: 376cf3839a84305e675fe45f829214c14e41d40eec916dde3a017dace140b946

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require 'omnitest/reporters'
module Omnitest
  module Command
    class List < Omnitest::Command::Base
      include Omnitest::Reporters

      def call
        setup
        @reporter = Omnitest::Reporters.reporter(options[:format], shell)
        tests = parse_subcommand(args.shift, args.shift)

        table = [header_row]
        table += tests.map do | scenario |
          row(scenario)
        end
        print_table(table)
      end

      private

      def header_row
        row = []
        row << colorize('Suite', :green)
        row << colorize('Scenario', :green)
        row << colorize('Project', :green)
        row << colorize('Status', :green)
        row << colorize('Source', :green) if options[:source]
        row
      end

      def row(scenario)
        row = []
        row << color_pad(scenario.suite)
        row << color_pad(scenario.name)
        row << color_pad(scenario.psychic.name)
        row << format_status(scenario)
        if options[:source]
          source_file = scenario.absolute_source_file ? scenario.source_file : colorize('<No code sample>', :red)
          row << source_file
        end
        row
      end

      def print_table(*args)
        @reporter.print_table(*args)
      end

      def colorize(string, *args)
        return string unless @reporter.respond_to? :set_color
        @reporter.set_color(string, *args)
      end

      def color_pad(string)
        string + colorize('', :white)
      end

      def format_status(scenario)
        colorize(scenario.status_description, scenario.status_color)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
omnitest-0.2.2 lib/omnitest/command/list.rb
omnitest-0.2.1 lib/omnitest/command/list.rb