Class: FunWith::Testing::TestCase

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/fun_with/testing/test_case.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._context(*args, &block) ⇒ Object

Convenience methods for disappearing a set of tests. Useful for focusing on one or two tests.



58
59
60
# File 'lib/fun_with/testing/test_case.rb', line 58

def self._context(*args, &block)
  puts "<<< WARNING >>> IGNORING TEST SET #{args.inspect}. Remove leading _ from '_context()' to reactivate."
end

._should(*args, &block) ⇒ Object



62
63
64
# File 'lib/fun_with/testing/test_case.rb', line 62

def self._should(*args, &block)
  puts "<<< WARNING >>> IGNORING TEST #{args.inspect}. Remove leading _ from '_should()' to reactivate."
end

.gem_to_test(gem_const = nil, test_mode = true) ⇒ Object

I may eventually decide that there’s a reason to specify which gem is being tested, but this really wasn’t it.

Okay, that was stupid. The point was to allow verbosity to be specified in the gem’s code, not just in the test suite. What would that be… MyGem.test_mode? MyGem.verbose_gem? MyGem.say



9
10
11
12
13
14
15
16
17
# File 'lib/fun_with/testing/test_case.rb', line 9

def self.gem_to_test( gem_const = nil, test_mode = true )
  if @fwt_gem_to_test
    return @fwt_gem_to_test
  elsif self.superclass.respond_to?( :gem_to_test )
    self.superclass.gem_to_test
  else
    nil
  end
end

.gem_to_test=(gem_const) ⇒ Object



19
20
21
# File 'lib/fun_with/testing/test_case.rb', line 19

def self.gem_to_test=( gem_const )
  @fwt_gem_to_test = gem_const
end

.in_test_mode?Boolean

Originally named test_mode?(), but Test::Unit::TestCase picked up on the fact that it started with “test” and tried to run it as a test in its own right



29
30
31
32
33
# File 'lib/fun_with/testing/test_case.rb', line 29

def self.in_test_mode?
  return self::FWT_TEST_MODE if self.constants.include?( :FWT_TEST_MODE )
  return self.superclass.in_test_mode? if self.superclass.respond_to?(:in_test_mode?)
  return false
end

.set_test_mode(mode = true) ⇒ Object



23
24
25
# File 'lib/fun_with/testing/test_case.rb', line 23

def self.set_test_mode( mode = true )
  self.const_set( :FWT_TEST_MODE, mode )
end

.set_verbose(mode = true) ⇒ Object



39
40
41
# File 'lib/fun_with/testing/test_case.rb', line 39

def self.set_verbose( mode = true )
  self.const_set( :FWT_TEST_VERBOSITY, mode )
end

.verbose?Boolean



43
44
45
46
47
# File 'lib/fun_with/testing/test_case.rb', line 43

def self.verbose?
  return self::FWT_TEST_VERBOSITY if self.constants.include?( :FWT_TEST_VERBOSITY )
  return self.superclass.verbose? if self.superclass.respond_to?(:verbose)
  return false
end

Instance Method Details

#build_message(*args) ⇒ Object



72
73
74
# File 'lib/fun_with/testing/test_case.rb', line 72

def build_message( *args )
  args.map(&:inspect).join("  ")
end

#in_test_mode?Boolean



35
36
37
# File 'lib/fun_with/testing/test_case.rb', line 35

def in_test_mode?
  self.class.in_test_mode?
end

#puts_if_verbose(msg, stream = $stdout) ⇒ Object



53
54
55
# File 'lib/fun_with/testing/test_case.rb', line 53

def puts_if_verbose( msg, stream = $stdout )
  stream.puts( msg ) if self.verbose?
end

#test_gem_validityObject



66
67
68
69
70
# File 'lib/fun_with/testing/test_case.rb', line 66

def test_gem_validity
  if jem = self.class.gem_to_test
    assert_equal [], jem.validate_gem
  end
end

#verbose?Boolean



49
50
51
# File 'lib/fun_with/testing/test_case.rb', line 49

def verbose?
  self.class.verbose?
end