Permalink
Browse files

starting a test suite

  • Loading branch information...
1 parent 1d75ee0 commit 2ce9c66e5606bb4218ce8f889f8a591c7be3aa56 @schacon schacon committed Sep 11, 2011
View
@@ -9,6 +9,8 @@ gem "parslet"
group :development do
gem "mg"
+ gem "turn"
+ gem "rack-test"
end
group :optional do
View
File renamed without changes.
View
@@ -1,7 +1,27 @@
+require 'rake/testtask'
+
begin
require 'mg'
rescue LoadError
abort "Please `gem install mg`"
end
MG.new("showoff.gemspec")
+
+#
+# Tests
+#
+
+task :default => :test
+
+desc "Run tests"
+task :turn do
+ suffix = "-n #{ENV['TEST']}" if ENV['TEST']
+ sh "turn test/*_test.rb #{suffix}"
+end
+
+Rake::TestTask.new do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
View
@@ -1,84 +0,0 @@
-# PrinceXML Ruby interface.
-# http://www.princexml.com
-#
-# Library by Subimage Interactive - http://www.subimage.com
-#
-#
-# USAGE
-# -----------------------------------------------------------------------------
-# princely = Princely.new()
-# html_string = render_to_string(:template => 'some_document')
-# send_data(
-# princely.pdf_from_string(html_string),
-# :filename => 'some_document.pdf'
-# :type => 'application/pdf'
-# )
-#
-$:.unshift(File.dirname(__FILE__))
-
-class Princely
- VERSION = "1.0.0" unless const_defined?("VERSION")
-
- attr_accessor :exe_path, :style_sheets, :log_file
-
- # Initialize method
- #
- def initialize()
- # Finds where the application lives, so we can call it.
- @exe_path = `which prince`.chomp
- raise "Cannot find prince command-line app in $PATH" if @exe_path.length == 0
- @style_sheets = ''
- @log_file = "/tmp/prince.log"
- end
-
- # Sets stylesheets...
- # Can pass in multiple paths for css files.
- #
- def add_style_sheets(*sheets)
- for sheet in sheets do
- @style_sheets << " -s #{sheet} "
- end
- end
-
- # Returns fully formed executable path with any command line switches
- # we've set based on our variables.
- #
- def exe_path
- # Add any standard cmd line arguments we need to pass
- @exe_path << " --input=html --server --log=#{@log_file} "
- @exe_path << @style_sheets
- return @exe_path
- end
-
- # Makes a pdf from a passed in string.
- #
- # Returns PDF as a stream, so we can use send_data to shoot
- # it down the pipe using Rails.
- #
- def pdf_from_string(string, output_file = '-')
- path = self.exe_path()
- # Don't spew errors to the standard out...and set up to take IO
- # as input and output
- path << ' --silent - -o -'
-
- # Actually call the prince command, and pass the entire data stream back.
- pdf = IO.popen(path, "w+")
- pdf.puts(string)
- pdf.close_write
- result = pdf.gets(nil)
- pdf.close_read
- return result
- end
-
- def pdf_from_string_to_file(string, output_file)
- path = self.exe_path()
- # Don't spew errors to the standard out...and set up to take IO
- # as input and output
- path << " --silent - -o '#{output_file}' >> '#{@log_file}' 2>> '#{@log_file}'"
-
- # Actually call the prince command, and pass the entire data stream back.
- pdf = IO.popen(path, "w+")
- pdf.puts(string)
- pdf.close
- end
-end
View
@@ -7,7 +7,6 @@
here = File.expand_path(File.dirname(__FILE__))
require "#{here}/showoff_utils"
-require "#{here}/princely"
require "#{here}/commandline_parser"
begin
@@ -0,0 +1,9 @@
+!SLIDE
+# My Presentation #
+
+!SLIDE bullets incremental
+# Bullet Points #
+
+* first point
+* second point
+* third point
@@ -0,0 +1 @@
+{ "name": "My Preso", "sections": [ {"section":"one"} ]}
View
@@ -0,0 +1,20 @@
+require File.expand_path "../test_helper", __FILE__
+
+context "ShowOff basic tests" do
+
+ def app
+ opt = {:verbose => true, :pres_dir => "fixtures/simple", :pres_file => 'showoff.json'}
+ ShowOff.set opt
+ ShowOff.new
+ end
+
+ setup do
+ end
+
+ test "can get the basic page" do
+ get '/'
+ assert last_response.ok?
+ assert_match '<div id="preso">', last_response.body
+ end
+
+end
View
@@ -0,0 +1,34 @@
+dir = File.dirname(File.expand_path(__FILE__))
+$LOAD_PATH.unshift dir + '/../lib'
+$TESTING = true
+require 'test/unit'
+require 'rubygems'
+require 'showoff'
+require 'rack/test'
+require 'pp'
+
+class Test::Unit::TestCase
+ include Rack::Test::Methods
+end
+
+##
+# test/spec/mini 3
+# http://gist.github.com/25455
+# chris@ozmm.org
+#
+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
+ ($contexts ||= []) << klass # make sure klass doesn't get GC'd
+ klass
+end

0 comments on commit 2ce9c66

Please sign in to comment.