Permalink
Browse files

start up tests

  • Loading branch information...
1 parent 04449c4 commit edb50c862189291450ede0123544746e6cb5c00b @holman committed Nov 21, 2010
Showing with 60 additions and 0 deletions.
  1. +1 −0 test/examples/urls.json
  2. +28 −0 test/helper.rb
  3. +31 −0 test/test_command.rb
View
1 test/examples/urls.json
@@ -0,0 +1 @@
+{"lists":[{"urls":[{"github":"https://github.com"},{"blog":"http://zachholman.com"}]}]}
View
28 test/helper.rb
@@ -0,0 +1,28 @@
+require 'rubygems'
+require 'test/unit'
+require 'redgreen'
+require 'mocha'
+
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require 'boom'
+
+# test/spec/mini 3
+# http://gist.github.com/25455
+# chris@ozmm.org
+# file:lib/test/spec/mini.rb
+def context(*args, &block)
+ return super unless (name = args.first) && block
+ require 'test/unit'
+ klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
+ def self.test(name, &block)
+ define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
+ end
+ def self.xtest(*args) end
+ def self.setup(&block) define_method(:setup, &block) end
+ def self.teardown(&block) define_method(:teardown, &block) end
+ end
+ (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
+ klass.class_eval &block
+end
View
31 test/test_command.rb
@@ -0,0 +1,31 @@
+require 'helper'
+
+class Boom::Command
+ # Intercept STDOUT and collect it
+ def self.output(s)
+ @saved_output ||= ''
+ @saved_output << s
+ end
+
+ def self.saved_output
+ @saved_output
+ end
+end
+
+class TestCommand < Test::Unit::TestCase
+
+ def setup
+ Boom::Storage.any_instance.expects(:json_file).
+ returns('test/examples/urls.json')
+ @storage = Boom::Storage.new
+ end
+
+ def command(cmd)
+ Boom::Command.execute(@storage,cmd)
+ Boom::Command.saved_output
+ end
+
+ def test_overview
+ assert_equal ' urls (2)', command(nil)
+ end
+end

0 comments on commit edb50c8

Please sign in to comment.