Skip to content
Browse files

adding collectors

  • Loading branch information...
1 parent c199320 commit 3fb1734d03cf0117a589538d92ece0caf5586887 @tenderlove committed
View
1 lib/busted.rb
@@ -1,4 +1,5 @@
require 'busted/gem'
+require 'busted/collectors'
module Busted
BASEDIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
View
3 lib/busted/collectors.rb
@@ -0,0 +1,3 @@
+require 'busted/collectors/collector'
+require 'busted/collectors/ruby_info'
+require 'busted/collectors/gem_info'
View
13 lib/busted/collectors/collector.rb
@@ -0,0 +1,13 @@
+module Busted
+ module Collectors
+ class Collector
+ def initialize scratch_dir
+ @scratch_dir = scratch_dir
+ Dir.chdir @scratch_dir
+ end
+
+ def process gemspec
+ end
+ end
+ end
+end
View
15 lib/busted/collectors/gem_info.rb
@@ -0,0 +1,15 @@
+module Busted
+ module Collectors
+ class GemInfo < Collector
+ def process gemspec = nil
+ template_file = File.join(BASEDIR, 'templates', 'gem_info.erb')
+ template = ERB.new(File.read(template_file))
+ target = File.expand_path 'gem_info.txt'
+ File.open(target, 'wb') { |f|
+ f.write template.result(binding)
+ }
+ target
+ end
+ end
+ end
+end
View
15 lib/busted/collectors/ruby_info.rb
@@ -0,0 +1,15 @@
+module Busted
+ module Collectors
+ class RubyInfo < Collector
+ def process gemspec = nil
+ template_file = File.join(BASEDIR, 'templates', 'ruby_info.erb')
+ template = ERB.new(File.read(template_file))
+ target = File.expand_path('ruby_info.txt')
+ File.open(target, 'wb') { |f|
+ f.write template.result(binding)
+ }
+ target
+ end
+ end
+ end
+end
View
21 lib/busted/gem.rb
@@ -1,4 +1,6 @@
require 'tempfile'
+require 'fileutils'
+require 'rbconfig'
require 'erb'
module Busted
@@ -18,6 +20,9 @@ def initialize gemspec
@gemspec = gemspec
@tarcommand = 'tar'
@zipcommand = 'zip'
+ @scratch_dir = File.join(Dir.tmpdir, $$.to_s)
+ FileUtils.mkdir_p(@scratch_dir)
+ Dir.chdir @scratch_dir
end
def archive_file
@@ -35,23 +40,11 @@ def archive_file
end
def ruby_info_file
- template_file = File.join(BASEDIR, 'templates', 'ruby_info.erb')
- template = ERB.new(File.read(template_file))
- target = File.join(Dir::tmpdir, 'ruby_info.txt')
- File.open(target, 'wb') { |f|
- f.write template.result(binding)
- }
- target
+ Collectors::RubyInfo.new(@scratch_dir).process(@gemspec)
end
def gem_info_file
- template_file = File.join(BASEDIR, 'templates', 'gem_info.erb')
- template = ERB.new(File.read(template_file))
- target = File.join(Dir::tmpdir, 'gem_info.txt')
- File.open(target, 'wb') { |f|
- f.write template.result(binding)
- }
- target
+ Collectors::GemInfo.new(@scratch_dir).process(@gemspec)
end
private
View
2 tasks/test.rb
@@ -1,5 +1,5 @@
Rake::TestTask.new do |t|
- %w[ lib ].each do |dir|
+ %w[ lib test ].each do |dir|
t.libs << dir
end
View
43 test/busted/test_gem.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
+require 'helper'
module Busted
class TestGem < TestCase
@@ -24,46 +24,5 @@ def test_archive_file
assert File.exists?(filename)
end
- def test_ruby_info
- broken = Busted::Gem.new(@spec)
- filename = broken.ruby_info_file
- assert_match Dir::tmpdir, filename
- assert File.exists?(filename)
- assert_match /txt$/, filename
- contents = File.read(filename)
- Config::CONFIG.each { |k,v|
- assert_match k, contents
- assert_match v, contents
- }
- end
-
- def test_gem_information
- broken = Busted::Gem.new(@spec)
- filename = broken.gem_info_file
- assert_match Dir::tmpdir, filename
- assert File.exists?(filename)
- assert_match /txt$/, filename
- contents = File.read(filename)
- assert_match ::Gem::RubyGemsVersion, contents
- assert_match RUBY_VERSION, contents
- assert_match RUBY_RELEASE_DATE, contents
- assert_match RUBY_PLATFORM, contents
- assert_match ::Gem.dir, contents
- assert_match ::Gem.ruby, contents
- assert_match ::Gem.bindir, contents
- ::Gem.platforms.each { |platform|
- assert_match platform, contents
- }
- ::Gem.path.each { |path|
- assert_match path, contents
- }
- ::Gem.configuration.each do |name,value|
- assert_match name.inspect, contents
- assert_match value.inspect, contents
- end
- ::Gem.sources.each do |s|
- assert_match s, contents
- end
- end
end
end
View
45 test/collectors/test_gem_info.rb
@@ -0,0 +1,45 @@
+require 'helper'
+
+module Busted
+ module Collectors
+ class TestGemInfo < TestCase
+ def setup
+ @scratch_dir = File.join(Dir.tmpdir, $$.to_s)
+ FileUtils.mkdir_p @scratch_dir
+ @gi = GemInfo.new @scratch_dir
+ end
+
+ def test_writes_to_scratch_dir
+ filename = @gi.process
+ assert_match @scratch_dir, filename
+ end
+
+ def test_gem_information
+ filename = @gi.process
+ assert File.exists?(filename)
+ assert_match /txt$/, filename
+ contents = File.read(filename)
+ assert_match ::Gem::RubyGemsVersion, contents
+ assert_match RUBY_VERSION, contents
+ assert_match RUBY_RELEASE_DATE, contents
+ assert_match RUBY_PLATFORM, contents
+ assert_match ::Gem.dir, contents
+ assert_match ::Gem.ruby, contents
+ assert_match ::Gem.bindir, contents
+ ::Gem.platforms.each { |platform|
+ assert_match platform, contents
+ }
+ ::Gem.path.each { |path|
+ assert_match path, contents
+ }
+ ::Gem.configuration.each do |name,value|
+ assert_match name.inspect, contents
+ assert_match value.inspect, contents
+ end
+ ::Gem.sources.each do |s|
+ assert_match s, contents
+ end
+ end
+ end
+ end
+end
View
29 test/collectors/test_ruby_info.rb
@@ -0,0 +1,29 @@
+require 'helper'
+
+module Busted
+ module Collectors
+ class TestRubyInfo < TestCase
+ def setup
+ @scratch_dir = File.join(Dir.tmpdir, $$.to_s)
+ FileUtils.mkdir_p @scratch_dir
+ @ri = RubyInfo.new @scratch_dir
+ end
+
+ def test_writes_to_scratch_dir
+ filename = @ri.process
+ assert_match @scratch_dir, filename
+ end
+
+ def test_process
+ filename = @ri.process
+ assert File.exists?(filename)
+ assert_match /txt$/, filename
+ contents = File.read(filename)
+ Config::CONFIG.each { |k,v|
+ assert_match k, contents
+ assert_match v, contents
+ }
+ end
+ end
+ end
+end
View
1 test/helper.rb
@@ -1,6 +1,7 @@
require 'test/unit'
require 'tempfile'
require 'busted'
+require 'rubygems'
module Busted
class TestCase < Test::Unit::TestCase

0 comments on commit 3fb1734

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