Module: CoreEx::EmbeddedTests

Included in:
Object
Defined in:
lib/core_ex/embedded_tests.rb

Constant Summary collapse

@@embedded_test_mode =
nil
@@embedded_test_files =
Set.new
@@embedded_test_blocks =
[]

Instance Method Summary collapse

Instance Method Details

#embedded_test_mode(aRegexp) ⇒ Object



15
16
17
18
19
# File 'lib/core_ex/embedded_tests.rb', line 15

def embedded_test_mode ( aRegexp )
  raise 'No block needed' if block_given?
  require 'test/unit'
  @@embedded_test_mode = aRegexp
end

#embedded_test_mode?Boolean

Returns:

  • (Boolean)


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

def embedded_test_mode?
  !! @@embedded_test_mode
end

#run_embedded_test_sectionsObject



35
36
37
38
39
# File 'lib/core_ex/embedded_tests.rb', line 35

def run_embedded_test_sections
  @@embedded_test_blocks.each do |block|
    Kernel.instance_eval(&block)
  end
end

#test_section(__file__, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/core_ex/embedded_tests.rb', line 25

def test_section ( __file__, &block )
  __file__ = ::Pathname.new(__file__).expand_path
  if block_given? and __file__.to_s =~ @@embedded_test_mode
    unless @@embedded_test_files.include?(__file__)
      @@embedded_test_blocks << block
      @@embedded_test_files << __file__
    end
  end
end