Class: SpecConverter
- Inherits:
-
Object
- Object
- SpecConverter
- Defined in:
- lib/spec_converter.rb
Overview
Simple converter to go to test/spec style This will change all files in place, so make sure you are properly backed up and/or committed to SVN!
Constant Summary collapse
- VERSION =
"0.0.4"
Class Method Summary collapse
Instance Method Summary collapse
-
#convert ⇒ Object
Convert tests from old spec style to new style – assumes you are in your project root and globs all tests in your test directory.
- #convert_line(line) ⇒ Object
- #translate_file(file) ⇒ Object
Class Method Details
.start ⇒ Object
6 7 8 9 |
# File 'lib/spec_converter.rb', line 6 def self.start spec_converter = SpecConverter.new spec_converter.convert end |
Instance Method Details
#convert ⇒ Object
Convert tests from old spec style to new style – assumes you are in your project root and globs all tests in your test directory.
13 14 15 16 17 18 19 |
# File 'lib/spec_converter.rb', line 13 def convert raise "No test diretory - you must run this script from your project root, which should also contain a test directory." unless File.directory?("test") tests = Dir.glob('test/**/*_test.rb') tests.each do |test_file| translate_file(test_file) end end |
#convert_line(line) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/spec_converter.rb', line 33 def convert_line(line) convert_rspec_old_style_names(line) convert_dust_style(line) convert_test_unit_class_name(line) convert_test_unit_methods(line) convert_def_setup(line) convert_assert(line) line end |
#translate_file(file) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/spec_converter.rb', line 21 def translate_file(file) translation = "" File.open(file) do |io| io.each_line do |line| translation << convert_line(line) end end File.open(file, "w") do |io| io.write(translation) end end |