file_sandbox 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ CHANGES
2
+ Manifest.txt
3
+ README
4
+ Rakefile
5
+ lib/file_sandbox.rb
6
+ test/file_sandbox_test.rb
data/README CHANGED
@@ -33,5 +33,8 @@ File sandbox creates a space for your tests to safely hit the file system. It al
33
33
 
34
34
  Author:: Jeremy Stell-Smith
35
35
  Email:: jeremystellsmith@gmail.com
36
- Home Page:: http://onemanswalk.com
37
36
  License:: LGPL License
37
+
38
+ == Home Page
39
+
40
+ http://onemanswalk.com
data/Rakefile CHANGED
@@ -1,112 +1,14 @@
1
- require 'rake/clean'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- begin
6
- require 'rubygems'
7
- require 'rake/gempackagetask'
8
- require 'rake/gempackagetask'
9
- require 'rake/contrib/rubyforgepublisher'
10
- rescue
11
- puts "caught error : #{$!}"
12
- nil
13
- end
14
-
15
- PKG_NAME = 'file_sandbox'
16
- PKG_VERSION = '0.1'
17
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
18
-
19
- RELEASE_NAME = "REL #{PKG_VERSION}"
20
-
21
- RUBY_FORGE_PROJECT = "filesandbox"
22
- RUBY_FORGE_USER = "stellsmi"
23
- # RUBY_FORGE_GROUP = 2944
24
- # RUBY_FORGE_PACKAGE = 3495
25
-
26
- SRC_RB = FileList['lib/**/*.rb']
27
-
28
- desc "Default Task"
29
- task :default => :test
30
-
31
- #################################################
32
- # Test
33
-
34
- desc "Run all tests"
35
- task :test => [:test_units]
36
-
37
- Rake::TestTask.new("test_units") do |t|
38
- t.test_files = FileList['test/**/*test.rb']
39
- t.verbose = false
40
- end
41
-
42
- #################################################
43
- # RDoc
44
-
45
- rd = Rake::RDocTask.new("rdoc") { |rdoc|
46
- rdoc.rdoc_dir = 'html'
47
- rdoc.title = "File Sandbox"
48
- rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
49
- rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc')
50
- # rdoc.template = 'doc/jamis.rb'
51
- }
52
-
53
- #################################################
54
- # Package
55
-
56
- PKG_FILES = FileList[
57
- 'CHANGES', 'Rakefile', 'README', 'lib/**/*.rb', 'test/**/*.rb',
58
- ]
59
-
60
- spec = Gem::Specification.new do |s|
61
- s.name = PKG_NAME
62
- s.summary = "A File Sandbox for testing against the file system."
63
- s.description = <<-EOS
64
- File sandbox creates a space for your tests to safely hit the file system.
65
- It also makes it easier for them to do so..
66
- EOS
67
- s.version = PKG_VERSION
68
-
69
- s.files = PKG_FILES.to_a
70
- s.require_path = 'lib'
71
- s.autorequire = 'file_sandbox'
72
- s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/.*_test.rb$/ }
73
-
74
- s.has_rdoc = true
75
- s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
76
- s.rdoc_options <<
77
- '--title' << 'Builder -- Easy XML Building' <<
78
- '--main' << 'README' <<
79
- '--line-numbers'
80
-
81
- s.author = "Jeremy Stell-Smith"
82
- s.email = "jeremystellsmith@gmail.com"
83
- s.rubyforge_project = RUBY_FORGE_PROJECT
84
- s.homepage = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}"
85
- end
86
-
87
- Rake::GemPackageTask.new(spec) do |p|
88
- p.gem_spec = spec
89
- p.need_tar = true
90
- p.need_zip = true
91
- end
92
-
93
- ################################################
94
- # release
95
-
96
- task :release => [:test, :package, :upload_release]
97
-
98
- task :upload_release do
99
- require 'rubyforge'
100
-
101
- # puts "Enter rubyforge password:"
102
- # rubyforge = RubyForge.new(File.dirname(__FILE__) + "/config/rubyforge.yml",
103
- # :cookie_jar => RubyForge::COOKIE_F, :password => $stdin.gets.strip)
104
- rubyforge = RubyForge.new
105
- p rubyforge.class.instance_methods(false).sort
106
- rubyforge.login
107
- rubyforge.autoconfig
108
-
109
- files = %w(gem tgz zip).collect {|ext| "pkg/#{PKG_FILE_NAME}.#{ext}"}
110
- puts "Releasing #{files.collect{|f| File.basename(f)}.join(", ")}..."
111
- rubyforge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, *files)
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/file_sandbox.rb'
6
+
7
+ Hoe.new('file_sandbox', FileSandbox::VERSION) do |p|
8
+ p.rubyforge_name = 'filesandbox'
9
+ p.summary = p.description = p.paragraphs_of('README', 2).first
10
+ p.url = p.paragraphs_of('README', -1).first.strip
11
+ p.author = 'Jeremy Stell-Smith'
12
+ p.email = 'jeremystellsmith@gmail.com'
13
+ p.changes = p.paragraphs_of('CHANGES', 0..1).join("\n\n")
112
14
  end
@@ -3,6 +3,7 @@ require 'fileutils'
3
3
  require 'test/unit/assertions'
4
4
 
5
5
  module FileSandbox
6
+ VERSION = "0.2"
6
7
  def in_sandbox(&block)
7
8
  raise "I expected to create a sandbox as you passed in a block to me" if !block_given?
8
9
 
