Class: Rproof::Censor

Inherits:
Object
  • Object
show all
Defined in:
lib/rproof/censor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter, name, description) ⇒ Censor

Returns a new instance of Censor.



12
13
14
15
# File 'lib/rproof/censor.rb', line 12

def initialize(reporter, name, description)
  @reporter = reporter
  @test_result = TestResult.new name, description
end

Instance Attribute Details

#test_resultObject (readonly)

Returns the value of attribute test_result.



16
17
18
# File 'lib/rproof/censor.rb', line 16

def test_result
  @test_result
end

Instance Method Details

#assert(statement, comment) ⇒ Object



38
39
40
# File 'lib/rproof/censor.rb', line 38

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

#assert_different(expected, obtained, comment) ⇒ Object



18
19
20
21
# File 'lib/rproof/censor.rb', line 18

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

#assert_equal(expected, obtained, comment) ⇒ Object



23
24
25
26
# File 'lib/rproof/censor.rb', line 23

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

#assert_exception(expected, comment, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/rproof/censor.rb', line 28

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

#log_exception(error) ⇒ Object



47
48
49
50
# File 'lib/rproof/censor.rb', line 47

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

#warning(message) ⇒ Object



42
43
44
45
# File 'lib/rproof/censor.rb', line 42

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