Class: TConsole::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/tconsole/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Reporter

Returns a new instance of Reporter.



6
7
8
# File 'lib/tconsole/reporter.rb', line 6

def initialize(config)
  self.config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/tconsole/reporter.rb', line 4

def config
  @config
end

Instance Method Details

#error(message = "") ⇒ Object

Public: Outputs an error message.



27
28
29
# File 'lib/tconsole/reporter.rb', line 27

def error(message = "")
  puts ::Term::ANSIColor.red(message)
end

#exclaim(message = "") ⇒ Object

Public: Outputs a positive informative message. Colors it green if the console supports it.



17
18
19
# File 'lib/tconsole/reporter.rb', line 17

def exclaim(message = "")
  puts ::Term::ANSIColor.green(message)
end

#exit_messageObject

Public: Outputs the tconsole exit message



108
109
110
111
# File 'lib/tconsole/reporter.rb', line 108

def exit_message
  info
  info("Exiting. Bye!")
end

#help_messageObject

Public: Prints a list of available commands



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tconsole/reporter.rb', line 58

def help_message
  puts
  puts "Available commands:"
  puts
  puts "reload                      # Reload your Rails environment"
  puts "set [variable] [value]      # Sets a runtime variable (see below for details)"
  puts "exit                        # Exit the console"
  puts "!failed                     # Runs the last set of failing tests"
  puts "!timings [limit]            # Lists the timings for the last test run, sorted."
  puts "[filename] [test_pattern]   # Run the tests contained in the given file"
  puts ".[command]                  # Executes the given command in a subshell"
  puts
  puts "Running file sets"
  puts
  puts "File sets are sets of files that are typically run together. For example,"
  puts "in Rails projects it's common to run `rake test:units` to run all of the"
  puts "tests under the units directory."
  puts
  puts "Available file sets:"

  config.file_sets.each do |set, paths|
    puts set
  end

  puts
  puts "Working with test patterns:"
  puts
  puts "All of the test execution commands include an optional test_pattern argument. A"
  puts "test pattern can be given to filter the executed tests to only those tests whose"
  puts "name matches the pattern given. This is especially useful when rerunning a failing"
  puts "test."
  puts
  puts "Runtime Variables"
  puts
  puts "You can set runtime variables with the set command. This helps out with changing"
  puts "features of TConsole that you may want to change at runtime. At present, the"
  puts "following runtime variables are available:"
  puts
  puts "fast        # Turns on fail fast mode. Values: on, off"
  puts

end

#info(message = "") ⇒ Object

Public: Ouptuts an informative message.



11
12
13
# File 'lib/tconsole/reporter.rb', line 11

def info(message = "")
  puts message
end

#timing(timing, test_id) ⇒ Object

Public: Outputs a timing for the timings command, using the proper color logic



46
47
48
49
50
51
52
53
54
55
# File 'lib/tconsole/reporter.rb', line 46

def timing(timing, test_id)
  output = "#{"%0.6f" % timing[:time]}s #{timing[:name]}"
  if timing[:time] > 1
    print ::Term::ANSIColor.red, output, ::Term::ANSIColor.reset
  else
    print ::Term::ANSIColor.green, output, ::Term::ANSIColor.reset
  end

  print ::Term::ANSIColor.magenta, " #{last_result}", ::Term::ANSIColor.reset, "\n"
end

#trace(message = "") ⇒ Object

Public: Outputs a trace message, when needed.



33
34
35
# File 'lib/tconsole/reporter.rb', line 33

def trace(message = "")
  puts "[tconsole trace] #{message}" if config.trace?
end

#trace_backtrace(exception) ⇒ Object

Public: Prints a backtrace out.



38
39
40
41
42
# File 'lib/tconsole/reporter.rb', line 38

def trace_backtrace(exception)
  trace("===========")
  trace(exception.backtrace.join("\n"))
  trace("===========")
end

#warn(message = "") ⇒ Object

Public: Outputs a warning message.



22
23
24
# File 'lib/tconsole/reporter.rb', line 22

def warn(message = "")
  puts ::Term::ANSIColor.yellow(message)
end

#welcome_messageObject

Public: Outputs the tconsole welcome message



102
103
104
105
# File 'lib/tconsole/reporter.rb', line 102

def welcome_message
  info
  info("Welcome to tconsole (v#{TConsole::VERSION}). Type 'help' for help or 'exit' to quit.")
end