test/test_rube.rb in rube-0.1.1 vs test/test_rube.rb in rube-0.1.2
- old
+ new
@@ -1,19 +1,19 @@
require File.dirname(__FILE__) + '/test_helper.rb'
class TestRubeBasic < Test::Unit::TestCase
def setup
- @new_rube = Rube.new
+ @new_rube = Rube::Generator.new
end
def test_truth
assert true
end
def test_creates_rube_object
- assert_instance_of Rube, @new_rube, "Rube.new does not create Rube object"
+ assert_instance_of Rube::Generator, @new_rube, "Rube:Generator.new does not create Rube::Generator object"
end
def test_rube_object_has_tasks
assert_respond_to @new_rube, :tasks
end
@@ -63,18 +63,10 @@
end
def test_rube_object_trim_mode
assert_respond_to @new_rube, :trim_mode
end
-
- def test_rube_object_to_string
- assert_respond_to @new_rube, :to_string
- end
-
- def test_rube_object_to_file
- assert_respond_to @new_rube, :to_file
- end
def test_rube_object_go
assert_respond_to @new_rube, :generate
end
@@ -84,11 +76,11 @@
end
class TestRubeTaskManipulation < Test::Unit::TestCase
def setup
- @empty_rube = Rube.new
+ @empty_rube = Rube::Generator.new
end
def test_empty_rube_object_has_no_tasks
assert_equal @empty_rube.tasks.size, 0
end
@@ -141,11 +133,11 @@
end
class TestRubeSettings < Test::Unit::TestCase
def setup
- @empty_rube = Rube.new
+ @empty_rube = Rube::Generator.new
end
def test_rube_default_disable_percent
assert_equal false, !!@empty_rube.disable_percent
end
@@ -170,35 +162,17 @@
def test_rube_object_preserves_from_command_line
@empty_rube.from_command_line = 'foo'
assert_equal 'foo', @empty_rube.from_command_line
end
-
- def test_rube_default_to_string
- assert_equal false, !!@empty_rube.to_string
- end
-
- def test_rube_object_preserves_to_string
- @empty_rube.to_string = 'foo'
- assert_equal 'foo', @empty_rube.to_string
- end
-
- def test_rube_default_to_file
- assert_equal nil, @empty_rube.to_file
- end
-
- def test_rube_object_preserves_to_file
- @empty_rube.to_file = 'foo'
- assert_equal 'foo', @empty_rube.to_file
- end
end
class TestRubeTrimLevel < Test::Unit::TestCase
def setup
- @empty_rube = Rube.new
- @disabled_rube = Rube.new
+ @empty_rube = Rube::Generator.new
+ @disabled_rube = Rube::Generator.new
@disabled_rube.disable_percent = true
end
def test_rube_default_trim_level
assert_equal '0', @empty_rube.trim_level
@@ -272,117 +246,82 @@
end
class TestRubeProcessing < Test::Unit::TestCase
def setup
- @rube = Rube.new
- @save_stdout = $stdout
+ @out = StringIO.new
+ @rube = Rube::Generator.new(@out)
end
- def teardown
- $stdout = @save_stdout
- end
-
- def test_simple_eval_to_stdout
- StringIO.open do |out|
- $stdout = out
- @rube.add_task :eval, 'puts "foo"'
- res = @rube.generate
- assert_equal "foo\n", out.string, "Failed to produce expected output on $stdout"
- assert_equal nil, res, "Without redirection, rube.generate should return nil"
- end
- end
-
- def test_simple_eval_to_string
- @rube.to_string = true
+ def test_simple_eval
@rube.add_task :eval, 'puts "foo"'
- out = @rube.generate
- assert_equal "foo\n", out, "Failed to output to string"
- end
-
- def test_simple_eval_to_file
- out = Tempfile.new('testout')
- @rube.to_file = out.path
- @rube.add_task :eval, 'puts "foo"'
res = @rube.generate
- out.close
- output = File.read(out.path)
- assert_equal "foo\n", output, "Failed to produce expected output on file #{out.path}"
+ assert_equal "foo\n", @out.string, "Failed to produce expected output on $stdout"
assert_equal nil, res, "Without redirection, rube.generate should return nil"
end
def test_process_require_task
- StringIO.open do |out|
- $stdout = out
- @rube.add_task :require, 'English'
- @rube.add_task :eval, 'puts $PID'
- @rube.generate
- # If English doesn't load properly, then $PID is nil; if it does, then it's a numeric process id
- assert_match(/^\d+$/, out.string.chomp, "Failed to load require file")
- end
+ @rube.add_task :require, 'English'
+ @rube.add_task :eval, 'puts $PID'
+ @rube.generate
+ # If English doesn't load properly, then $PID is nil; if it does, then it's a numeric process id
+ assert_match(/^\d+$/, @out.string.chomp, "Failed to load require file")
end
def test_process_template_task
- @rube.to_string = true
@rube.add_task :template, 'templates/test1'
- out = @rube.generate
- assert_equal "foo\nblurg\nblurble\n\nfarb\n\n", out, "Failed to produce expected result from test1 template"
+ @rube.generate
+ assert_equal "foo\nblurg\nblurble\n\nfarb\n\n", @out.string, "Failed to produce expected result from test1 template"
end
def test_process_template_task_with_disabled_percent
- @rube.to_string = true
@rube.disable_percent = true
@rube.add_task :template, 'templates/test1'
- out = @rube.generate
+ @rube.generate
# Note: test1 template produces different results with % lines disabled
- assert_equal "foo\nblurg\nblurble\n\n% z = 'farb'\nbarf\n\n", out, "Failed to produce expected result from test1 template with percentage lines disabled"
+ assert_equal "foo\nblurg\nblurble\n\n% z = 'farb'\nbarf\n\n", @out.string, "Failed to produce expected result from test1 template with percentage lines disabled"
end
def test_process_template_task_with_trim_level_1
- @rube.to_string = true
@rube.trim_level = 1
@rube.add_task :template, 'templates/test1'
- out = @rube.generate
- assert_equal "foo\nblurgblurblefarb\n", out, "Failed to produce expected result from test1 template"
+ @rube.generate
+ assert_equal "foo\nblurgblurblefarb\n", @out.string, "Failed to produce expected result from test1 template"
end
def test_process_template_task_with_trim_level_2
- @rube.to_string = true
@rube.trim_level = 2
@rube.add_task :template, 'templates/test1'
out = @rube.generate
- assert_equal "foo\nblurgblurble\nfarb\n", out, "Failed to produce expected result from test1 template"
+ assert_equal "foo\nblurgblurble\nfarb\n", @out.string, "Failed to produce expected result from test1 template"
end
def test_process_template_with_persistent_variable
- @rube.to_string = true
@rube.add_task :eval, 'b="foo"'
@rube.add_task :template, 'templates/test2'
- out = @rube.generate
- assert_equal "bar\nfoo*2\n", out, "Failed to produce expected result from test2 template with passed variable value"
+ @rube.generate
+ assert_equal "bar\nfoo*2\n", @out.string, "Failed to produce expected result from test2 template with passed variable value"
end
end
class TestRubeErrors < Test::Unit::TestCase
def setup
- @rube = Rube.new
+ @out = StringIO.new
+ @rube = Rube::Generator.new(@out)
end
def test_bad_eval
- @rube.to_string = true
@rube.add_task :eval, 'foo'
assert_raises(Rube::ScriptError) { @rube.generate }
end
def test_bad_require
- @rube.to_string = true
@rube.add_task :require, 'foo'
assert_raises(Rube::MissingRequireError) { @rube.generate }
end
def test_bad_template
- @rube.to_string = true
@rube.add_task :template, 'foo'
assert_raises(Rube::MissingTemplateError) { @rube.generate }
end
end
@@ -425,91 +364,66 @@
class TestRubeCommandLineIndirectly < Test::Unit::TestCase
#
# Not really an exhaustive test, but if this works, things should be okay
#
-
- def setup
- @rube = Rube.new
- @save_stdout = $stdout
- end
-
- def teardown
- $stdout = @save_stdout
- end
def test_eval
StringIO.open do |out|
- $stdout = out
- @rube.process_options('-E', '-e', 'puts "foo"')
- res = @rube.generate
+ res = Rube::CLI.execute(out, ['-E', '-e', 'puts "foo"'])
assert_equal "foo\n", out.string, "Failed to produce expected output on $stdout"
end
end
def test_process_require_task
StringIO.open do |out|
- $stdout = out
- @rube.process_options('-E', '-r', 'English', '-e', 'puts $PID')
- @rube.generate
+ res = Rube::CLI.execute(out, ['-E', '-r', 'English', '-e', 'puts $PID'])
# If English doesn't load properly, then $PID is nil; if it does, then it's a numeric process id
assert_match(/^\d+$/, out.string.chomp, "Failed to load require file")
end
end
def test_process_require_task_long_form
StringIO.open do |out|
- $stdout = out
- @rube.process_options('--explicit', '--require', 'English', '--eval', 'puts $PID')
- @rube.generate
+ res = Rube::CLI.execute(out, ['--explicit', '--require', 'English', '--eval', 'puts $PID'])
# If English doesn't load properly, then $PID is nil; if it does, then it's a numeric process id
assert_match(/^\d+$/, out.string.chomp, "Failed to load require file")
end
end
def test_process_template_task
StringIO.open do |out|
- $stdout = out
- @rube.process_options('templates/test1')
- @rube.generate
+ res = Rube::CLI.execute(out, ['templates/test1'])
assert_equal "foo\nblurg\nblurble\n\nfarb\n\n", out.string, "Failed to produce expected result from test1 template"
end
end
def test_process_template_task_with_disabled_percent
StringIO.open do |out|
- $stdout = out
- @rube.process_options('-P', 'templates/test1')
- @rube.generate
+ res = Rube::CLI.execute(out, ['-P', 'templates/test1'])
# Note: test1 template produces different results with % lines disabled
assert_equal "foo\nblurg\nblurble\n\n% z = 'farb'\nbarf\n\n", out.string, "Failed to produce expected result from test1 template with percentage lines disabled"
end
end
def test_process_template_task_with_trim_level_1
StringIO.open do |out|
- $stdout = out
- @rube.process_options('--trim', '1', 'templates/test1')
- @rube.generate
+ res = Rube::CLI.execute(out, ['--trim', '1', 'templates/test1'])
assert_equal "foo\nblurgblurblefarb\n", out.string, "Failed to produce expected result from test1 template"
end
end
def test_process_template_task_with_trim_level_2
StringIO.open do |out|
- $stdout = out
- @rube.process_options('--trim', '2', 'templates/test1')
- @rube.generate
+ res = Rube::CLI.execute(out, ['--trim', '2', 'templates/test1'])
assert_equal "foo\nblurgblurble\nfarb\n", out.string, "Failed to produce expected result from test1 template"
end
end
def test_process_template_with_persistent_variable
StringIO.open do |out|
- $stdout = out
- @rube.process_options('--eval', 'b="foo"', 'templates/test2')
- @rube.generate
+ res = Rube::CLI.execute(out, ['--eval', 'b="foo"', 'templates/test2'])
assert_equal "bar\nfoo*2\n", out.string, "Failed to produce expected result from test2 template with passed variable value"
end
end
end
@@ -527,10 +441,10 @@
# If English doesn't load properly, then $PID is nil; if it does, then it's a numeric process id
assert_match(/^\d+$/, res.chomp, "Failed to load require file")
end
def test_process_template_task
- res = `rube.rb templates/test1` # Not sure why it insists on the '.rb' here, but it does...
+ res = `rube templates/test1` # Not sure why it insists on the '.rb' here, but it does...
assert_equal "foo\nblurg\nblurble\n\nfarb\n\n", res, "Failed to produce expected result from test1 template"
end
def test_process_implicit_template_task
res = `rube < templates/test1`