Skip to content
Browse files

Implemented top-level test helper & added mix-in to Test::Unit::TestCase

  • Loading branch information...
1 parent d460ed5 commit bfa2bb0bc0cbaef770687f19fde2fd21829cc7ae @reagent committed Jan 18, 2009
Showing with 58 additions and 0 deletions.
  1. +6 −0 lib/test_fs.rb
  2. +14 −0 lib/test_fs/helper.rb
  3. +38 −0 test/unit/test_fs/helper_test.rb
View
6 lib/test_fs.rb
@@ -2,8 +2,14 @@
require 'tmpdir'
require 'fileutils'
+require 'test/unit'
require 'test_fs/node'
require 'test_fs/directory'
require 'test_fs/root_directory'
require 'test_fs/file'
+require 'test_fs/helper'
+
+class Test::Unit::TestCase
+ include TestFs::Helper
+end
View
14 lib/test_fs/helper.rb
@@ -0,0 +1,14 @@
+module TestFs
+ module Helper
+
+ def setup_filesystem(&block)
+ root_directory = TestFs::RootDirectory.new
+
+ block.call(root_directory)
+ root_directory.create!
+
+ root_directory
+ end
+
+ end
+end
View
38 test/unit/test_fs/helper_test.rb
@@ -0,0 +1,38 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class HelperImplementation
+ include TestFs::Helper
+end
+
+module TestFs
+ class HelperTest < Test::Unit::TestCase
+
+ describe "An instance of HelperImplementation" do
+
+ it "should have a setup_filesystem method" do
+ hi = HelperImplementation.new
+ hi.respond_to?(:setup_filesystem).should be(true)
+ end
+
+ it "should create a test filesystem when using the setup_filesystem helper" do
+ hi = HelperImplementation.new
+
+ root_directory = mock do |m|
+ m.expects(:dir).with('dir')
+ m.expects(:create!).with()
+ end
+
+ TestFs::RootDirectory.expects(:new).with().returns(root_directory)
+
+ fs = hi.setup_filesystem do |root|
+ root.dir 'dir'
+ end
+
+ fs.should == root_directory
+ end
+
+
+ end
+
+ end
+end

0 comments on commit bfa2bb0

Please sign in to comment.
Something went wrong with that request. Please try again.