test-construct 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.devver/hooks/build +11 -0
  2. data/.devver/hooks/install_dependencies +3 -0
  3. data/.devver/hooks/notify +50 -0
  4. data/.devver/hooks/prepare_database +1 -0
  5. data/History.txt +4 -0
  6. data/README.markdown +144 -0
  7. data/Rakefile +36 -0
  8. data/bin/construct +8 -0
  9. data/bugs/issue-0127c8c6ba1d31b5488f4551f8d869e57d53956d.yaml +29 -0
  10. data/bugs/issue-404e5da7b128e5b34e7a33fbcd56603618010d92.yaml +22 -0
  11. data/bugs/issue-50798912193be32b1dc610d949a557b3860d96fd.yaml +23 -0
  12. data/bugs/issue-5a10ec7298127df3c62255ea59e01dcf831ff1d3.yaml +22 -0
  13. data/bugs/issue-67f704f8b7190ccc1157eec007c3d584779dc805.yaml +18 -0
  14. data/bugs/issue-881ae950569b6ca718fae0060f2751710b972fd2.yaml +22 -0
  15. data/bugs/issue-bc8dfdf3834bb84b1d942ab2a90ac8c82b4389fb.yaml +22 -0
  16. data/bugs/issue-d05e9a907202348d47c4bf92062c1f4673dcae68.yaml +18 -0
  17. data/bugs/issue-f30a3db19d917f8e72ca8689e099ef0cb2681fd3.yaml +20 -0
  18. data/bugs/project.yaml +16 -0
  19. data/construct.gemspec +40 -0
  20. data/geminstaller.yml +7 -0
  21. data/lib/construct.rb +68 -0
  22. data/lib/construct/helpers.rb +29 -0
  23. data/lib/construct/path_extensions.rb +52 -0
  24. data/tasks/ann.rake +80 -0
  25. data/tasks/bones.rake +20 -0
  26. data/tasks/gem.rake +201 -0
  27. data/tasks/git.rake +40 -0
  28. data/tasks/notes.rake +27 -0
  29. data/tasks/post_load.rake +34 -0
  30. data/tasks/rdoc.rake +51 -0
  31. data/tasks/rubyforge.rake +55 -0
  32. data/tasks/setup.rb +292 -0
  33. data/tasks/spec.rake +54 -0
  34. data/tasks/svn.rake +47 -0
  35. data/tasks/test.rake +40 -0
  36. data/tasks/zentest.rake +36 -0
  37. data/test-construct.gemspec +39 -0
  38. data/test/construct_test.rb +469 -0
  39. data/test/test_helper.rb +35 -0
  40. metadata +114 -0