@@ -30,13 +31,15 @@ module FileSandbox
30
31
  end
31
32
  end
32
33
 
33
- def setup_sandbox
34
- @sandbox = Sandbox.new
34
+ def setup_sandbox(path = '__sandbox')
35
+ @sandbox = Sandbox.new(path)
35
36
  end
36
37
 
37
38
  def teardown_sandbox
38
- @sandbox.clean_up
39
- @sandbox = nil
39
+ if @sandbox
40
+ @sandbox.clean_up
41
+ @sandbox = nil
42
+ end
40
43
  end
41
44
 
42
45
  def file(name)
@@ -47,25 +50,32 @@ module FileSandbox
47
50
  include Test::Unit::Assertions
48
51
  attr_reader :root
49
52
 
50
- def initialize
51
- @root = File.expand_path("__sandbox")
53
+ def initialize(path = '__sandbox')
54
+ @root = File.expand_path(path)
52
55
  clean_up
53
56
  FileUtils.mkdir_p @root
54
57
  end
55
58
 
56
59
  # usage new :file=>'my file.rb', :with_contents=>'some stuff'
57
60
  def new(options)
58
- name = File.join(@root, options[:file])
61
+ name = File.join(@root, options.delete(:file))
59
62
  dir = File.dirname(name)
60
63
  FileUtils.mkdir_p dir
61
64
 
62
- if (binary_content = options[:with_binary_content] || options[:with_binary_contents])
65
+ if (binary_content = options.delete(:with_binary_content) || options.delete(:with_binary_contents))
63
66
  File.open(name, "wb") {|f| f << binary_content }
64
67
  else
65
- File.open(name, "w") {|f| f << (options[:with_content] || options[:with_contents] || '')}
68
+ File.open(name, "w") {|f| f << (options.delete(:with_content) || options.delete(:with_contents) || '')}
66
69
  end
70
+
71
+ raise "unexpected keys '#{options.keys.join(', ')}'" unless options.empty?
67
72
  end
68
-
73
+
74
+ def remove(options)
75
+ name = File.join(@root, options[:file])
76
+ FileUtils.remove_file name
77
+ end
78
+
69
79
  # usage assert :file=>'my file.rb', :has_contents=>'some stuff'
70
80
  def assert(options)
71
81
  name = File.join(@root, options[:file])
@@ -28,9 +28,39 @@ class FileSandboxTest < Test::Unit::TestCase
28
28
  assert !file('a.txt').exists?
29
29
 
30
30
  sandbox.new :file => 'a.txt'
31
-
32
31
  assert file('a.txt').exist?
32
+
33
+ sandbox.new :file => 'b', :with_contents => 'some'
34
+ assert_equal 'some', file('b').contents
35
+
36
+ sandbox.new :file => 'c', :with_contents => 'thing'
37
+ assert_equal 'thing', file('c').contents
38
+
39
+ assert_raises("unexpected keys 'contents'") {
40
+ sandbox.new :file => 'd', :contents => 'crap'
41
+ }
42
+ end
43
+ end
44
+
45
+ def test_remove_file
46
+ in_sandbox do |sandbox|
47
+ sandbox.new :file => 'foo'
48
+ sandbox.remove :file => 'foo'
49
+
50
+ assert !file('foo').exists?
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def assert_raises(string)
57
+ begin
58
+ yield
59
+ rescue
60
+ assert_equal string, $!.message, "wrong exception thrown"
61
+ return
33
62
  end
63
+ fail "expected exception '#{string}'"
34
64
  end
35
65
  end
36
66
 
metadata CHANGED
@@ -3,16 +3,16 @@ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: file_sandbox
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2007-02-08 00:00:00 -08:00
8
- summary: A File Sandbox for testing against the file system.
6
+ version: "0.2"
7
+ date: 2007-02-27 00:00:00 -08:00
8
+ summary: File sandbox creates a space for your tests to safely hit the file system. It also makes it easier for them to do so.
9
9
  require_paths:
10
10
  - lib
11
11
  email: jeremystellsmith@gmail.com
12
- homepage: http://rubyforge.org/projects/filesandbox
12
+ homepage: http://onemanswalk.com
13
13
  rubyforge_project: filesandbox
14
- description: File sandbox creates a space for your tests to safely hit the file system. It also makes it easier for them to do so..
15
- autorequire: file_sandbox
14
+ description: File sandbox creates a space for your tests to safely hit the file system. It also makes it easier for them to do so.
15
+ autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
@@ -30,27 +30,30 @@ authors:
30
30
  - Jeremy Stell-Smith
31
31
  files:
32
32
  - CHANGES
33
- - Rakefile
33
+ - Manifest.txt
34
34
  - README
35
+ - Rakefile
35
36
  - lib/file_sandbox.rb
36
37
  - test/file_sandbox_test.rb
37
- test_files:
38
- - test/file_sandbox_test.rb
39
- rdoc_options:
40
- - --title
41
- - Builder -- Easy XML Building
42
- - --main
43
- - README
44
- - --line-numbers
45
- extra_rdoc_files:
46
- - CHANGES
47
- - Rakefile
48
- - README
38
+ test_files: []
39
+
40
+ rdoc_options: []
41
+
42
+ extra_rdoc_files: []
43
+
49
44
  executables: []
50
45
 
51
46
  extensions: []
52
47
 
53
48
  requirements: []
54
49
 
55
- dependencies: []
56
-
50
+ dependencies:
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Version::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.2.0
59
+ version: