Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit bfa2bb0bc0cbaef770687f19fde2fd21829cc7ae 1 parent d460ed5
Patrick Reagan authored
6 lib/test_fs.rb
@@ -2,8 +2,14 @@
2 2
3 3 require 'tmpdir'
4 4 require 'fileutils'
  5 +require 'test/unit'
5 6
6 7 require 'test_fs/node'
7 8 require 'test_fs/directory'
8 9 require 'test_fs/root_directory'
9 10 require 'test_fs/file'
  11 +require 'test_fs/helper'
  12 +
  13 +class Test::Unit::TestCase
  14 + include TestFs::Helper
  15 +end
14 lib/test_fs/helper.rb
... ... @@ -0,0 +1,14 @@
  1 +module TestFs
  2 + module Helper
  3 +
  4 + def setup_filesystem(&block)
  5 + root_directory = TestFs::RootDirectory.new
  6 +
  7 + block.call(root_directory)
  8 + root_directory.create!
  9 +
  10 + root_directory
  11 + end
  12 +
  13 + end
  14 +end
38 test/unit/test_fs/helper_test.rb
... ... @@ -0,0 +1,38 @@
  1 +require File.dirname(__FILE__) + '/../../test_helper'
  2 +
  3 +class HelperImplementation
  4 + include TestFs::Helper
  5 +end
  6 +
  7 +module TestFs
  8 + class HelperTest < Test::Unit::TestCase
  9 +
  10 + describe "An instance of HelperImplementation" do
  11 +
  12 + it "should have a setup_filesystem method" do
  13 + hi = HelperImplementation.new
  14 + hi.respond_to?(:setup_filesystem).should be(true)
  15 + end
  16 +
  17 + it "should create a test filesystem when using the setup_filesystem helper" do
  18 + hi = HelperImplementation.new
  19 +
  20 + root_directory = mock do |m|
  21 + m.expects(:dir).with('dir')
  22 + m.expects(:create!).with()
  23 + end
  24 +
  25 + TestFs::RootDirectory.expects(:new).with().returns(root_directory)
  26 +
  27 + fs = hi.setup_filesystem do |root|
  28 + root.dir 'dir'
  29 + end
  30 +
  31 + fs.should == root_directory
  32 + end
  33 +
  34 +
  35 + end
  36 +
  37 + end
  38 +end

0 comments on commit bfa2bb0

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