gemdev 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,100 +1,73 @@
1
- # = GemDev
2
- # Utilities simplifying gem development.
3
- #
4
- # == Introduction
5
- # RubyGems is an amazing packaging system, hands down. GemDev
6
- # provides some extensions to make it easy to develop multiple,
7
- # interrelated gems at once by allowing you to specify your gem
8
- # development folders in the RubyGems configuration file (.gemrc). Additionally, test
9
- # extensions are provided to permit test subsetting.
10
- #
11
- # Copyright (c) 2006-2007, Regents of the University of Colorado.
12
- # Developer:: Simon Chiang, Biomolecular Structure Program
13
- # Support:: UCHSC School of Medicine Deans Academic Enrichment Fund
14
- # Licence:: MIT-Style
15
- #
16
- # == GemDev Usage
17
- # For specifying development folders, add one big glob or a list of filepaths
18
- # to the .gemrc file, keyed by 'development'. GemDev will look for 'Rakefile'
19
- # in every folder specified and read and instantiate each Gem::Specification
20
- # included therein. As a result, you can require the gems as if they were
21
- # already installed.
22
- #
23
- # Say you were developing 'ioutils' in folder '/path/to/ioutils' with the sample
24
- # Rakefile (see below) at '/path/to/ioutils/Rakefile'.
25
- #
26
- # To specify this file add to '.gemrc':
27
- #
28
- # development: /path/to/{ioutils, another_gem}
29
- #
30
- # or:
31
- #
32
- # development:
33
- # - /path/to/ioutils
34
- # - /path/to/another_gem
35
- #
36
- # In your scripts:
37
- #
38
- # require 'gemdev'
39
- # require 'ioutils' # => now works
40
- #
41
- # == Subsets Usage
42
- # Subsets are provided to make unit testing more convenient.
43
- #
44
- # Example:
45
- #
46
- # require 'gemdev'
47
- # require 'test/unit/subsets'
48
- #
49
- # class YourTest < Test::Unit::TestCase
50
- # # only runs if ENV['benchmark']=true
51
- # def test_benchmark_some_method
52
- # benchmark_test do |x|
53
- # x.report("speed") {...}
54
- # end
55
- # end
56
- # end
57
- #
58
- # == Sample Rakefile
59
- #
60
- # require 'rake'
61
- # require 'rake/testtask'
62
- # require 'rake/rdoctask'
63
- # require 'rake/gempackagetask'
64
- #
65
- # # tasks
66
- # desc 'Default: Run tests.'
67
- # task :default => :test
68
- #
69
- # desc 'Run tests.'
70
- # Rake::TestTask.new(:test) do |t|
71
- # t.libs << 'lib'
72
- # t.pattern = File.join('test', ENV['subset'] || '', ENV['pattern'] || '**/*_test.rb')
73
- # t.verbose = true
74
- # end
75
- #
76
- # #
77
- # # Gem specification
78
- # #
79
- # Gem::manage_gems
80
- # spec = Gem::Specification.new do |s|
81
- # s.name = "ioutils"
82
- # s.version = "0.1.0"
83
- # s.author = "Simon Chiang"
84
- # s.email = "simon.chiang@uchsc.edu"
85
- # s.homepage = "http://rubyforge.org/projects/ioutils/"
86
- # s.platform = Gem::Platform::RUBY
87
- # s.files = Dir.glob("{test,lib,docs}/**/*")
88
- # s.require_path = "lib"
89
- # s.autorequire = "ioutils"
90
- # s.test_file = "test/ioutils_test_suite.rb"
91
- #
92
- # s.has_rdoc = true
93
- # s.extra_rdoc_files = ["README"]
94
- # s.add_dependency("gemdev", ">= 0.1.1")
95
- # s.add_dependency("activesupport", ">= 1.4.2")
96
- # end
97
- #
98
- # Rake::GemPackageTask.new(spec) do |pkg|
99
- # pkg.need_tar = true
100
- # end
1
+ = GemDev
2
+ Utilities simplifying gem development.
3
+
4
+ == Introduction
5
+ GemDev provides some extensions to make it easy to develop multiple,
6
+ interrelated gems at once by allowing you to specify your gem
7
+ development folders in the RubyGems configuration file (.gemrc).
8
+
9
+ Additionally, test extensions are provided to permit test subsetting.
10
+
11
+ Copyright (c) 2006-2007, Regents of the University of Colorado.
12
+ Developer:: Simon Chiang, Biomolecular Structure Program
13
+ Support:: UCHSC School of Medicine Deans Academic Enrichment Fund
14
+ Licence:: MIT-Style
15
+
16
+ == GemDev Usage
17
+ Specify development folders using one big glob or an array of globs
18
+ keyed by 'development' in the '.gemrc' file. GemDev will load each
19
+ 'gemspecs/*.gemspec' file along every path specified, and set the
20
+ gem path so you can require the gems as if they were already installed.
21
+
22
+ Say you were developing 'ioutils' with the following:
23
+ /path/to/ioutils # => your development folder
24
+ /path/to/ioutils/gemspecs/0.7.0.gemspec # => a released gemspec
25
+ /path/to/ioutils/gemspecs/0.8.0.gemspec # => the lastest, unreleased gemspec
26
+
27
+ To specify this gem, you add to '.gemrc':
28
+
29
+ development: /path/to/ioutils
30
+
31
+ or if you have a bunch of other gems:
32
+
33
+ development:
34
+ - /path/to/{ioutils,another_gem}
35
+ - /path/to/yet_another_gem
36
+
37
+ In your scripts:
38
+
39
+ require 'gemdev'
40
+ require 'ioutils' # => now works without installing ioutils
41
+
42
+ Requiring ioutils as above will load the latest version (0.8.0) by default, but
43
+ nothing prevents you from requiring a different version if you need to.
44
+
45
+ == Working with Rakefiles
46
+ Splitting gemspecs out of a Rakefile while preserving a GemPackageTask is easy:
47
+
48
+ # Normally here you'd have your definition
49
+ # Gem::Specification.new ...
50
+ #
51
+ # Just replace with the path to the gemspec you want to package
52
+ spec = Gem::SourceIndex.load_specification("./gemspecs/0.8.0.gemspec")
53
+ Rake::GemPackageTask.new(spec) do |pkg|
54
+ pkg.need_tar = true
55
+ end
56
+
57
+ == Subsets Usage
58
+ Subsets are provided to make unit testing more convenient.
59
+
60
+ Example:
61
+
62
+ require 'gemdev'
63
+ require 'test/unit/subsets'
64
+
65
+ class YourTest < Test::Unit::TestCase
66
+ # only runs if ENV['benchmark']=true
67
+ def test_benchmark_some_method
68
+ benchmark_test do |x|
69
+ x.report("speed") {...}
70
+ end
71
+ end
72
+ end
73
+
@@ -1,69 +1,63 @@
1
1
  require 'rubygems'
