Class: Test::Unit::TestCase

Inherits:
Object show all
Defined in:
lib/test_case_extension.rb

Class Method Summary collapse

Class Method Details

.disallow_helpers!Object

call-seq: disallow_helpers!

Used to disallow helper methods in test specifications.

Test::Unit::TestCase.disallow_helper!

A test specification can override this behavior by passing the helper name (as a symbol) in the :allow options.

unit_tests :allow => [:create_something, :destroy_something] do
  test "verify something" do                                   
    ...
  end                   

  def create_something
    ...
  end                          

  def destroy_something
    ...
  end                                                     
end


50
51
52
# File 'lib/test_case_extension.rb', line 50

def self.disallow_helpers!
  @disallow_helpers = true
end

.disallow_helpers?Boolean

:nodoc:

Returns:

  • (Boolean)


54
55
56
# File 'lib/test_case_extension.rb', line 54

def self.disallow_helpers? #:nodoc:
  @disallow_helpers
end

.disallow_setup!Object

call-seq: disallow_setup!

Used to disallow setup methods in test specifications.

Test::Unit::TestCase.disallow_setup!

A test specification can override this behavior by passing :setup in the :allow options.

unit_tests :allow => :setup do
  def setup
    ...
  end        

  test "verify something" do                                   
    ...
  end                                                     
end


21
22
23
# File 'lib/test_case_extension.rb', line 21

def self.disallow_setup!
  @disallow_setup = true
end

.disallow_setup?Boolean

:nodoc:

Returns:

  • (Boolean)


25
26
27
# File 'lib/test_case_extension.rb', line 25

def self.disallow_setup? #:nodoc:
  @disallow_setup
end

.test(name, &block) ⇒ Object

call-seq: test(name, &block)

Used to define a test and assign it a descriptive name.

unit_tests do
  test "verify something" do                                   
    ...
  end                                                     
end


67
68
69
70
71
72
73
# File 'lib/test_case_extension.rb', line 67

def self.test(name, &block)
  test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
  raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s
  define_method test_name do
    instance_eval &block
  end
end