Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/test/unit/testcase.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.omit_if(message, *tests, &block) ⇒ Object

Omit (and don’t run setup/teardown) if block evalutes to true.



17
18
19
# File 'lib/ext/test/unit/testcase.rb', line 17

def omit_if(message, *tests, &block)
  attribute(:fast_omit, [caller, message, block], *tests)
end

.omit_rest_if(message, &block) ⇒ Object

Omit remaining tests in class (and don’t run setup/teardown) if block evalutes to true.



27
28
29
# File 'lib/ext/test/unit/testcase.rb', line 27

def omit_rest_if(message, &block)
  attribute(:fast_omit, [caller, message, block], {:keep => true})
end

.omit_unless(message, *tests, &block) ⇒ Object

Sugar for omit_if() { not .. }



22
23
24
# File 'lib/ext/test/unit/testcase.rb', line 22

def omit_unless(message, *tests, &block)
  attribute(:fast_omit, [caller, message, Proc.new { |*args| not block.call(*args) }], *tests)
end

.pend(message, *tests) ⇒ Object

Mark test as pending (and don’t run setup/teardown)



5
6
7
8
9
# File 'lib/ext/test/unit/testcase.rb', line 5

def pend(message, *tests)
  # We capture `caller` here so that we can give a better backtrace in
  # #pending_setup.
  attribute(:fast_pending, [caller, message], *tests)
end

.pend_rest_if(message) ⇒ Object

Mark remaining tests in class as pending (and don’t run setup/teardown)



12
13
14
# File 'lib/ext/test/unit/testcase.rb', line 12

def pend_rest_if(message)
  attribute(:fast_pending, [caller, message], {:keep => true})
end

Instance Method Details

#run_teardown(*args) ⇒ Object

We only run the #run_teardown if we’re not skipping this test, since teardown probably assumes setup() was called.



58
59
60
# File 'lib/ext/test/unit/testcase.rb', line 58

def run_teardown(*args)
  run_teardown_original(*args) unless @fast_skipped
end

#run_teardown_originalObject



55
# File 'lib/ext/test/unit/testcase.rb', line 55

alias_method :run_teardown_original, :run_teardown

#skipping_setupObject

We pend/omit() before setup runs, so that we don’t have to run the test’s setup if we’re skipping it.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ext/test/unit/testcase.rb', line 35

def skipping_setup
  @fast_skipped = false
  bt = nil
  begin
    if self[:fast_pending]
      bt, message = self[:fast_pending]
      pend(message)
    elsif self[:fast_omit]
      bt, message, cond_block = self[:fast_omit]
      omit_if(cond_block.call(self), message)
    end
  rescue PendedError, OmittedError => e
    @fast_skipped = true
    # We reset the backtrace to point to the line where the pend/omit call was
    # originally made.
    e.set_backtrace(bt) if bt
    raise e
  end
end