2
2
  require 'yaml'
3
- require 'strscan'
4
3
 
5
- module Gem
6
- class Specification
7
- # The full path to the gem (install path + full name).
8
- #
9
- # return:: [String] the full gem path
10
- #
11
- def full_gem_path
12
- @full_gem_path || File.join(installation_path, "gems", full_name)
13
- end
4
+ module Gem # :nodoc:
5
+ class Specification
6
+ # The full path to the gem (install path + full name).
7
+ #
8
+ # return:: [String] the full gem path
9
+ #
10
+ def full_gem_path
11
+ @full_gem_path || File.join(installation_path, "gems", full_name)
12
+ end
14
13
 
15
- def full_gem_path=(input)
16
- @full_gem_path = input
17
- end
14
+ def full_gem_path=(input)
15
+ @full_gem_path = input
16
+ end
18
17
 
19
- def self.load_devel(path)
20
- gemspecs = []
21
- fail "NESTED Specification.load calls not allowed!" if @@gather
22
- @@gather = proc do |gs|
23
- gs.full_gem_path = path
24
- gemspecs << gs
25
- end
18
+ def self.load_devel(path)
19
+ gemspecs = []
20
+ fail "NESTED Specification.load calls not allowed!" if @@gather
21
+ @@gather = proc do |gs|
22
+ gs.full_gem_path = path
23
+ gemspecs << gs
24
+ end
26
25
 
