Sha256: 1cb0188db453b4ad57d2168e71a0f89d28892e172a267f5f2b97967b65466475

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

########################################################################################################################
# Provide various assertion, warning and exception methods
########################################################################################################################

require_relative 'abstract_reporter'
require_relative 'assertion'
require_relative 'test_result'
require_relative 'warning'

module Rproof
  class Censor
    def initialize(reporter, name, description)
      @reporter = reporter
      @test_result = TestResult.new name, description
    end
    attr_reader :test_result

    def assert_different(expected, obtained, comment)
      @test_result.add_assertion Assertion.new(expected, obtained, (obtained != expected), comment)
      @reporter.report_assertion @test_result.assertions.last
    end

    def assert_equal(expected, obtained, comment)
      @test_result.add_assertion Assertion.new(expected, obtained, (obtained == expected), comment)
      @reporter.report_assertion @test_result.assertions.last
    end

    def assert_exception(expected, comment, &block)
      error = nil
      begin
        block.call
      rescue Exception => error
      ensure
        assert_equal(expected, error.class, comment)
      end
    end

    def assert(statement, comment)
      assert_equal true, statement, comment
    end

    def warning(message)
      @test_result.add_warning Warning.new(message)
      @reporter.report_warning @test_result.warnings.last
    end

    def log_exception(error)
      @test_result.add_exception error
      @reporter.report_exception @test_result.exceptions.last
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rproof-0.0.1 lib/rproof/censor.rb