Class: OSpec::PhantomFormatter
Instance Method Summary collapse
- #example_count ⇒ Object
- #example_failed(example) ⇒ Object
- #example_group_finished(group) ⇒ Object
- #example_group_started(group) ⇒ Object
- #example_passed(example) ⇒ Object
- #example_started(example) ⇒ Object
- #finish ⇒ Object
-
#initialize ⇒ PhantomFormatter
constructor
A new instance of PhantomFormatter.
- #log(str) ⇒ Object
- #log_green(str) ⇒ Object
- #log_red(str) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ PhantomFormatter
Returns a new instance of PhantomFormatter.
3 4 5 6 |
# File 'lib/ospec/phantom_formatter.rb', line 3 def initialize @examples = [] @failed_examples = [] end |
Instance Method Details
#example_count ⇒ Object
74 75 76 |
# File 'lib/ospec/phantom_formatter.rb', line 74 def example_count @examples.size end |
#example_failed(example) ⇒ Object
64 65 66 67 68 |
# File 'lib/ospec/phantom_formatter.rb', line 64 def example_failed example @failed_examples << example @example_group_failed = true log_red " #{example.description}" end |
#example_group_finished(group) ⇒ Object
56 57 |
# File 'lib/ospec/phantom_formatter.rb', line 56 def example_group_finished group end |
#example_group_started(group) ⇒ Object
50 51 52 53 54 |
# File 'lib/ospec/phantom_formatter.rb', line 50 def example_group_started group @example_group = group @example_group_failed = false log "\n#{group.description}" end |
#example_passed(example) ⇒ Object
70 71 72 |
# File 'lib/ospec/phantom_formatter.rb', line 70 def example_passed example log_green " #{example.description}" end |
#example_started(example) ⇒ Object
59 60 61 62 |
# File 'lib/ospec/phantom_formatter.rb', line 59 def example_started example @examples << example @example = example end |
#finish ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ospec/phantom_formatter.rb', line 23 def finish if @failed_examples.empty? log "\nFinished" log_green "#{example_count} examples, 0 failures" `phantom.exit(0)` else log "\nFailures:" @failed_examples.each_with_index do |example, idx| log "\n #{idx+1}. #{example.example_group.description} #{example.description}" exception = example.exception case exception when OSpec::ExpectationNotMetError output = exception. else output = "#{exception.class}: #{exception.}\n" output += " #{exception.backtrace.join "\n "}\n" end log_red " #{output}" end log "\nFinished" log_red "#{example_count} examples, #{@failed_examples.size} failures" `phantom.exit(1)` end end |
#log(str) ⇒ Object
16 17 18 |
# File 'lib/ospec/phantom_formatter.rb', line 16 def log(str) `console.log(str)` end |
#log_green(str) ⇒ Object
8 9 10 |
# File 'lib/ospec/phantom_formatter.rb', line 8 def log_green(str) `console.log('\\033[92m' + str + '\\033[0m')` end |
#log_red(str) ⇒ Object
12 13 14 |
# File 'lib/ospec/phantom_formatter.rb', line 12 def log_red(str) `console.log('\\033[31m' + str + '\\033[0m')` end |
#start ⇒ Object
20 21 |
# File 'lib/ospec/phantom_formatter.rb', line 20 def start end |