27
- #full rakefile is not needed or desired... just gemspecs
28
- data = File.read(File.join(path,"Rakefile"))
29
- scanner = StringScanner.new(data)
30
- specs = []
31
- while scanner.skip_until(/Gem::Specification\.new do/)
32
- start = scanner.pos - 25 # length of 'Gem::Specification.new do'
33
- scanner.skip_until(/\send/)
34
-
35
- specs << data[start..scanner.pos]
36
- end
37
-
38
- eval(specs.join("\n"))
39
- gemspecs
40
- ensure
41
- @@gather = nil
42
- end
26
+ # load any gemspecs
27
+ specs = Dir.glob( File.expand_path(File.join(path, "gemspecs/*.gemspec")) ).collect do |spec|
28
+ File.read(spec)
29
+ end
30
+
31
+ eval(specs.join("\n"))
32
+ gemspecs
33
+ ensure
34
+ @@gather = nil
35
+ end
43
36
  end
44
37
 
45
- class GemPathSearcher
46
- def refresh!
38
+ class GemPathSearcher
39
+ def refresh!
47
40
  # cut and paste of the initialize routine
48
41
  @gemspecs = init_gemspecs
49
42
  @lib_dirs = {}
50
43
  @gemspecs.each do |spec|
51
- @lib_dirs[spec.object_id] = lib_dirs(spec)
44
+ @lib_dirs[spec.object_id] = lib_dirs(spec)
52
45
  end
53
- end
46
+ end
54
47
  end
55
48
  end
56
49
 
57
50
  if File.exists?(Gem.config_file)
58
51
  config = YAML.load_file(Gem.config_file)
59
- devel = config['development']
52
+ devel_paths = config['development']
60
53
 
61
54
  # File.expand_path required to change windows filepaths to unix filepaths
62
- paths = case devel
63
- when Array then devel
64
- when String then Dir.glob(File.expand_path(devel))
65
- end.collect {|p| File.expand_path(p)}
66
-
55
+ devel_paths = [devel_paths] unless devel_paths.kind_of?(Array)
56
+ paths = devel_paths.collect do |path|
57
+ Dir.glob(File.expand_path(path))
58
+ end
59
+
60
+ paths = paths.flatten.collect {|path| File.expand_path(path)}
67
61
  paths.each do |path|
68
62
  next if File.file?(path)
69
63
  Gem::Specification.load_devel(path).each do |spec|
@@ -72,4 +66,5 @@ if File.exists?(Gem.config_file)
72
66
  end
73
67
  end
74
68
 
69
+ raise "RubyGems version is too old for GemDev.\nUpdate with 'gem update --server' or download the latest One-Click installer for Windows, then try again." unless Gem.respond_to?(:searcher)
75
70
  Gem.searcher.refresh!
@@ -2,264 +2,267 @@ require 'test/unit'
2
2
  require 'benchmark'
3
3
  require 'pp'
4
4
 
5
- # These subsets facilitate testing by using the ENV variables specified on the command line
6
- # to indicate which tests to run. The ENV variables are set by rake, so this code implicitly
7
- # assumes that you're running your tests through rake.
8
- #
9
- class Test::Unit::TestCase
5
+ module Test # :nodoc:
6
+ module Unit # :nodoc:
7
+
8
+ # These subsets facilitate testing by using the ENV variables specified on the command line
9
+ # to indicate which tests to run. The ENV variables are set by rake, so this code implicitly
10
+ # assumes that you're running your tests through rake.
11
+ class TestCase
12
+ class << self
13
+ # Access to the case-insensitive ENV variables
14
+ def env(type, reset=false)
15
+ if @env_vars.nil? || reset
16
+ @env_vars = {}
17
+ ENV.each_pair do |key, value|
18
+ @env_vars[key.downcase] = value
19
+ end
20
+ end
21
+ @env_vars[type.downcase]
22
+ end
23
+
24
+ # Causes a whole test suite to require one of the listed platforms
25
+ # in order to run. See match_platform? for details.
26
+ #
27
+ # Simply declare like:
28
+ #
29
+ # class Test::Unit::TestCase
30
+ # require_platform 'mswin'
31
+ # end
32
+ def require_platform(*platforms)
33
+ @platforms = platforms
34
+ end
35
+
36
+ # Returns true if RUBY_PLATFORM matches one of the specfied
37
+ # platforms. Use the prefix 'non_' to specify any plaform but the
38
+ # specified platform (ex: 'non_mswin')
39
+ #
40
+ # Some common platforms:
41
+ # - mswin:: Windows
42
+ def match_platform?(*platforms)
43
+ platforms.each do |platform|
44
+ platform.to_s =~ /^(non_)?(.*)/
45
+
46
+ non = true if $1
47
+ match_platform = !RUBY_PLATFORM.index($2).nil?
48
+ return false unless (non && !match_platform) || (!non && match_platform)
49
+ end
50
+
51
+ true
52
+ end
53
+
54
+ alias :original_suite :suite
55
+ end
56
+
57
+ def self.suite
58
+ if match_platform?(*@platforms)
59
+ original_suite
60
+ else
61
+ # if platforms are specfied for the tests and the platform does NOT
62
+ # match, remake the suite to skip all tests.
63
+ method_names = public_instance_methods(true)
64
+ suite = Test::Unit::TestSuite.new(name)
65
+ method_names.each do |method_name|
66
+ catch(:invalid_test) do
67
+ suite << new('on_test_skipped') if method_name =~ /^test/
68
+ end
69
+ end
70
+ suite
71
+ end
72
+ end
10
73
 
