Class: AnySpec::Assertions

Inherits:
Object
  • Object
show all
Defined in:
lib/any-spec/assertions.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_case_instance) ⇒ Assertions

Returns a new instance of Assertions.



4
5
6
# File 'lib/any-spec/assertions.rb', line 4

def initialize(test_case_instance)
  @test_case = test_case_instance
end

Instance Method Details

#assert(expression) ⇒ Object



13
14
15
16
# File 'lib/any-spec/assertions.rb', line 13

def assert( expression )
  message = "#{expression.inspect} is not true".indent(3).red
  assert_block(message) { expression == true }
end

#assert_block(message = "assert_block failed") ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/any-spec/assertions.rb', line 35

def assert_block(message = "assert_block failed")
  return if(@test_case.last_assertion_result == false)
  @test_case.assertions += 1
  unless( yield )
    @test_case.last_assertion_result = false
    @test_case.message = message
  end
end

#assert_execution_failureObject



29
30
31
32
33
# File 'lib/any-spec/assertions.rb', line 29

def assert_execution_failure
  message = "      Execution of test case succeeded when it was expected to fail:\n"
  message += @test_case.test_output.prefix_each_line_with("# ").indent(4).grey
  assert_block(message) { @test_case.exit_status != 0 }
end

#assert_execution_successObject



23
24
25
26
27
# File 'lib/any-spec/assertions.rb', line 23

def assert_execution_success
  message = "Execution of test case failed when it was expected to succeed:\n".indent(3).red
  message += @test_case.test_output.prefix_each_line_with("# ").indent(4).grey
  assert_block(message) { @test_case.exit_status == 0 }
end

#assert_output(expected, output = @test_case.test_output) ⇒ Object



18
19
20
21
# File 'lib/any-spec/assertions.rb', line 18

def assert_output(expected, output = @test_case.test_output)
  message = "Expected output to be:\n<#{expected.inspect}> but was:\n<#{output.inspect}>".indent(3).red
  assert_block(message) { output == expected }
end

#flunkObject



8
9
10
11
# File 'lib/any-spec/assertions.rb', line 8

def flunk
  message = "Flunked.".indent(3).red
  assert_block(message) { false }
end