Class: Opal::RSpec::TextFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- Opal::RSpec::TextFormatter
- Defined in:
- opal/opal/rspec/text_formatter.rb
Instance Method Summary collapse
- #dump_failure(example, index) ⇒ Object
- #dump_failure_info(example) ⇒ Object
- #dump_failures ⇒ Object
- #dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
- #finish_with_code(code) ⇒ Object
- #green(str) ⇒ Object
- #long_padding ⇒ Object
- #red(str) ⇒ Object
- #short_padding ⇒ Object
Instance Method Details
#dump_failure(example, index) ⇒ Object
17 18 19 20 |
# File 'opal/opal/rspec/text_formatter.rb', line 17 def dump_failure(example, index) puts "#{short_padding}#{index.next}) #{example.full_description}" dump_failure_info(example) end |
#dump_failure_info(example) ⇒ Object
22 23 24 25 26 27 |
# File 'opal/opal/rspec/text_formatter.rb', line 22 def dump_failure_info(example) exception = example.execution_result[:exception] exception_class_name = exception.class.name.to_s red "#{long_padding}#{exception_class_name}:" exception..to_s.split("\n").each { |line| red "#{long_padding} #{line}" } end |
#dump_failures ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'opal/opal/rspec/text_formatter.rb', line 5 def dump_failures if failed_examples.empty? puts "\nFinished" else puts "\nFailures:" failed_examples.each_with_index do |example, index| puts "\n" dump_failure(example, index) end end end |
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'opal/opal/rspec/text_formatter.rb', line 29 def dump_summary(duration, example_count, failure_count, pending_count) @duration = duration @example_count = example_count @failure_count = failure_count @pending_count = pending_count msg = "\n#{example_count} examples, #{failure_count} failures (time taken: #{duration})" if failure_count == 0 green msg finish_with_code(0) else red msg finish_with_code(1) end end |
#finish_with_code(code) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'opal/opal/rspec/text_formatter.rb', line 46 def finish_with_code(code) %x{ if (typeof(phantom) !== "undefined") { phantom.exit(code); } else { Opal.global.OPAL_SPEC_CODE = code; } } end |
#green(str) ⇒ Object
57 58 59 |
# File 'opal/opal/rspec/text_formatter.rb', line 57 def green(str) `console.log('\033[32m' + str + '\033[0m')` end |
#long_padding ⇒ Object
69 70 71 |
# File 'opal/opal/rspec/text_formatter.rb', line 69 def long_padding ' ' end |
#red(str) ⇒ Object
61 62 63 |
# File 'opal/opal/rspec/text_formatter.rb', line 61 def red(str) `console.log('\033[31m' + str + '\033[0m')` end |
#short_padding ⇒ Object
65 66 67 |
# File 'opal/opal/rspec/text_formatter.rb', line 65 def short_padding ' ' end |