11
- class << self
12
- # Access to the case-insensitive ENV variables
13
- def env(type, reset=false)
14
- if @env_vars.nil? || reset
15
- @env_vars = {}
16
- ENV.each_pair do |key, value|
17
- @env_vars[key.downcase] = value
18
- end
19
- end
20
- @env_vars[type.downcase]
21
- end
22
-
23
- # Causes a whole test suite to require one of the listed platforms
24
- # in order to run. See match_platform? for details.
25
- #
26
- # Simply declare like:
27
- #
28
- # class Test::Unit::TestCase
29
- # require_platform 'mswin'
30
- # end
31
- def require_platform(*platforms)
32
- @platforms = platforms
33
- end
34
-
35
- # Returns true if RUBY_PLATFORM matches one of the specfied
36
- # platforms. Use the prefix 'non_' to specify any plaform but the
37
- # specified platform (ex: 'non_mswin')
38
- #
39
- # Some common platforms:
40
- # - mswin:: Windows
41
- def match_platform?(*platforms)
42
- platforms.each do |platform|
43
- platform.to_s =~ /^(non_)?(.*)/
44
-
45
- non = true if $1
46
- match_platform = !RUBY_PLATFORM.index($2).nil?
47
- return false unless (non && !match_platform) || (!non && match_platform)
48
- end
49
-
50
- true
51
- end
52
-
53
- alias :original_suite :suite
54
- end
55
-
56
- def self.suite
57
- if match_platform?(*@platforms)
58
- original_suite
59
- else
60
- # if platforms are specfied for the tests and the platform does NOT
61
- # match, remake the suite to skip all tests.
62
- method_names = public_instance_methods(true)
63
- suite = Test::Unit::TestSuite.new(name)
64
- method_names.each do |method_name|
65
- catch(:invalid_test) do
66
- suite << new('on_test_skipped') if method_name =~ /^test/
67
- end
68
- end
69
- suite
70
- end
71
- end
74
+ # Platform-specific test. Useful for specifying test that should only be run on,
75
+ # for instance, windows. See match_platform? for details.
76
+ def platform_test(*platforms, &block)
77
+ if self.class.match_platform?(*platforms)
78
+ yield
79
+ else
80
+ print ' '
81
+ end
82
+ end
83
+
84
+ # Subset test declaration for extended tests -- type: EXTENDED
85
+ # Prints 'x' unless run.
86
+ def extended_test(&block)
87
+ subset_test("EXTENDED", "x", &block)
88
+ end
89
+
90
+ # Subset test declaration for benchmark tests -- type: BENCHMARK
91
+ # Prints 'b' unless run.
92
+ def benchmark_test(length=10, &block)
93
+ subset_test("BENCHMARK") do
94
+ puts
95
+ puts calling_method
96
+ bm(length) do |x|
97
+ yield(x)
98
+ end
99
+ end
100
+ end
72
101
 
73
- # Platform-specific test. Useful for specifying test that should only be run on,
74
- # for instance, windows. See match_platform? for details.
75
- def platform_test(*platforms, &block)
76
- if self.class.match_platform?(*platforms)
77
- yield
78
- else
79
- print ' '
80
- end
81
- end
82
-
83
- # Subset test declaration for extended tests -- type: EXTENDED
84
- # Prints 'x' unless run.
85
- def extended_test(&block)
86
- subset_test("EXTENDED", "x", &block)
87
- end
88
-
89
- # Subset test declaration for benchmark tests -- type: BENCHMARK
90
- # Prints 'b' unless run.
91
- def benchmark_test(length=10, &block)
92
- subset_test("BENCHMARK") do
93
- puts
94
- puts calling_method
95
- bm(length) do |x|
96
- yield(x)
97
- end
98
- end
99
- end
102
+ # Case tests take a hash of testcases and expected values. Each pair in the hash will
103
+ # be passed to the block if type CASE_TEST is specified. Individual cases tests can be
104
+ # specified by providing a regexp in CASE; the testcase will run if the pretty-print of
105
+ # the testcase matches the provided regexp. Example:
106
+ #
107
+ # case_test(
108
+ # [1,2,3] => 'an array testcase',
109
+ # '[1, 2, 3]' => 'the pretty print of the array',
110
+ # 'another testcase' => 'some third testcase'
111
+ # ).do |testcase, expected|
112
+ # ...your test code...
113
+ # end
114
+ #
115
+ # ENV['CASE_TEST']=true => all tests run
116
+ # ENV['CASE']='1, 2, 3' => first two tests run
117
+ # ENV['CASE']='another' => only last test runs
118
+ def case_test(hash, &block)
119
+ if match_regexp?("CASE_TEST", calling_method)
120
+ hash.each_pair do |testcase, expected|
121
+ yield(testcase, expected) if match_regexp?("CASE", testcase)
122
+ end
123
+ end
124
+ end
125
+
126
+ # Acase tests take an array of testcases. Each testcase in the array will
127
+ # be passed to the block if type CASE_TEST is specified. Individual cases tests can be
128
+ # specified by providing a regexp in CASE; the testcase will run if the pretty-print of
129
+ # the testcase matches the provided regexp. Example:
130
+ #
131
+ # case_test(
132
+ # [1,2,3] ,
133
+ # '[1, 2, 3]',
134
+ # 'another testcase'
135
+ # ).do |testcase|
136
+ # ...your test code...
137
+ # end
138
+ #
139
+ # ENV['CASE_TEST']=true => all tests run
140
+ # ENV['CASE']='1, 2, 3' => first two tests run
141
+ # ENV['CASE']='another' => only last test runs
142
+ def acase_test(*array)
143
+ if match_regexp?("CASE_TEST", calling_method)
144
+ array.each do |testcase|
145
+ yield(testcase) if match_regexp?("CASE", testcase)
146
+ end
147
+ end
148
+ end
100
149
 
101
- # Case tests take a hash of testcases and expected values. Each pair in the hash will
102
- # be passed to the block if type CASE_TEST is specified. Individual cases tests can be
103
- # specified by providing a regexp in CASE; the testcase will run if the pretty-print of
104
- # the testcase matches the provided regexp. Example:
105
- #
106
- # case_test(
107
- # [1,2,3] => 'an array testcase',
108
- # '[1, 2, 3]' => 'the pretty print of the array',
109
- # 'another testcase' => 'some third testcase'
110
- # ).do |testcase, expected|
111
- # ...your test code...
112
- # end
113
- #
114
- # ENV['CASE_TEST']=true => all tests run
115
- # ENV['CASE']='1, 2, 3' => first two tests run
116
- # ENV['CASE']='another' => only last test runs
117
- def case_test(hash, &block)
118
- if match_regexp?("CASE_TEST", calling_method)
119
- hash.each_pair do |testcase, expected|
120
- yield(testcase, expected) if match_regexp?("CASE", testcase)
121
- end
122
- end
123
- end
124
-
125
- # Acase tests take an array of testcases. Each testcase in the array will
126
- # be passed to the block if type CASE_TEST is specified. Individual cases tests can be
127
- # specified by providing a regexp in CASE; the testcase will run if the pretty-print of
128
- # the testcase matches the provided regexp. Example:
129
- #
130
- # case_test(
131
- # [1,2,3] ,
132
- # '[1, 2, 3]',
133
- # 'another testcase'
134
- # ).do |testcase|
135
- # ...your test code...
136
- # end
137
- #
138
- # ENV['CASE_TEST']=true => all tests run
139
- # ENV['CASE']='1, 2, 3' => first two tests run
140
- # ENV['CASE']='another' => only last test runs
141
- def acase_test(*array)
142
- if match_regexp?("CASE_TEST", calling_method)
143
- array.each do |testcase|
144
- yield(testcase) if match_regexp?("CASE", testcase)
145
- end
146
- end
147
- end
150
+
151
+ # Subset test declaration for prompt tests -- type: PROMPT
152
+ # Prints 'p' unless run.
153
+ #
154
+ # Useful for tests that require user input. If run, then this test will
155
+ # prompt the user for an input for each item in the array. The results
156
+ # are collected in a hash and passed to the block.
157
+ #
158
+ # Example:
159
+ #
160
+ # def test_something_important
161
+ # prompt_test(:a, :b, :c).do |config|
162
+ # ...your test code...
163
+ # end
164
+ # end
165
+ #
166
+ # (if run, prompts print to $stdout the following:)
167
+ # test_something_important: Enter values or 'skip'
168
+ # a: # => enter 'avalue'
169
+ # b: # => enter 'bvalue'
170
+ # c: # => enter 'cvalue'
171
+ #
172
+ # # config => {:a => 'avalue', :b => 'bvalue', :c => 'cvalue'}
173
+ def prompt_test(*array, &block)
174
+ subset_test("PROMPT", "p") do
175
+ puts "\n#{calling_method} -- Enter values or 'skip'."
176
+
177
+ config = {}
178
+ array.each do |key|
179
+ print "#{key}: "
180
+ value = gets.strip
181
+ flunk "skipped test" if value =~ /skip/i
182
+
183
+ config[key] = value
184
+ end
185
+
186
+ yield(config)
187
+ end
188
+ end
189
+
190
+ protected
191
+
192
+ # Formats the input by using singleline_pp
193
+ def spp(input, str='')
194
+ PP.singleline_pp(input, str)
195
+ end
196
+
197
+ # Required for platform tests
198
+ def on_test_skipped
199
+ print ' '
200
+ end
201
+
202
+ # Access to the case-insensitive ENV variables
203
+ def env(type)
204
+ self.class.env(type)
205
+ end
206
+
207
+ # Returns true if the env_var(var) is set and matches /^true%/i
208
+ def env_true?(var)
209
+ env(var) && env(var) =~ /^true$/i
210
+ end
211
+
212
+ # Returns true if the subset type or 'ALL' is specified in ENV
213
+ def run_subset?(type)
214
+ env_true?(type) || env_true?("ALL") ? true : false
215
+ end
148
216
 
149
-
150
- # Subset test declaration for prompt tests -- type: PROMPT
151
- # Prints 'p' unless run.
152
- #
153
- # Useful for tests that require user input. If run, then this test will
154
- # prompt the user for an input for each item in the array. The results
155
- # are collected in a hash and passed to the block.
156
- #
157
- # Example:
158
- #
159
- # def test_something_important
160
- # prompt_test(:a, :b, :c).do |config|
161
- # ...your test code...
162
- # end
163
- # end
164
- #
165
- # (if run, prompts print to $stdout the following:)
166
- # test_something_important: Enter values or 'skip'
167
- # a: # => enter 'avalue'
168
- # b: # => enter 'bvalue'
169
- # c: # => enter 'cvalue'
170
- #
171
- # # config => {:a => 'avalue', :b => 'bvalue', :c => 'cvalue'}
172
- def prompt_test(*array, &block)
173
- subset_test("PROMPT", "p") do
174
- puts "\n#{calling_method} -- Enter values or 'skip'."
175
-
176
- config = {}
177
- array.each do |key|
178
- print "#{key}: "
179
- value = gets.strip
180
- flunk "skipped test" if value =~ /skip/i
181
-
182
- config[key] = value
183
- end
184
-
185
- yield(config)
186
- end
187
- end
188
-
189
- protected
190
-
191
- # Formats the input by using singleline_pp
192
- def spp(input, str='')
193
- PP.singleline_pp(input, str)
194
- end
195
-
196
- # Required for platform tests
197
- def on_test_skipped
198
- print ' '
199
- end
200
-
201
- # Access to the case-insensitive ENV variables
202
- def env(type)
203
- self.class.env(type)
204
- end
205
-
206
- # Returns true if the env_var(var) is set and matches /^true%/i
207
- def env_true?(var)
208
- env(var) && env(var) =~ /^true$/i
209
- end
210
-
211
- # Returns true if the subset type or 'ALL' is specified in ENV
212
- def run_subset?(type)
213
- env_true?(type) || env_true?("ALL") ? true : false
214
- end
215
-
216
- # Returns true if the pretty-print string for obj matches the regexp specified in env_var(type).
217
- # Returns the default value if 'ALL' is specified in ENV or type is not specified in ENV.
218
- def match_regexp?(type, obj, default=true)
219
- return true if env_true?("ALL")
220
- return default unless env(type)
221
-
222
- spp(obj) =~ Regexp.new(env(type)) ? true : false
223
- end
224
-
225
- # Calling method iterates over the call stack, and returns the first calling
226
- # method name that matches the input pattern (by default /^test/)
227
- def calling_method(pattern=/^test/)
228
- 0.upto(caller.length) do |i|
229
- caller[i] =~ /:in `(.*)'$/
230
- method_name = $1
231
- return method_name if method_name =~ pattern
232
- end
233
-
234
- ''
235
- end
236
-
237
- # Basic method for a subset test. The provided block will run if:
238
- # - The subset type or 'ALL' is specified in ENV
239
- # - The calling method matches the regexp provided in the "TYPE_TEST" ENV variable
240
- #
241
- # Otherwise the block will be skipped and +skip+ will be printed. By default skip
242
- # is the first letter of +type+.
243
- def subset_test(type, skip=type[0..0].downcase, &block)
244
- type = type.upcase
245
- type_test = "#{type}_TEST"
246
- if run_subset?(type) || env(type_test)
247
- if match_regexp?(type_test, calling_method)
248
- yield
249
- else
250
- print skip
251
- end
252
- else
253
- print skip
254
- end
255
- end
256
-
257
- # Runs only if the first argument causes an 'if' statement to return true.
258
- def switch_test(run_test, skip="!", &block)
259
- if run_test
260
- yield
261
- else
262
- print skip
263
- end
264
- end
217
+ # Returns true if the pretty-print string for obj matches the regexp specified in env_var(type).
218
+ # Returns the default value if 'ALL' is specified in ENV or type is not specified in ENV.
219
+ def match_regexp?(type, obj, default=true)
220
+ return true if env_true?("ALL")
221
+ return default unless env(type)
222
+
223
+ spp(obj) =~ Regexp.new(env(type)) ? true : false
224
+ end
225
+
226
+ # Calling method iterates over the call stack, and returns the first calling
227
+ # method name that matches the input pattern (by default /^test/)
228
+ def calling_method(pattern=/^test/)
229
+ 0.upto(caller.length) do |i|
230
+ caller[i] =~ /:in `(.*)'$/
231
+ method_name = $1
232
+ return method_name if method_name =~ pattern
233
+ end
234
+
235
+ ''
236
+ end
237
+
238
+ # Basic method for a subset test. The provided block will run if:
239
+ # - The subset type or 'ALL' is specified in ENV
240
+ # - The calling method matches the regexp provided in the "TYPE_TEST" ENV variable
241
+ #
242
+ # Otherwise the block will be skipped and +skip+ will be printed. By default skip
243
+ # is the first letter of +type+.
244
+ def subset_test(type, skip=type[0..0].downcase, &block)
245
+ type = type.upcase
246
+ type_test = "#{type}_TEST"
247
+ if run_subset?(type) || env(type_test)
248
+ if match_regexp?(type_test, calling_method)
249
+ yield
250
+ else
251
+ print skip
252
+ end
253
+ else
254
+ print skip
255
+ end
256
+ end
257
+
258
+ # Runs only if the first argument causes an 'if' statement to return true.
259
+ def switch_test(run_test, skip="!", &block)
260
+ if run_test
261
+ yield
262
+ else
263
+ print skip
264
+ end
265
+ end
266
+ end
267
+ end
265
268
  end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Gem specification
3
+ #
4
+ Gem::Specification.new do |s|
5
+ s.name = "gem_with_folder_require"
6
+ s.version = "0.1.1"
7
+ s.require_path = "lib"
8
+ s.autorequire = "folder_require"
9
+ end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Gem specification
3
+ #
4
+ Gem::Specification.new do |s|
5
+ s.name = "rakefile_with_multiple_specs"
6
+ s.version = "0.1.2"
7
+ s.require_path = "lib"
8
+ s.autorequire = "unrequired"
9
+ end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Gem specification
3
+ #
4
+ Gem::Specification.new { |s|
5
+ s.name = "rakefile_with_multiple_specs"
6
+ s.version = "0.1.3"
7
+ s.require_path = "lib"
8
+ s.autorequire = "multiple_spec_require"
9
+ }
@@ -0,0 +1,9 @@
1
+ #
2
+ # Gem specification
3
+ #
4
+ Gem::Specification.new do |s|
5
+ s.name = "rakefile_with_multiple_specs"
6
+ s.version = "0.1.1"
7
+ s.require_path = "lib"
8
+ s.autorequire = "unrequired"
9
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: gemdev
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2007-05-08 00:00:00 -06:00
6
+ version: 0.1.3
7
+ date: 2007-05-29 00:00:00 -06:00
8
8
  summary: Making gem development a bit easier.
9
9
  require_paths:
10
10
  - lib
@@ -30,20 +30,24 @@ authors:
30
30
  - Simon Chiang
31
31
  files:
32
32
  - test/gemdev
33
- - test/gemdev_test.rb
34
- - test/gemdev_test_helper.rb
35
- - test/gemdev_test_suite.rb
36
- - test/subsets_test.rb
37
33
  - test/gemdev/gemrc
38
34
  - test/gemdev/gem_with_folder_require
39
- - test/gemdev/rakefile_with_multiple_specs
35
+ - test/gemdev/gem_with_folder_require/gemspecs
36
+ - test/gemdev/gem_with_folder_require/gemspecs/some.gemspec
40
37
  - test/gemdev/gem_with_folder_require/lib
41
- - test/gemdev/gem_with_folder_require/Rakefile
42
38
  - test/gemdev/gem_with_folder_require/lib/folder_require.rb
39
+ - test/gemdev/rakefile_with_multiple_specs
40
+ - test/gemdev/rakefile_with_multiple_specs/gemspecs
41
+ - test/gemdev/rakefile_with_multiple_specs/gemspecs/1.gemspec
42
+ - test/gemdev/rakefile_with_multiple_specs/gemspecs/2.gemspec
43
+ - test/gemdev/rakefile_with_multiple_specs/gemspecs/3.gemspec
43
44
  - test/gemdev/rakefile_with_multiple_specs/lib
44
- - test/gemdev/rakefile_with_multiple_specs/Rakefile
45
45
  - test/gemdev/rakefile_with_multiple_specs/lib/multiple_spec_require.rb
46
46
  - test/gemdev/rakefile_with_multiple_specs/lib/unrequired.rb
47
+ - test/gemdev_test.rb
48
+ - test/gemdev_test_helper.rb
49
+ - test/gemdev_test_suite.rb
50
+ - test/subsets_test.rb
47
51
  - lib/gemdev.rb
48
52
  - lib/test
49
53
  - lib/test/unit
@@ -1,15 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
-
6
- #
7
- # Gem specification
8
- #
9
- Gem::manage_gems
10
- spec = Gem::Specification.new do |s|
11
- s.name = "gem_with_folder_require"
12
- s.version = "0.1.1"
13
- s.require_path = "lib"
14
- s.autorequire = "folder_require"
15
- end
@@ -1,29 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- require 'rake/gempackagetask'
5
-
6
- #
7
- # Gem specification
8
- #
9
- spec = Gem::Specification.new do |s|
10
- s.name = "rakefile_with_multiple_specs"
11
- s.version = "0.1.2"
12
- s.require_path = "lib"
13
- s.autorequire = "unrequired"
14
- end
15
-
16
- spec = Gem::Specification.new { |s|
17
- s.name = "rakefile_with_multiple_specs"
18
- s.version = "0.1.3"
19
- s.require_path = "lib"
20
- s.autorequire = "multiple_spec_require"
21
- }
22
-
23
- # out of order
24
- spec = Gem::Specification.new do |s|
25
- s.name = "rakefile_with_multiple_specs"
26
- s.version = "0.1.1"
27
- s.require_path = "lib"
28
- s.autorequire = "unrequired"
29
- end