Module: EEtee::Assertions

Included in:
AssertionWrapper
Defined in:
lib/eetee/assertion_wrapper.rb

Instance Method Summary collapse

Instance Method Details

#be_a(klass) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/eetee/assertion_wrapper.rb', line 4

def be_a(klass)
  object_class = @object.class
  
  invert_helper(
    "expected instance of #{klass}, got #{object_class}",
    "instance of #{klass} not expected"
  ) do
    object_class.should == klass
  end
  
end

#close?(target, error_margin) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/eetee/assertion_wrapper.rb', line 38

def close?(target, error_margin)
  invert_helper(
    "expected #{target} += #{error_margin}, got #{@object}",
    "expected to be outside of #{target} += #{error_margin}, got #{@object}"
  ) do
    (target-error_margin .. target+error_margin).should.include?(@object)
  end
end

#raise(expected_error_class = RuntimeError) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eetee/assertion_wrapper.rb', line 16

def raise(expected_error_class = RuntimeError)
  @object.should.be_a ::Proc
  err = nil
  begin
    @object.call()
  rescue => ex
    err = ex
  end
  
  error_message = err ? err.message : ""
  fail_message = err ? "#{err.class} (#{error_message})" : "no error"
  
  invert_helper(
    "expected to raise #{expected_error_class}, got #{fail_message}",
    "expected not to raise #{expected_error_class} (#{error_message})"
  ) do
    err.class.should == expected_error_class
  end
  
  err
end