Class: ButterflyNet::TestUnitAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/butterfly_net/test_unit_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestUnitAdapter

Returns a new instance of TestUnitAdapter.



6
7
8
# File 'lib/butterfly_net/test_unit_adapter.rb', line 6

def initialize
  @assertion_sets = []
end

Instance Attribute Details

#assertion_setsObject (readonly)

Returns the value of attribute assertion_sets.



4
5
6
# File 'lib/butterfly_net/test_unit_adapter.rb', line 4

def assertion_sets
  @assertion_sets
end

Instance Method Details

#add_command(line) ⇒ Object



10
11
12
13
# File 'lib/butterfly_net/test_unit_adapter.rb', line 10

def add_command(line)
  @assertion_sets << TestUnitMethod.new unless @assertion_sets.last
  @assertion_sets.last << line
end

#close_assertion_setObject



15
16
17
# File 'lib/butterfly_net/test_unit_adapter.rb', line 15

def close_assertion_set
  @assertion_sets << TestUnitMethod.new
end

#create_file(filename) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/butterfly_net/test_unit_adapter.rb', line 19

def create_file(filename)
  return nil if @assertion_sets.empty?
  file = File.open(filename, 'w+')
  file.puts "require \"test/unit\"\n\nclass TempTest < Test::Unit::TestCase"

  test_methods.each do |test_method|
    file.puts "\n  #{test_method}"
  end

  file.puts "\nend"
ensure
  file.close if file # todo: closing is good, but prevent writing partial data in case of exception
end

#test_methodsObject



33
34
35
36
37
38
39
40
41
# File 'lib/butterfly_net/test_unit_adapter.rb', line 33

def test_methods
  method_strings = []
  @assertion_sets.each_with_index do |assertions, i|


    method_strings << assertions.text(i + 1)
  end
  method_strings
end