Class: Spec::TestToSpec::TranslationTestRunner

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/spec/test_to_spec/translation_test_runner.rb

Overview

A Test::Unit runner that doesn’t run tests, but translates them instead!

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suite) ⇒ TranslationTestRunner

Returns a new instance of TranslationTestRunner.


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/spec/test_to_spec/translation_test_runner.rb', line 15

def initialize(suite)
  log "Writing translated specs to #{$test2spec_options[:specdir]}"
  ObjectSpace.each_object(Class) do |klass|
    if klass < ::Test::Unit::TestCase
      begin
        translation = klass.to_rspec
        
        unless $test2spec_options[:dry_run]
          relative_path = underscore(klass.name)
          template = $test2spec_options[:template] ? IO.read($test2spec_options[:template]) : nil
          source = render(translation, relative_path, template)

          relative_path.gsub! /_test$/, "_spec"
          relative_path += ".rb"
          write(source, relative_path)
        else
          log "Successfully translated #{klass}"
        end
      rescue => e
        log "Failed to translate     #{klass}"
        verbose "Message: #{e.message}"
        verbose e.backtrace.join("\n")
      end
    end
  end
  puts "\nDone"
end

Class Method Details

.run(suite, output_level) ⇒ Object


11
12
13
# File 'lib/spec/test_to_spec/translation_test_runner.rb', line 11

def self.run(suite, output_level)
  self.new(suite)
end

Instance Method Details

#passed?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/spec/test_to_spec/translation_test_runner.rb', line 43

def passed?
  true
end