Permalink
Browse files

use other test syntax

  • Loading branch information...
shaiguitar committed Sep 6, 2013
1 parent 8861d6c commit 3b7460f5ca36fde3533534725fa683acd6d42a7e
View
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+
+# git co .; for f in test/*.rb; do mkdir -p /tmp/test; cp $f /tmp/$f; scripts/renew_test_syntax /tmp/$f > $f ; done; b rake
+def replace(str)
+ str.match(/^(\s*)test/)
+ whitespace = $1
+ str = str.strip.downcase.gsub(/ do$/,"")
+ not_allowed = %w([ } = # > ' " % : - { ] . / \ @ , ( ) )
+ not_allowed.each {|c|
+ str = str.gsub(Regexp.new(Regexp.escape(c)),"")
+ }
+ str = str.gsub(" ","_")
+ str = str.gsub(/^(\s*)/,"#{whitespace}def ")
+ str
+end
+
+new_body = File.readlines(ARGV[0]).map{|l| l.match(/test.*do$/) ? replace(l) : l }
+puts new_body
View
@@ -3,7 +3,7 @@
module Haml
class CLITest < MiniTest::Unit::TestCase
- test "it needs an explicit interactive or non-interactive option" do
+ def test_it_needs_an_explicit_interactive_or_noninteractive_option
opts = {:non_interactive => nil, :interactive => nil}
with_highline do
begin
@@ -14,7 +14,7 @@ class CLITest < MiniTest::Unit::TestCase
end
end
- test "with a interactive option it needs a path" do
+ def test_with_a_interactive_option_it_needs_a_path
opts = {:non_interactive => nil, :path => nil}
with_highline do
begin
@@ -22,14 +22,14 @@ class ExceptionFinderTest < MiniTest::Unit::TestCase
%{link_to(pending_account_invoices_path(account),"http://random")} => ""
}
- test "it finds text pretty simply" do
+ def test_it_finds_text_pretty_simply
MATCHES.each do |k,v|
#puts "handling #{k}"
assert_equal find(k), v
end
end
- test "it actually needs to do something intellegent with intperolated values..." do
+ def test_it_actually_needs_to_do_something_intellegent_with_intperolated_values
# @FIXME
#raise "raw text matching needs to be responsible for knowing if needed to interpolate?"
end
View
@@ -8,30 +8,30 @@ def setup
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
end
- test "it can process the haml and replace it with other text" do
+ def test_it_can_process_the_haml_and_replace_it_with_other_text
@ex1.run
end
- test "it should be able to process filters with the haml_parser now..." do
+ def test_it_should_be_able_to_process_filters_with_the_haml_parser_now
#@FIXME
#raise 'implment me...check the finder#filters method and make sure you process the whole file at once so the parser gets it...'
end
- test "with a type of overwrite or dump affecting haml writer" do
+ def test_with_a_type_of_overwrite_or_dump_affecting_haml_writer
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :type => :overwrite)
assert_equal h.haml_writer.overwrite?, true
h = Haml::I18n::Extractor.new(file_path("ex1.haml"))
assert_equal h.haml_writer.overwrite?, false
end
- test "with a interactive option which prompts the user-per line" do
+ def test_with_a_interactive_option_which_prompts_the_userper_line
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
assert_equal h.interactive?, true
h = Haml::I18n::Extractor.new(file_path("ex1.haml"))
assert_equal h.interactive?, false
end
- test "with a interactive option takes user input into consideration for haml" do
+ def test_with_a_interactive_option_takes_user_input_into_consideration_for_haml
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
user_input = "D" # dump
File.readlines(file_path("ex1.haml")).size.times do
@@ -44,7 +44,7 @@ def setup
assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
end
- test "with a interactive option takes user input N as next and stops processing file" do
+ def test_with_a_interactive_option_takes_user_input_n_as_next_and_stops_processing_file
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
user_input = "D" # dump
File.readlines(file_path("ex1.haml")).size.times do
@@ -57,7 +57,7 @@ def setup
assert_equal File.read(h.haml_writer.path), File.read(file_path("ex1.haml"))
end
- test "with a interactive option takes user input into consideration for yaml" do
+ def test_with_a_interactive_option_takes_user_input_into_consideration_for_yaml
TestHelper.hax_shit
h = Haml::I18n::Extractor.new(file_path("ex1.haml"), :interactive => true)
user_input = "D" # dump
@@ -71,7 +71,7 @@ def setup
assert_equal YAML.load(File.read(h.yaml_tool.yaml_file)), {}
end
- test "with a interactive option user can tag a line for later review" do
+ def test_with_a_interactive_option_user_can_tag_a_line_for_later_review
TestHelper.hax_shit
if File.exist?(Haml::I18n::Extractor::TaggingTool::DB)
assert_equal File.readlines(Haml::I18n::Extractor::TaggingTool::DB), []
@@ -88,7 +88,7 @@ def setup
end
- test "can not initialize if the haml is not valid syntax" do
+ def test_can_not_initialize_if_the_haml_is_not_valid_syntax
begin
Haml::I18n::Extractor.new(file_path("bad.haml"))
assert false, "should not get here"
@@ -97,30 +97,30 @@ def setup
end
end
- test "it writes the haml to an out file if valid haml output" do
+ def test_it_writes_the_haml_to_an_out_file_if_valid_haml_output
FileUtils.rm_rf(@ex1.haml_writer.path)
assert_equal File.exists?(@ex1.haml_writer.path), false
@ex1.run
assert_equal File.exists?(@ex1.haml_writer.path), true
end
- test "it writes the locale info to an out file when run" do
+ def test_it_writes_the_locale_info_to_an_out_file_when_run
TestHelper.hax_shit
assert_equal File.exists?(@ex1.yaml_tool.yaml_file), false
@ex1.run
assert_equal File.exists?(@ex1.yaml_tool.yaml_file), true
assert_equal YAML.load(File.read(@ex1.yaml_tool.yaml_file)), @ex1.yaml_tool.yaml_hash
end
- test "sends a hash over of replacement info to its yaml tool when run" do
+ def test_sends_a_hash_over_of_replacement_info_to_its_yaml_tool_when_run
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
assert_equal @ex1.yaml_tool.locale_hash, nil
@ex1.run
assert @ex1.yaml_tool.locale_hash.is_a?(Hash), "its is hash of info about the files lines"
assert_equal @ex1.yaml_tool.locale_hash.size, @ex1.haml_reader.lines.size
end
- test "it fails before it writes to an out file if it is not valid" do
+ def test_it_fails_before_it_writes_to_an_out_file_if_it_is_not_valid
begin
@ex1 = Haml::I18n::Extractor.new(file_path("ex1.haml"))
@ex1.stub(:assign_new_body, nil) do #nop
View
@@ -7,20 +7,20 @@ def setup
@body = "- if true\n bar"
end
- test "it can collect metadata about lines" do
+ def test_it_can_collect_metadata_about_lines
tree = Haml::I18n::Extractor::HamlParser.new(@body)
line_metadatas = tree.flattened_values
assert_equal line_metadatas.size, 2
end
- test "it can collect metadata about lines" do
+ def test_it_can_collect_metadata_about_lines
parser = Haml::I18n::Extractor::HamlParser.new(@body)
line_metadatas = parser.flattened_values
assert_equal line_metadatas.size, 2
end
# easy api to use index <-> lineno
- test "it is sorted by line numbers" do
+ def test_it_is_sorted_by_line_numbers
parser = Haml::I18n::Extractor::HamlParser.new(@body)
line_metadatas = parser.flattened_values
assert_equal line_metadatas, line_metadatas.sort_by{|m| m[:line]}
View
@@ -17,16 +17,16 @@ def setup
@reader = Haml::I18n::Extractor::HamlReader.new(TEMP_FILE_PATH)
end
- test "has a body and a path" do
+ def test_has_a_body_and_a_path
assert_equal @reader.path, TEMP_FILE_PATH
assert_equal @reader.body, File.read(TEMP_FILE_PATH)
end
- test "has an array of lines in that file" do
+ def test_has_an_array_of_lines_in_that_file
assert_equal @reader.lines.size, LINE_COUNT
end
- test "has metadata about each line" do
+ def test_has_metadata_about_each_line
assert_equal @reader.metadata.size, LINE_COUNT
end
View
@@ -18,15 +18,15 @@ def teardown
FileUtils.rm_rf(ORIG_TEMP_FILE_PATH)
end
- test "it can dump the file and that is the default" do
+ def test_it_can_dump_the_file_and_that_is_the_default
@writer = Haml::I18n::Extractor::HamlWriter.new(ORIG_TEMP_FILE_PATH)
@writer.body = "This is what it is"
@writer.write_file
assert_equal @writer.path, "#{TestHelper::TMPDIR}foo_haml_extractor_test.i18n-extractor.haml"
assert_equal File.read(@writer.path), "This is what it is\n"
end
- test "it can overwrite the file" do
+ def test_it_can_overwrite_the_file
@writer = Haml::I18n::Extractor::HamlWriter.new(ORIG_TEMP_FILE_PATH, {:type => :overwrite})
@writer.body = "This is what it is"
@writer.write_file
View
@@ -12,35 +12,35 @@ def teardown
TestHelper.teardown_project_directory!
end
- test "it can handle namespaced views" do
+ def test_it_can_handle_namespaced_views
namespaced_extractor = Haml::I18n::Extractor.extractors.select{|ex| ex.haml_writer.path.match /namespace/ }.last
assert namespaced_extractor.yaml_tool.yaml_hash["en"]["namespace"], "namespace key works"
end
- test "it can handle partial views" do
+ def test_it_can_handle_partial_views
partial_extractor = Haml::I18n::Extractor.extractors.select{|ex| ex.haml_writer.path.match /_partial/ }.last
assert partial_extractor.yaml_tool.yaml_hash["en"]["view2"]["partial"], "partial filenames in yaml are w/out leading _"
end
## EXAMPLES
- test "it can replace a string body and have expected output ex4" do
+ def test_it_can_replace_a_string_body_and_have_expected_output_ex4
expected_output = File.read(file_path("ex4.output.haml"))
assert_equal Haml::I18n::Extractor.new(file_path("ex4.haml")).new_body, expected_output
end
- test "it can replace a string body and have expected output ex3" do
+ def test_it_can_replace_a_string_body_and_have_expected_output_ex3
expected_output = File.read(file_path("ex3.output.haml"))
assert_equal Haml::I18n::Extractor.new(file_path("ex3.haml")).new_body, expected_output
end
- test "it can replace a string body and have expected output ex2" do
+ def test_it_can_replace_a_string_body_and_have_expected_output_ex2
expected_output = File.read(file_path("ex2.output.haml"))
assert_equal Haml::I18n::Extractor.new(file_path("ex2.haml")).new_body, expected_output
end
- test "it can replace a string body and have expected output ex1" do
+ def test_it_can_replace_a_string_body_and_have_expected_output_ex1
expected_output = File.read(file_path("ex1.output.haml"))
assert_equal Haml::I18n::Extractor.new(file_path("ex1.haml")).new_body, expected_output
end
View
@@ -4,19 +4,19 @@ module Haml
# misnomer, this is also testing UserAction
class PrompterAndUserActionTest < MiniTest::Unit::TestCase
- test "asks_to_process_line_yes" do
+ def test_asks_to_process_line_yes
with_highline("y") do
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").replace_line?, true
end
end
- test "asks_to_process_line_no" do
+ def test_asks_to_process_line_no
with_highline("n") do
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").no_replace?, true
end
end
- test "test_asks_to_process_line_tag" do
+ def test_test_asks_to_process_line_tag
with_highline("t") do
assert_equal Haml::I18n::Extractor::Prompter.new.ask_user("orig", "replace").tag?, true
end
@@ -10,14 +10,14 @@ def teardown
FileUtils.rm_rf(FILE)
end
- test "It uses a file which it uses to keep track of user tagged lines" do
+ def test_it_uses_a_file_which_it_uses_to_keep_track_of_user_tagged_lines
TestHelper.hax_shit
assert ! File.exists?(FILE), "no tagging file should exist"
Haml::I18n::Extractor::TaggingTool.new
assert File.exists?(FILE), "tagging file should be created on init"
end
- test "It can write in a format" do
+ def test_it_can_write_in_a_format
tag_tool = Haml::I18n::Extractor::TaggingTool.new
tag_tool.write("/foo/bar/baz.txt", 49)
assert File.readlines(FILE).include?("/foo/bar/baz.txt:49\n"), "should write info"
Oops, something went wrong.

0 comments on commit 3b7460f

Please sign in to comment.