Sha256: f518f416c1d52fe13fc1a9616050fd23779b9ad10c7f6b6e9e1cf111300541a8

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'turnip_formatter/step_template/base'
require 'haml'

module TurnipFormatter
  module StepTemplate
    class Exception < Base
      on_failed :build_failed
      on_pending :build_pending

      def self.scss
        <<-EOS
          div#steps-statistics section.scenario {
              div.steps {
                  div.step_exception {
                      margin: 1em 0em;
                      padding: 1em;
                      border: 1px solid #999999;
                      background-color: #eee8d5;
                      color: #586e75;

                      dd {
                          margin-top: 1em;
                          margin-left: 1em;
                      }
                  }
              }
          }
        EOS
      end

      #
      # @param  [RSpec::Core::Example]  example
      #
      def build_failed(example)
        build(example.exception)
      end

      #
      # @param  [RSpec::Core::Example]  example
      #
      def build_pending(example)
        message = example.execution_result[:pending_message]
        exception = RSpec::Core::Pending::PendingDeclaredInExample.new(message)
        exception.set_backtrace([example.location])
        build(exception)
      end

      private

        def build(exception)
          template_step_exception.render(exception)
        end

        def template_step_exception
          @template_step_exception ||= Haml::Engine.new(<<-EOS)
%div.step_exception
  %dl
    %dt Failure:
    %dd
      %pre&= exception.to_s
    %dt Backtrace:
    %dd
      %ol
        - exception.backtrace.each do |line|
          %li&= line
          EOS
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
turnip_formatter-0.3.0 lib/turnip_formatter/step_template/exception.rb