Class: Matest::SpecPrinter
- Inherits:
-
Object
- Object
- Matest::SpecPrinter
- Includes:
- Color
- Defined in:
- lib/matest/spec_printer.rb
Instance Method Summary collapse
- #print_explanation_for(status) ⇒ Object
- #print_messages(runner) ⇒ Object
- #print_subexpression(subexpression, status) ⇒ Object
- #prints(res) ⇒ Object
Instance Method Details
#print_explanation_for(status) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/matest/spec_printer.rb', line 74 def print_explanation_for(status) subexpressions = Sorcerer.subexpressions(status.example.example_block.assertion_sexp).reverse.uniq.reverse if subexpressions.any? puts header("Explanation") subexpressions.all? do |code| print_subexpression(code, status) end end end |
#print_messages(runner) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/matest/spec_printer.rb', line 11 def (runner) puts header("\n\n### Messages ###") statuses = [] runner.info[:success] = true runner.info[:num_specs] = { total: 0 } runner.example_groups.each do |current_group| current_group.statuses.each do |status| runner.info[:num_specs][:total] += 1 runner.info[:num_specs][status.class] ||= 0 runner.info[:num_specs][status.class] += 1 if !status.is_a?(Matest::SpecPassed) puts send(colors[status.class], "\n[#{status.name}] #{status.description}") puts header("Location") puts " #{status.location}:" if status.is_a?(Matest::SpecFailed) runner.info[:success] = false puts header("Assertion") puts expression(" #{status.example.example_block.assertion}") if status.example.track_variables.any? puts header("Variables") status.example.track_variables.each do |var, val| puts key_value(var, val) end end if status.example.track_lets.any? puts header("Lets") status.example.track_lets.each do |var, val| puts key_value(var, val) end end print_explanation_for(status) end if status.is_a?(Matest::NotANaturalAssertion) runner.info[:success] = false puts " # => #{status.result.inspect}", reset("") print_explanation_for(status) end if status.is_a?(Matest::ExceptionRaised) runner.info[:success] = false puts error("EXCEPTION >> #{status.result}") status.result.backtrace.each do |l| puts error(" #{l}") end end end end end puts nil, "-"*50, nil puts "Specs:" runner.info[:num_specs].each { |klass, num| puts send(colors[klass], " #{num} #{klass.to_s.downcase}.") } end |
#print_subexpression(subexpression, status) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/matest/spec_printer.rb', line 84 def print_subexpression(subexpression, status) just_before_assertion = status.example.just_before_assertion code = just_before_assertion.code + subexpression result = Evaluator.new(just_before_assertion, just_before_assertion.before_assertion_block).eval_string(code) #result = Evaluator.new(just_before_assertion, proc{}).eval_string(code) if result.class != Matest::EvalErr explanation = [] explanation << expression(" #{subexpression}") explanation << "\n" explanation << value(" # => #{result}") puts explanation.join true else code = <<-CODE The assertion couldn't be explained. The error message was: #{result} CODE puts error(code) false end end |
#prints(res) ⇒ Object
7 8 9 |
# File 'lib/matest/spec_printer.rb', line 7 def prints(res) print send(colors[res.class], res.to_s) end |