@@ -0,0 +1,20 @@
1
+ --- !ditz.rubyforge.org,2008-03-06/issue
2
+ title: replace rand with counter
3
+ desc: |-
4
+ Use a counter instead of a random number for container naming
5
+ Should be process-wide (and probably threadsafe).
6
+ type: :feature
7
+ component: construct
8
+ release: neo
9
+ reporter: Avdi Grimm <avdi@avdi.org>
10
+ status: :unstarted
11
+ disposition:
12
+ creation_time: 2009-08-18 15:20:57.785823 Z
13
+ references: []
14
+
15
+ id: f30a3db19d917f8e72ca8689e099ef0cb2681fd3
16
+ log_events:
17
+ - - 2009-08-18 15:21:00.057673 Z
18
+ - Avdi Grimm <avdi@avdi.org>
19
+ - created
20
+ - ""
@@ -0,0 +1,16 @@
1
+ --- !ditz.rubyforge.org,2008-03-06/project
2
+ name: construct
3
+ version: "0.5"
4
+ components:
5
+ - !ditz.rubyforge.org,2008-03-06/component
6
+ name: construct
7
+ releases:
8
+ - !ditz.rubyforge.org,2008-03-06/release
9
+ name: neo
10
+ status: :unreleased
11
+ release_time:
12
+ log_events:
13
+ - - 2009-08-18 14:58:47.209904 Z
14
+ - Avdi Grimm <avdi@avdi.org>
15
+ - created
16
+ - Initial release
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{construct}
5
+ s.version = "1.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ben Brinckerhoff (ben@devver.net) and Avdi Grimm (avdi@devver.net)"]
9
+ s.date = %q{2009-09-09}
10
+ s.default_executable = %q{construct}
11
+ s.description = %q{}
12
+ s.email = %q{ben@devver.net, avdi@devver.net}
13
+ s.executables = ["construct"]
14
+ s.extra_rdoc_files = ["History.txt", "bin/construct"]
15
+ s.files = [".devver/devver_opts.yml", ".devver/hooks/build", ".devver/hooks/install_dependencies", ".devver/hooks/notify", ".devver/hooks/prepare_database", "History.txt", "README.markdown", "Rakefile", "bin/construct", "bugs/issue-0127c8c6ba1d31b5488f4551f8d869e57d53956d.yaml", "bugs/issue-404e5da7b128e5b34e7a33fbcd56603618010d92.yaml", "bugs/issue-50798912193be32b1dc610d949a557b3860d96fd.yaml", "bugs/issue-5a10ec7298127df3c62255ea59e01dcf831ff1d3.yaml", "bugs/issue-67f704f8b7190ccc1157eec007c3d584779dc805.yaml", "bugs/issue-881ae950569b6ca718fae0060f2751710b972fd2.yaml", "bugs/issue-bc8dfdf3834bb84b1d942ab2a90ac8c82b4389fb.yaml", "bugs/issue-d05e9a907202348d47c4bf92062c1f4673dcae68.yaml", "bugs/issue-f30a3db19d917f8e72ca8689e099ef0cb2681fd3.yaml", "bugs/project.yaml", "construct.gemspec", "geminstaller.yml", "lib/construct.rb", "lib/construct/helpers.rb", "lib/construct/path_extensions.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "tasks/zentest.rake", "test/construct_test.rb", "test/test_helper.rb"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/devver/construct}
18
+ s.rdoc_options = ["--main", "README.markdown"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{construct}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{Construct is a DSL for creating temporary files and directories during testing.}
23
+ s.test_files = ["test/construct_test.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_development_dependency(%q<bones>, [">= 2.5.1"])
31
+ s.add_development_dependency(%q<jeremymcanally-pending>, ["~> 0.1"])
32
+ else
33
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
34
+ s.add_dependency(%q<jeremymcanally-pending>, ["~> 0.1"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
38
+ s.add_dependency(%q<jeremymcanally-pending>, ["~> 0.1"])
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ defaults:
2
+ install_options: --include-dependencies
3
+ gems:
4
+ - name: bones
5
+ - name: jeremymcanally-pending
6
+ install_options: "--source http://gems.github.com"
7
+ - name: mocha
@@ -0,0 +1,68 @@
1
+ require 'pathname'
2
+ require 'tmpdir'
3
+ require 'English'
4
+
5
+ module Construct
6
+
7
+ # :stopdoc:
8
+ VERSION = '1.2.0'
9
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11
+ # :startdoc:
12
+
13
+ # Returns the version string for the library.
14
+ #
15
+ def self.version
16
+ VERSION
17
+ end
18
+
19
+ # Returns the library path for the module. If any arguments are given,
20
+ # they will be joined to the end of the libray path using
21
+ # <tt>File.join</tt>.
22
+ #
23
+ def self.libpath( *args )
24
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
25
+ end
26
+
27
+ # Returns the lpath for the module. If any arguments are given,
28
+ # they will be joined to the end of the path using
29
+ # <tt>File.join</tt>.
30
+ #
31
+ def self.path( *args )
32
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
33
+ end
34
+
35
+ # Utility method used to require all files ending in .rb that lie in the
36
+ # directory below this file that has the same name as the filename passed
37
+ # in. Optionally, a specific _directory_ name can be passed in such that
38
+ # the _filename_ does not have to be equivalent to the directory.
39
+ #
40
+ def self.require_all_libs_relative_to( fname, dir = nil )
41
+ dir ||= ::File.basename(fname, '.*')
42
+ search_me = ::File.expand_path(
43
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
44
+
45
+ Dir.glob(search_me).sort.each {|rb| require rb}
46
+ end
47
+
48
+ # END Bones boilerplate
49
+
50
+ CONTAINER_PREFIX = 'construct_container'
51
+
52
+ def self.tmpdir
53
+ dir = nil
54
+ Dir.chdir Dir.tmpdir do dir = Dir.pwd end # HACK FOR OSX
55
+ dir
56
+ end
57
+
58
+ def self.destroy_all!
59
+ Pathname.glob(File.join(tmpdir, CONTAINER_PREFIX + "*")) do |container|
60
+ container.rmtree
61
+ end
62
+ end
63
+
64
+ end # module Construct
65
+
66
+ Construct.require_all_libs_relative_to(__FILE__)
67
+
68
+ # EOF
@@ -0,0 +1,29 @@
1
+ require 'construct/path_extensions'
2
+
3
+ module Construct
4
+ module Helpers
5
+ include PathExtensions
6
+ extend self
7
+
8
+ def within_construct(chdir=true)
9
+ container = create_construct(chdir)
10
+ container.maybe_change_dir(chdir) do
11
+ yield(container)
12
+ end
13
+ ensure
14
+ container.destroy!
15
+ end
16
+
17
+ def create_construct(chdir=true)
18
+ path = (Pathname(Construct.tmpdir) +
19
+ "#{CONTAINER_PREFIX}-#{$PROCESS_ID}-#{rand(1_000_000_000)}")
20
+ path.mkpath
21
+ path.extend(PathExtensions)
22
+ path.construct__chdir_default = chdir
23
+ path
24
+ end
25
+
26
+ end
27
+
28
+ extend Helpers
29
+ end
@@ -0,0 +1,52 @@
1
+ module Construct
2
+ module PathExtensions
3
+
4
+ attr_accessor :construct__chdir_default
5
+
6
+ def directory(path,chdir=construct__chdir_default)
7
+ subdir = (self + path)
8
+ subdir.mkpath
9
+ subdir.extend(PathExtensions)
10
+ subdir.maybe_change_dir(chdir) do
11
+ yield(subdir) if block_given?
12
+ end
13
+ subdir
14
+ end
15
+
16
+ def file(filepath,contents=nil,&block)
17
+ path = (self+filepath)
18
+ path.dirname.mkpath
19
+ File.open(path,'w') do |f|
20
+ if(block)
21
+ if(block.arity==1)
22
+ block.call(f)
23
+ else
24
+ f << block.call
25
+ end
26
+ else
27
+ f << contents
28
+ end
29
+ end
30
+ path
31
+ end
32
+
33
+ def maybe_change_dir(chdir, &block)
34
+ if(chdir)
35
+ self.chdir(&block)
36
+ else
37
+ block.call
38
+ end
39
+ end
40
+
41
+ # Note: Pathname implements #chdir directly, but it is deprecated in favor
42
+ # of Dir.chdir
43
+ def chdir(&block)
44
+ Dir.chdir(self, &block)
45
+ end
46
+
47
+ def destroy!
48
+ rmtree
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,80 @@
1
+
2
+ begin
3
+ require 'bones/smtp_tls'
4
+ rescue LoadError
5
+ require 'net/smtp'
6
+ end
7
+ require 'time'
8
+
9
+ namespace :ann do
10
+
11
+ # A prerequisites task that all other tasks depend upon
12
+ task :prereqs
13
+
14
+ file PROJ.ann.file do
15
+ ann = PROJ.ann
16
+ puts "Generating #{ann.file}"
17
+ File.open(ann.file,'w') do |fd|
18
+ fd.puts("#{PROJ.name} version #{PROJ.version}")
19
+ fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
20
+ fd.puts(" #{PROJ.url}") if PROJ.url.valid?
21
+ fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
22
+ fd.puts
23
+ fd.puts("== DESCRIPTION")
24
+ fd.puts
25
+ fd.puts(PROJ.description)
26
+ fd.puts
27
+ fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
28
+ fd.puts
29
+ ann.paragraphs.each do |p|
30
+ fd.puts "== #{p.upcase}"
31
+ fd.puts
32
+ fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
33
+ fd.puts
34
+ end
35
+ fd.puts ann.text if ann.text
36
+ end
37
+ end
38
+
39
+ desc "Create an announcement file"
40
+ task :announcement => ['ann:prereqs', PROJ.ann.file]
41
+
42
+ desc "Send an email announcement"
43
+ task :email => ['ann:prereqs', PROJ.ann.file] do
44
+ ann = PROJ.ann
45
+ from = ann.email[:from] || Array(PROJ.authors).first || PROJ.email
46
+ to = Array(ann.email[:to])
47
+
48
+ ### build a mail header for RFC 822
49
+ rfc822msg = "From: #{from}\n"
50
+ rfc822msg << "To: #{to.join(',')}\n"
51
+ rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
52
+ rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
53
+ rfc822msg << "\n"
54
+ rfc822msg << "Date: #{Time.new.rfc822}\n"
55
+ rfc822msg << "Message-Id: "
56
+ rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
57
+ rfc822msg << File.read(ann.file)
58
+
59
+ params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
60
+ ann.email[key]
61
+ end
62
+
63
+ params[3] = PROJ.email if params[3].nil?
64
+
65
+ if params[4].nil?
66
+ STDOUT.write "Please enter your e-mail password (#{params[3]}): "
67
+ params[4] = STDIN.gets.chomp
68
+ end
69
+
70
+ ### send email
71
+ Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
72
+ end
73
+ end # namespace :ann
74
+
75
+ desc 'Alias to ann:announcement'
76
+ task :ann => 'ann:announcement'
77
+
78
+ CLOBBER << PROJ.ann.file
79
+
80
+ # EOF
@@ -0,0 +1,20 @@
1
+
2
+ if HAVE_BONES
3
+
4
+ namespace :bones do
5
+
6
+ desc 'Show the PROJ open struct'
7
+ task :debug do |t|
8
+ atr = if t.application.top_level_tasks.length == 2
9
+ t.application.top_level_tasks.pop
10
+ end
11
+
12
+ if atr then Bones::Debug.show_attr(PROJ, atr)
13
+ else Bones::Debug.show PROJ end
14
+ end
15
+
16
+ end # namespace :bones
17
+
18
+ end # HAVE_BONES
19
+
20
+ # EOF
@@ -0,0 +1,201 @@
1
+
2
+ require 'find'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/user_interaction'
5
+ require 'rubygems/builder'
6
+
7
+ module Bones
8
+ class GemPackageTask < Rake::PackageTask
9
+ # Ruby GEM spec containing the metadata for this package. The
10
+ # name, version and package_files are automatically determined
11
+ # from the GEM spec and don't need to be explicitly provided.
12
+ #
13
+ attr_accessor :gem_spec
14
+
15
+ # Tasks from the Bones gem directory
16
+ attr_reader :bones_files
17
+
18
+ # Create a GEM Package task library. Automatically define the gem
19
+ # if a block is given. If no block is supplied, then +define+
20
+ # needs to be called to define the task.
21
+ #
22
+ def initialize(gem_spec)
23
+ init(gem_spec)
24
+ yield self if block_given?
25
+ define if block_given?
26
+ end
27
+
28
+ # Initialization tasks without the "yield self" or define
29
+ # operations.
30
+ #
31
+ def init(gem)
32
+ super(gem.name, gem.version)
33
+ @gem_spec = gem
34
+ @package_files += gem_spec.files if gem_spec.files
35
+ @bones_files = []
36
+
37
+ local_setup = File.join(Dir.pwd, %w[tasks setup.rb])
38
+ if !test(?e, local_setup)
39
+ Dir.glob(::Bones.path(%w[lib bones tasks *])).each {|fn| bones_files << fn}
40
+ end
41
+ end
42
+
43
+ # Create the Rake tasks and actions specified by this
44
+ # GemPackageTask. (+define+ is automatically called if a block is
45
+ # given to +new+).
46
+ #
47
+ def define
48
+ super
49
+ task :prereqs
50
+ task :package => ['gem:prereqs', "#{package_dir_path}/#{gem_file}"]
51
+ file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files + bones_files do
52
+ when_writing("Creating GEM") {
53
+ chdir(package_dir_path) do
54
+ Gem::Builder.new(gem_spec).build
55
+ verbose(true) {
56
+ mv gem_file, "../#{gem_file}"
57
+ }
58
+ end
59
+ }
60
+ end
61
+
62
+ file package_dir_path => bones_files do
63
+ mkdir_p package_dir rescue nil
64
+
65
+ gem_spec.files = (gem_spec.files +
66
+ bones_files.map {|fn| File.join('tasks', File.basename(fn))}).sort
67
+
68
+ bones_files.each do |fn|
69
+ base_fn = File.join('tasks', File.basename(fn))
70
+ f = File.join(package_dir_path, base_fn)
71
+ fdir = File.dirname(f)
72
+ mkdir_p(fdir) if !File.exist?(fdir)
73
+ if File.directory?(fn)
74
+ mkdir_p(f)
75
+ else
76
+ raise "file name conflict for '#{base_fn}' (conflicts with '#{fn}')" if test(?e, f)
77
+ safe_ln(fn, f)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ def gem_file
84
+ if @gem_spec.platform == Gem::Platform::RUBY
85
+ "#{package_name}.gem"
86
+ else
87
+ "#{package_name}-#{@gem_spec.platform}.gem"
88
+ end
89
+ end
90
+ end # class GemPackageTask
91
+ end # module Bones
92
+
93
+ namespace :gem do
94
+
95
+ PROJ.gem._spec = Gem::Specification.new do |s|
96
+ s.name = PROJ.name
97
+ s.version = PROJ.version
98
+ s.summary = PROJ.summary
99
+ s.authors = Array(PROJ.authors)
100
+ s.email = PROJ.email
101
+ s.homepage = Array(PROJ.url).first
102
+ s.rubyforge_project = PROJ.rubyforge.name
103
+
104
+ s.description = PROJ.description
105
+
106
+ PROJ.gem.dependencies.each do |dep|
107
+ s.add_dependency(*dep)
108
+ end
109
+
110
+ PROJ.gem.development_dependencies.each do |dep|
111
+ s.add_development_dependency(*dep)
112
+ end
113
+
114
+ s.files = PROJ.gem.files
115
+ s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
116
+ s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
117
+
118
+ s.bindir = 'bin'
119
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
120
+ s.require_paths = dirs unless dirs.empty?
121
+
122
+ incl = Regexp.new(PROJ.rdoc.include.join('|'))
123
+ excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
124
+ excl = Regexp.new(excl.join('|'))
125
+ rdoc_files = PROJ.gem.files.find_all do |fn|
126
+ case fn
127
+ when excl; false
128
+ when incl; true
129
+ else false end
130
+ end
131
+ s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
132
+ s.extra_rdoc_files = rdoc_files
133
+ s.has_rdoc = true
134
+
135
+ if test ?f, PROJ.test.file
136
+ s.test_file = PROJ.test.file
137
+ else
138
+ s.test_files = PROJ.test.files.to_a
139
+ end
140
+
141
+ # Do any extra stuff the user wants
142
+ PROJ.gem.extras.each do |msg, val|
143
+ case val
144
+ when Proc
145
+ val.call(s.send(msg))
146
+ else
147
+ s.send "#{msg}=", val
148
+ end
149
+ end
150
+ end # Gem::Specification.new
151
+
152
+ Bones::GemPackageTask.new(PROJ.gem._spec) do |pkg|
153
+ pkg.need_tar = PROJ.gem.need_tar
154
+ pkg.need_zip = PROJ.gem.need_zip
155
+ end
156
+
157
+ desc 'Show information about the gem'
158
+ task :debug => 'gem:prereqs' do
159
+ puts PROJ.gem._spec.to_ruby
160
+ end
161
+
162
+ desc 'Write the gemspec '
163
+ task :spec => 'gem:prereqs' do
164
+ File.open("#{PROJ.name}.gemspec", 'w') do |f|
165
+ f.write PROJ.gem._spec.to_ruby
166
+ end
167
+ end
168
+
169
+ desc 'Install the gem'
170
+ task :install => [:clobber, 'gem:package'] do
171
+ sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
172
+
173
+ # use this version of the command for rubygems > 1.0.0
174
+ #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
175
+ end
176
+
177
+ desc 'Uninstall the gem'
178
+ task :uninstall do
179
+ installed_list = Gem.source_index.find_name(PROJ.name)
180
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
181
+ sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
182
+ end
183
+ end
184
+
185
+ desc 'Reinstall the gem'
186
+ task :reinstall => [:uninstall, :install]
187
+
188
+ desc 'Cleanup the gem'
189
+ task :cleanup do
190
+ sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
191
+ end
192
+ end # namespace :gem
193
+
194
+
195
+ desc 'Alias to gem:package'
196
+ task :gem => 'gem:package'
197
+
198
+ task :clobber => 'gem:clobber_package'
199
+ remove_desc_for_task 'gem:clobber_package'
200
+
201
+ # EOF