Skip to content

Commit

Permalink
add some basic testing
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Mar 21, 2011
1 parent b5ff460 commit 0dbde48
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
13 changes: 0 additions & 13 deletions lib/formatador.rb
Expand Up @@ -113,16 +113,3 @@ def self.#{method}(*args, &block)
end

end

if __FILE__ == $0

Formatador.display_line("[negative]Formatador![/]")
Formatador.indent do
Formatador.display_lines([
'one',
'two'
])
end
Formatador.display_table([], [:foo])

end
28 changes: 28 additions & 0 deletions tests/basic_tests.rb
@@ -0,0 +1,28 @@
Shindo.tests("Formatador") do

tests("#display_line(Formatador)").returns(" Formatador\n") do
capture_stdout do
Formatador.display_line('Formatador')
end
end

output = <<-OUTPUT
one
two
OUTPUT

tests("#display_lines(['one', 'two']").returns(output) do
capture_stdout do
Formatador.display_lines(['one', 'two'])
end
end

tests("#indent { display_line('Formatador') }").returns(" Formatador\n") do
capture_stdout do
Formatador.indent do
Formatador.display_line('Formatador')
end
end
end

end
8 changes: 0 additions & 8 deletions tests/formatador_tests.rb

This file was deleted.

45 changes: 45 additions & 0 deletions tests/table_tests.rb
@@ -0,0 +1,45 @@
Shindo.tests("Formatador") do

output = <<-OUTPUT
+---+
| \e[1ma\e[0m |
+---+
| 1 |
+---+
| 2 |
+---+
OUTPUT

tests("#display_table([{:a => 1}, {:a => 2}])").returns(output) do
capture_stdout do
Formatador.display_table([{:a => 1}, {:a => 2}])
end
end

output = <<-OUTPUT
+--------+
| \e[1mheader\e[0m |
+--------+
OUTPUT

tests("#display_table([], [:header])").returns(output) do
capture_stdout do
Formatador.display_table([], [:header])
end
end

output = <<-OUTPUT
+--------+
| \e[1mheader\e[0m |
+--------+
| |
+--------+
OUTPUT

tests("#display_table([{:a => 1}], [:header])").returns(output) do
capture_stdout do
Formatador.display_table([{:a => 1}], [:header])
end
end

end
9 changes: 9 additions & 0 deletions tests/tests_helper.rb
Expand Up @@ -3,3 +3,12 @@
require 'formatador'
require 'rubygems'
require 'shindo'

def capture_stdout
old_stdout = $stdout
new_stdout = StringIO.new
$stdout = new_stdout
yield
$stdout = old_stdout
new_stdout.string
end

0 comments on commit 0dbde48

Please sign in to comment.