Browse files

extracted some stuff out to a base test class

  • Loading branch information...
1 parent 291970e commit bda76efc5ba0c990352fe0c8af1463973dcf5a32 @justinfrench committed Sep 17, 2009
Showing with 59 additions and 26 deletions.
  1. +52 −0 test/publicious_base_test.rb
  2. +5 −26 test/single_match_test.rb
  3. +2 −0 test/test_helper.rb
View
52 test/publicious_base_test.rb
@@ -0,0 +1,52 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class PubliciousBaseTest < ActionController::TestCase
+ tests PubliciousController
+
+ def setup_plugin(*plugin_names)
+ plugin_names.each do |plugin_name|
+ plugin_name = plugin_name.to_s
+
+ PubliciousController.view_paths << File.join(@vendor_dir, plugin_name, 'app', 'views')
+
+ FileUtils.mkdir(File.join(@vendor_dir, plugin_name))
+ FileUtils.mkdir(File.join(@vendor_dir, plugin_name, 'public'))
+ FileUtils.mkdir(File.join(@vendor_dir, plugin_name, 'public', 'stylesheets'))
+ FileUtils.mkdir(File.join(@vendor_dir, plugin_name, 'public', 'images'))
+ FileUtils.mkdir(File.join(@vendor_dir, plugin_name, 'public', 'javascripts'))
+ end
+ end
+
+ def setup_vendor_dir
+ unless @vendor_dir
+ @vendor_dir = "/tmp/vendor"
+ FileUtils.mkdir(@vendor_dir)
+ end
+ end
+
+ def teardown_vendor_dir
+ if @vendor_dir
+ begin
+ FileUtils.rm_r(@vendor_dir)
+ rescue StandardError => e
+ puts "Error while removing #{@vendor_dir}"
+ end
+ end
+ end
+
+ def setup_standard_view_paths
+ PubliciousController.view_paths = ['/tmp/app/views']
+ end
+
+ def setup
+ super
+ setup_vendor_dir
+ setup_standard_view_paths
+ end
+
+ def teardown
+ super
+ teardown_vendor_dir
+ end
+
+end
View
31 test/single_match_test.rb
@@ -1,26 +1,14 @@
require File.dirname(__FILE__) + '/test_helper'
-class SingleMatchTest < ActionController::TestCase
- tests PubliciousController
-
+class SingleMatchTest < PubliciousBaseTest
+
def setup
super
- PubliciousController.view_paths = ['/tmp/app/views','/tmp/vendor/my_plugin/app/views']
-
+ setup_plugin :my_plugin
+
@path = ['foo', 'bah.css']
-
- @vendordir = "/tmp/vendor"
- @plugindir = "/tmp/vendor/my_plugin"
- @publicdir = "/tmp/vendor/my_plugin/public"
- @stylesheetsdir = "/tmp/vendor/my_plugin/public/stylesheets"
@filename = "/tmp/vendor/my_plugin/public/stylesheets/#{@path.join('/')}"
@filecontents = "hello from stylesheet"
-
- FileUtils.mkdir(@vendordir)
- FileUtils.mkdir(@plugindir)
- FileUtils.mkdir(@publicdir)
- FileUtils.mkdir(@stylesheetsdir)
-
FileUtils.mkdir(File.dirname(@filename))
File.open(@filename, 'w') do |file|
file << "hello from stylesheet"
@@ -29,15 +17,6 @@ def setup
get :show, :path => @path
end
- def teardown
- super
- begin
- FileUtils.rm_r(@vendordir)
- rescue StandardError => e
- puts "Error while removing #{@plugindir}"
- end
- end
-
test "view_paths should contain two items" do
assert_equal 2, @controller.view_paths.size
end
@@ -47,7 +26,7 @@ def teardown
end
test "public_paths should contain the plugin's public dir" do
- assert_equal @publicdir, @controller.send(:public_paths).first
+ assert_equal "/tmp/vendor/my_plugin/public", @controller.send(:public_paths).first
end
test "should respond with the file contents" do
View
2 test/test_helper.rb
@@ -1,5 +1,7 @@
require 'test/unit'
require 'rubygems'
+require 'active_support'
+require 'activesupport'
require 'action_controller'
require 'action_controller/test_case'
require 'action_controller/test_process'

0 comments on commit bda76ef

Please sign in to comment.