sprout 1.0.35.pre → 1.1.2.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

Files changed (234) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +0 -2
  3. data/README.textile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/sprout/concern.rb +5 -7
  6. data/lib/sprout/daemon.rb +183 -143
  7. data/lib/sprout/executable/base.rb +564 -0
  8. data/lib/sprout/executable.rb +1 -550
  9. data/lib/sprout/generator/base.rb +2 -3
  10. data/lib/sprout/generator.rb +2 -1
  11. data/lib/sprout/generators/ruby/templates/ruby_base.rb +1 -2
  12. data/lib/sprout/library.rb +3 -3
  13. data/lib/sprout/output_buffer.rb +35 -0
  14. data/lib/sprout/process_runner.rb +68 -17
  15. data/lib/sprout/progress_bar.rb +5 -5
  16. data/lib/sprout/remote_file_target.rb +1 -1
  17. data/lib/sprout/system/base_system.rb +3 -3
  18. data/lib/sprout/system/unix_system.rb +1 -1
  19. data/lib/sprout/{test/sprout_test_case.rb → test_helper.rb} +214 -14
  20. data/lib/sprout/version.rb +1 -1
  21. data/lib/sprout.rb +133 -2
  22. data/rakefile.rb +2 -0
  23. data/test/fixtures/examples/echo_inputs.rb +1 -2
  24. data/test/fixtures/executable/fdb.rb +7 -9
  25. data/test/fixtures/executable/flex3sdk_gem/fdb +49 -18
  26. data/test/fixtures/executable/mxmlc.rb +1 -2
  27. data/test/fixtures/executable/subclass/executable_subclass.rb +0 -1
  28. data/test/fixtures/executable/subclass/executable_superclass.rb +1 -2
  29. data/test/fixtures/specification/flex4sdk.rb +35 -24
  30. data/test/unit/archive_unpacker_test.rb +1 -1
  31. data/test/unit/boolean_param_test.rb +1 -1
  32. data/test/unit/daemon_test.rb +35 -3
  33. data/test/unit/executable_option_parser_test.rb +2 -3
  34. data/test/unit/executable_param_test.rb +1 -1
  35. data/test/unit/executable_test.rb +8 -15
  36. data/test/unit/fake_other_executable.rb +1 -2
  37. data/test/unit/file_param_test.rb +1 -1
  38. data/test/unit/file_target_test.rb +1 -1
  39. data/test/unit/files_param_test.rb +1 -1
  40. data/test/unit/generator_generator_test.rb +1 -1
  41. data/test/unit/generator_test.rb +1 -1
  42. data/test/unit/library_generator_test.rb +1 -1
  43. data/test/unit/library_test.rb +1 -1
  44. data/test/unit/osx_system_test.rb +1 -1
  45. data/test/unit/path_param_test.rb +1 -1
  46. data/test/unit/paths_param_test.rb +1 -1
  47. data/test/unit/platform_test.rb +1 -1
  48. data/test/unit/process_runner_test.rb +1 -1
  49. data/test/unit/rdoc_parser_test.rb +1 -1
  50. data/test/unit/remote_file_loader_test.rb +1 -1
  51. data/test/unit/remote_file_target_test.rb +1 -1
  52. data/test/unit/ruby_feature_test.rb +1 -1
  53. data/test/unit/ruby_generator_test.rb +1 -1
  54. data/test/unit/specification_test.rb +8 -1
  55. data/test/unit/sprout_test.rb +2 -2
  56. data/test/unit/string_param_test.rb +1 -1
  57. data/test/unit/string_test.rb +1 -1
  58. data/test/unit/strings_param_test.rb +1 -1
  59. data/test/unit/test_helper.rb +33 -1
  60. data/test/unit/tool_generator_test.rb +1 -1
  61. data/test/unit/unix_system_test.rb +1 -1
  62. data/test/unit/user_test.rb +1 -1
  63. data/test/unit/vista_system_test.rb +1 -1
  64. data/test/unit/win_nix_system_test.rb +1 -1
  65. data/test/unit/win_system_test.rb +1 -1
  66. data/test-stderr.log +1 -0
  67. data/test-stdout.log +237 -0
  68. metadata +15 -190
  69. data/doc/Dir.html +0 -288
  70. data/doc/Rake/Task.html +0 -184
  71. data/doc/Sprout/ArchiveUnpacker.html +0 -1246
  72. data/doc/Sprout/Base/ClassMethods.html +0 -434
  73. data/doc/Sprout/Base.html +0 -126
  74. data/doc/Sprout/Concern.html +0 -353
  75. data/doc/Sprout/Daemon/ClassMethods.html +0 -244
  76. data/doc/Sprout/Daemon/InstanceMethods.html +0 -601
  77. data/doc/Sprout/Daemon.html +0 -166
  78. data/doc/Sprout/Errors/ArchiveUnpackerError.html +0 -125
  79. data/doc/Sprout/Errors/DestinationExistsError.html +0 -133
  80. data/doc/Sprout/Errors/DuplicateMemberError.html +0 -132
  81. data/doc/Sprout/Errors/ExecutableError.html +0 -125
  82. data/doc/Sprout/Errors/ExecutableRegistrationError.html +0 -132
  83. data/doc/Sprout/Errors/ExecutionError.html +0 -121
  84. data/doc/Sprout/Errors/GeneratorError.html +0 -125
  85. data/doc/Sprout/Errors/InvalidArgumentError.html +0 -132
  86. data/doc/Sprout/Errors/LoadError.html +0 -121
  87. data/doc/Sprout/Errors/MissingArgumentError.html +0 -132
  88. data/doc/Sprout/Errors/MissingExecutableError.html +0 -132
  89. data/doc/Sprout/Errors/MissingGeneratorError.html +0 -132
  90. data/doc/Sprout/Errors/MissingTemplateError.html +0 -132
  91. data/doc/Sprout/Errors/ProcessRunnerError.html +0 -121
  92. data/doc/Sprout/Errors/RemoteFileLoaderError.html +0 -110
  93. data/doc/Sprout/Errors/SproutError.html +0 -114
  94. data/doc/Sprout/Errors/UnknownArchiveType.html +0 -122
  95. data/doc/Sprout/Errors/UsageError.html +0 -121
  96. data/doc/Sprout/Errors/ValidationError.html +0 -121
  97. data/doc/Sprout/Errors/VersionRequirementNotMetError.html +0 -121
  98. data/doc/Sprout/Errors.html +0 -101
  99. data/doc/Sprout/Executable/Boolean.html +0 -483
  100. data/doc/Sprout/Executable/ClassMethods.html +0 -417
  101. data/doc/Sprout/Executable/CollectionParam.html +0 -483
  102. data/doc/Sprout/Executable/FileParam.html +0 -484
  103. data/doc/Sprout/Executable/Files.html +0 -292
  104. data/doc/Sprout/Executable/InstanceMethods.html +0 -2006
  105. data/doc/Sprout/Executable/Number.html +0 -141
  106. data/doc/Sprout/Executable/Param.html +0 -2818
  107. data/doc/Sprout/Executable/ParameterFactory.html +0 -232
  108. data/doc/Sprout/Executable/Path.html +0 -223
  109. data/doc/Sprout/Executable/Paths.html +0 -253
  110. data/doc/Sprout/Executable/StringParam.html +0 -213
  111. data/doc/Sprout/Executable/Strings.html +0 -167
  112. data/doc/Sprout/Executable/Url.html +0 -160
  113. data/doc/Sprout/Executable/Urls.html +0 -170
  114. data/doc/Sprout/Executable.html +0 -173
  115. data/doc/Sprout/FileTarget.html +0 -1109
  116. data/doc/Sprout/Generator/Base.html +0 -1626
  117. data/doc/Sprout/Generator/Command.html +0 -690
  118. data/doc/Sprout/Generator/DirectoryManifest.html +0 -476
  119. data/doc/Sprout/Generator/FileManifest.html +0 -572
  120. data/doc/Sprout/Generator/Manifest.html +0 -377
  121. data/doc/Sprout/Generator/TemplateManifest.html +0 -196
  122. data/doc/Sprout/Generator.html +0 -689
  123. data/doc/Sprout/GeneratorGenerator.html +0 -1018
  124. data/doc/Sprout/Library.html +0 -1141
  125. data/doc/Sprout/LibraryGenerator.html +0 -309
  126. data/doc/Sprout/Log.html +0 -496
  127. data/doc/Sprout/MXMLC.html +0 -6373
  128. data/doc/Sprout/Platform.html +0 -714
  129. data/doc/Sprout/ProcessRunner.html +0 -1352
  130. data/doc/Sprout/ProgressBar.html +0 -376
  131. data/doc/Sprout/ProgressBarImpl.html +0 -2119
  132. data/doc/Sprout/ProgressBarManager.html +0 -434
  133. data/doc/Sprout/ProgressBarOutputStream.html +0 -416
  134. data/doc/Sprout/RDocParser.html +0 -211
  135. data/doc/Sprout/RemoteFileLoader.html +0 -172
  136. data/doc/Sprout/RemoteFileTarget.html +0 -679
  137. data/doc/Sprout/ReversedProgressBar.html +0 -194
  138. data/doc/Sprout/RubyFeature/ClassMethods.html +0 -1065
  139. data/doc/Sprout/RubyFeature.html +0 -155
  140. data/doc/Sprout/RubyGenerator.html +0 -764
  141. data/doc/Sprout/Specification.html +0 -767
  142. data/doc/Sprout/System/BaseSystem.html +0 -1455
  143. data/doc/Sprout/System/JavaSystem.html +0 -122
  144. data/doc/Sprout/System/OSXSystem.html +0 -335
  145. data/doc/Sprout/System/ThreadMock.html +0 -193
  146. data/doc/Sprout/System/UnixSystem.html +0 -584
  147. data/doc/Sprout/System/VistaSystem.html +0 -251
  148. data/doc/Sprout/System/WinNixSystem.html +0 -325
  149. data/doc/Sprout/System/WinSystem.html +0 -571
  150. data/doc/Sprout/System.html +0 -191
  151. data/doc/Sprout/ToolGenerator.html +0 -931
  152. data/doc/Sprout/VERSION.html +0 -128
  153. data/doc/Sprout.html +0 -144
  154. data/doc/SproutTestCase.html +0 -1412
  155. data/doc/String.html +0 -286
  156. data/doc/_index.html +0 -1035
  157. data/doc/class_list.html +0 -36
  158. data/doc/css/common.css +0 -1
  159. data/doc/css/full_list.css +0 -53
  160. data/doc/css/style.css +0 -310
  161. data/doc/file.README.html +0 -96
  162. data/doc/file.archive_unpacker.html +0 -288
  163. data/doc/file.base.html +0 -208
  164. data/doc/file.base_system.html +0 -278
  165. data/doc/file.boolean.html +0 -135
  166. data/doc/file.collection_param.html +0 -139
  167. data/doc/file.command.html +0 -126
  168. data/doc/file.concern.html +0 -136
  169. data/doc/file.daemon.html +0 -309
  170. data/doc/file.dir.html +0 -76
  171. data/doc/file.directory_manifest.html +0 -122
  172. data/doc/file.errors.html +0 -147
  173. data/doc/file.executable.html +0 -638
  174. data/doc/file.file_manifest.html +0 -109
  175. data/doc/file.file_param.html +0 -120
  176. data/doc/file.file_target.html +0 -140
  177. data/doc/file.files.html +0 -85
  178. data/doc/file.generator.html +0 -296
  179. data/doc/file.generator_class.html +0 -72
  180. data/doc/file.generator_generator.html +0 -137
  181. data/doc/file.generator_test.html +0 -92
  182. data/doc/file.generator_test_helper.html +0 -67
  183. data/doc/file.java_system.html +0 -62
  184. data/doc/file.library.html +0 -291
  185. data/doc/file.library_generator.html +0 -74
  186. data/doc/file.log.html +0 -100
  187. data/doc/file.manifest.html +0 -67
  188. data/doc/file.mxmlc.html +0 -740
  189. data/doc/file.number.html +0 -67
  190. data/doc/file.osx_system.html +0 -79
  191. data/doc/file.param.html +0 -491
  192. data/doc/file.parameter_factory.html +0 -119
  193. data/doc/file.path.html +0 -81
  194. data/doc/file.paths.html +0 -80
  195. data/doc/file.platform.html +0 -124
  196. data/doc/file.process_runner.html +0 -224
  197. data/doc/file.progress_bar.html +0 -390
  198. data/doc/file.rdoc_parser.html +0 -145
  199. data/doc/file.remote_file_loader.html +0 -117
  200. data/doc/file.remote_file_target.html +0 -176
  201. data/doc/file.ruby_base.html +0 -64
  202. data/doc/file.ruby_feature.html +0 -244
  203. data/doc/file.ruby_generator.html +0 -118
  204. data/doc/file.ruby_input.html +0 -62
  205. data/doc/file.ruby_test_case.html +0 -78
  206. data/doc/file.ruby_test_helper.html +0 -61
  207. data/doc/file.specification.html +0 -248
  208. data/doc/file.sprout.html +0 -64
  209. data/doc/file.sprout_test_case.html +0 -280
  210. data/doc/file.string.html +0 -72
  211. data/doc/file.string_param.html +0 -76
  212. data/doc/file.strings.html +0 -71
  213. data/doc/file.system.html +0 -86
  214. data/doc/file.template_manifest.html +0 -67
  215. data/doc/file.tool.html +0 -92
  216. data/doc/file.tool_generator.html +0 -90
  217. data/doc/file.unix_system.html +0 -128
  218. data/doc/file.url.html +0 -71
  219. data/doc/file.urls.html +0 -70
  220. data/doc/file.version.html +0 -71
  221. data/doc/file.vista_system.html +0 -69
  222. data/doc/file.win_nix_system.html +0 -88
  223. data/doc/file.win_system.html +0 -129
  224. data/doc/file_list.html +0 -230
  225. data/doc/frames.html +0 -13
  226. data/doc/index.html +0 -96
  227. data/doc/js/app.js +0 -202
  228. data/doc/js/full_list.js +0 -149
  229. data/doc/js/jquery.js +0 -154
  230. data/doc/method_list.html +0 -3355
  231. data/doc/top-level-namespace.html +0 -192
  232. data/lib/sprout/base.rb +0 -121
  233. data/lib/sprout/log.rb +0 -46
  234. data/test/unit/sprout_test_helper.rb +0 -33
@@ -1,30 +1,43 @@
1
1
 
2
- module Sprout #:nodoc:
2
+ module Sprout
3
3
 
4
4
  # The ProcessRunner is a cross-platform wrapper for executing
5
5
  # external executable processes.
6
6
  #
7
- # As it turns out, Ruby handle differences very well, and
8
- # other process libraries (like win32-open3 and open4.popen4),
9
- # do make the experience more consistent on a given platform,
10
- # but they don't hide the differences introduced by the
11
- # continuing beligerence of Windows or *nix (depending on
12
- # which side of the fence you're on).
7
+ # This class is typically accesses via the concrete Sprout::System
8
+ # classes in order to avoid ugly branching logic in the application
9
+ # layer.
10
+ #
11
+ # An example of this kind of usage might be:
12
+ #
13
+ # Sprout.current_system.execute './some.exe', '--foo=bar --baz=buz'
14
+ #
15
+ # To use this class directly, you need to know if you're on
16
+ # a unix-like system or a dos platform as these two deal with
17
+ # processes very differently.
18
+ #
19
+ # Assuming you know you're on a unix-like system, you could
20
+ # execute the previous example with:
21
+ #
22
+ # runner = Sprout::ProcessRunner.new
23
+ # runner.execute_open4 './some.exe --foo-bar --baz=buz'
24
+ # puts runner.read
25
+ #
13
26
  class ProcessRunner
14
27
 
15
28
  attr_reader :pid
16
29
  attr_reader :ruby_version
17
30
 
18
31
  ##
19
- # Read IO (readable)
32
+ # @return [IO] Read only
20
33
  attr_reader :r
21
34
 
22
35
  ##
23
- # Write IO (writeable)
36
+ # @return [IO] Write only
24
37
  attr_reader :w
25
38
 
26
39
  ##
27
- # Error IO (readable)
40
+ # @return [IO] Error output
28
41
  attr_reader :e
29
42
 
30
43
  def initialize
@@ -32,6 +45,7 @@ module Sprout #:nodoc:
32
45
  @ruby_version = RUBY_VERSION
33
46
  end
34
47
 
48
+ ##
35
49
  # Execute the provided command using the open4.popen4
36
50
  # library. This is generally only used by Cygwin and
37
51
  # *nix variants (including OS X).
@@ -44,27 +58,36 @@ module Sprout #:nodoc:
44
58
  end
45
59
  end
46
60
 
61
+ ##
47
62
  # Execute the provided command using the win32-open3
48
- # library. This is generally used even by 64-bit
49
- # Windows installations.
63
+ # library. This is generally used only only Windows
64
+ # systems (even 64 bit).
50
65
  def execute_win32(*command)
51
66
  execute_with_block *command do
52
67
  @pid, @w, @r, @e = io_popen_block *command.join(' ')
53
68
  end
54
69
  end
55
70
 
71
+ ##
72
+ # @return [Boolean] whether the process is still running.
56
73
  def alive?
57
74
  @alive = update_status
58
75
  end
59
76
 
77
+ ##
78
+ # Kill the process.
60
79
  def kill
61
80
  Process.kill(9, pid)
62
81
  end
63
82
 
83
+ ##
84
+ # Close the process
64
85
  def close
65
86
  update_status
66
87
  end
67
88
 
89
+ ##
90
+ # Send an update signal to the process.
68
91
  def update_status
69
92
  pid_int = Integer("#{ @pid }")
70
93
  begin
@@ -75,42 +98,70 @@ module Sprout #:nodoc:
75
98
  end
76
99
  end
77
100
 
78
- def readpartial(count)
79
- @r.readpartial(count)
101
+ ##
102
+ # Read +count+ characters from the process standard out.
103
+ #
104
+ # @param count [Integer] Number of characters to read.
105
+ # @return [String]
106
+ def readpartial count
107
+ @r.readpartial count
80
108
  end
81
109
 
82
- def readlines
83
- @r.readlines
110
+ ##
111
+ # Read +count+ lines from the process standard out.
112
+ #
113
+ # @param count [Integer] Number of lines to read.
114
+ # @return [String]
115
+ def readlines count
116
+ @r.readlines count
84
117
  end
85
118
 
119
+ ##
120
+ # Flush the write IO to the process.
86
121
  def flush
87
122
  @w.flush
88
123
  end
89
124
 
125
+ ##
126
+ # Get user input on the read stream from the process.
90
127
  def getc
91
128
  @r.getc
92
129
  end
93
130
 
94
- def print(msg)
131
+ ##
132
+ # Print some characters to process without an end of line character.
133
+ def print msg
95
134
  @w.print msg
96
135
  end
97
136
 
137
+ ##
138
+ # Print characters to the process followed by an end of line.
98
139
  def puts(msg)
99
140
  @w.puts(msg)
100
141
  end
101
142
 
143
+ ##
144
+ # Close the write stream - usually terminates the process.
102
145
  def close_write
103
146
  @w.close_write
104
147
  end
105
148
 
149
+ ##
150
+ # Wait for the process to end and return the entire standard output.
106
151
  def read
107
152
  return @r.read
108
153
  end
109
154
 
155
+ ##
156
+ # Wait for the process to end and return the entire standard error.
110
157
  def read_err
111
158
  return @e.read
112
159
  end
113
160
 
161
+ def readpartial_err count
162
+ return @e.readpartial count
163
+ end
164
+
114
165
  private
115
166
 
116
167
  def open4_popen4_block *command
@@ -13,7 +13,7 @@
13
13
  require 'singleton'
14
14
 
15
15
  module Sprout
16
- class ProgressBar # :nodoc:[all]
16
+ class ProgressBar
17
17
  VERSION = "0.9"
18
18
  @@debug = false
19
19
  @@outio = $stderr
@@ -41,7 +41,7 @@ module Sprout
41
41
 
42
42
  end
43
43
 
44
- class ProgressBarImpl # :nodoc:[all]
44
+ class ProgressBarImpl
45
45
 
46
46
  def initialize (title, total, out = STDERR)
47
47
  @title = title
@@ -265,13 +265,13 @@ module Sprout
265
265
  end
266
266
  end
267
267
 
268
- class ReversedProgressBar < ProgressBar # :nodoc:[all]
268
+ class ReversedProgressBar < ProgressBar
269
269
  def do_percentage
270
270
  100 - super
271
271
  end
272
272
  end
273
273
 
274
- class ProgressBarOutputStream # :nodoc:[all]
274
+ class ProgressBarOutputStream
275
275
  attr_reader :title
276
276
 
277
277
  def initialize(mgr)
@@ -293,7 +293,7 @@ module Sprout
293
293
 
294
294
  end
295
295
 
296
- class ProgressBarManager # :nodoc:[all]
296
+ class ProgressBarManager
297
297
  include Singleton
298
298
 
299
299
  def initialize
@@ -44,7 +44,7 @@ module Sprout
44
44
  protected
45
45
 
46
46
  def logger
47
- Sprout::Log
47
+ Sprout.stdout
48
48
  end
49
49
 
50
50
  def expand_local_path path
@@ -68,13 +68,13 @@ module Sprout::System
68
68
  # Raises a +Sprout::Errors::ExecutionError+ if the process writes to stderr
69
69
  #
70
70
  def execute(tool, options='')
71
- Sprout::Log.puts("#{tool} #{options}")
71
+ Sprout.stdout.puts("#{tool} #{options}")
72
72
  runner = get_and_execute_process_runner(tool, options)
73
73
  error = runner.read_err
74
74
  result = runner.read
75
75
 
76
76
  if(result.size > 0)
77
- Sprout::Log.puts result
77
+ Sprout.stdout.puts result
78
78
  end
79
79
 
80
80
  if(error.size > 0)
@@ -216,7 +216,7 @@ module Sprout::System
216
216
 
217
217
  end
218
218
 
219
- class ThreadMock # :nodoc:
219
+ class ThreadMock
220
220
  def alive?
221
221
  return false
222
222
  end
@@ -50,7 +50,7 @@ module Sprout::System
50
50
  def repair_executable path
51
51
  content = File.read(path)
52
52
  if(content.match(/\r\n/))
53
- Sprout::Log.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
53
+ Sprout.stdout.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
54
54
  content.gsub!(/\r\n/, "\n")
55
55
  File.open(path, 'w+') do |f|
56
56
  f.write content
@@ -1,24 +1,74 @@
1
1
 
2
- # Had to make this a module instead of a base class
3
- # because the ruby test suite kept complaining that
4
- # the abstract test case didn't have any test mehods
5
- # or assertions
6
- module SproutTestCase # :nodoc:[all]
2
+ ##
3
+ # A collection of custom assertions and helper methods
4
+ # to take some of the suck out of testing functionality
5
+ # that is based on Sprout features.
6
+ #
7
+ # Include this module into your test cases to make
8
+ # testing Sprout tools easier.
9
+ #
10
+ # require 'sprout/test/sprout_test_helper'
11
+ #
12
+ # class SomeTestCase < Test::Unit::TestCase
13
+ # include Sprout::TestHelper
14
+ #
15
+ # def setup
16
+ # super
17
+ # # do something
18
+ # end
19
+ #
20
+ # def teardown
21
+ # super
22
+ # # do something
23
+ # end
24
+ #
25
+ # def test_something
26
+ # assert_file File.join(fixtures, 'some_file') do |f|
27
+ # assert_matches /Fred/, f
28
+ # end
29
+ # end
30
+ # end
31
+ #
32
+ module Sprout::TestHelper
33
+
34
+ ##
35
+ # The name of the folder that should contain
36
+ # fixture data.
7
37
  FIXTURES_NAME = 'fixtures'
8
38
 
9
39
  # Gives us the ability to hide RubyGem output from
10
40
  # our test results...
11
41
  include Gem::DefaultUserInteraction
12
42
 
43
+ ##
44
+ # Add the skip method that was introduced in Ruby 1.9.1 Test::Unit
45
+ # This doesn't really work all that well...
46
+ if(RUBY_VERSION == '1.8.7')
47
+ def skip message=""
48
+ puts
49
+ puts ">> SproutTestCase.skip called from: #{caller[0]} ( #{message} )"
50
+ end
51
+ end
52
+
53
+ ##
54
+ # @return [Dir] Path to a fixtures folder that is next to
55
+ # the text case that calls this method.
13
56
  def fixtures from=nil
14
57
  @fixtures ||= find_fixtures(from || Sprout.file_from_caller(caller.first))
15
58
  end
16
59
 
60
+ ##
61
+ # Override the setup method in order to record the
62
+ # working directory before the test method runs.
17
63
  def setup
18
64
  super
19
65
  @start_path = Dir.pwd
20
66
  end
21
67
 
68
+ ##
69
+ # Override the teardown method in order to perform
70
+ # systemic cleanup work like, clearing lingering rake tasks,
71
+ # and removing temporary folders.
22
72
  def teardown
23
73
  super
24
74
  clear_tasks
@@ -35,56 +85,123 @@ module SproutTestCase # :nodoc:[all]
35
85
  end
36
86
  end
37
87
 
88
+ protected
89
+
90
+ ##
91
+ # Create a temporary folder relative to the
92
+ # test case that calls this method.
93
+ #
94
+ # @return [Dir] Path to the requested temp folder.
38
95
  def temp_path
39
96
  caller_file = Sprout.file_from_caller caller.first
40
97
  @temp_path ||= make_temp_folder File.dirname(caller_file)
41
98
  end
42
99
 
100
+ ##
101
+ # Create a temporary folder relative to the
102
+ # provided path.
103
+ #
104
+ # @param from [Dir] Folder within which a 'tmp' folder should be added.
105
+ #
106
+ # @return [Dir] Path to the requested temp folder.
43
107
  def make_temp_folder from
44
108
  dir = File.join(fixtures(from), 'tmp')
45
109
  FileUtils.mkdir_p dir
46
110
  dir
47
111
  end
48
112
 
113
+ ##
114
+ # Invoke a Rake task by name.
115
+ #
116
+ # @return [Rake::Task] The task that was invoked.
49
117
  def run_task(name)
50
118
  t = Rake.application[name]
51
119
  t.invoke
52
120
  return t
53
121
  end
54
122
 
123
+ ##
124
+ # Retrieve a registered Rake task by name.
125
+ #
126
+ # @return [Rake::Task] The task that was found.
55
127
  def get_task(name)
56
128
  return Rake.application[name]
57
129
  end
58
130
 
131
+ ##
132
+ # Clear all registered Rake tasks.
59
133
  def clear_tasks
60
134
  CLEAN.delete_if {|a| true }
61
135
  Rake::Task.clear
62
136
  Rake.application.clear
63
137
  end
64
138
 
139
+ ##
140
+ # Create an empty file at +path+
141
+ #
142
+ # @param [File] The path to the file that should be created.
143
+ # @return [File] The path to the file.
65
144
  def create_file path
66
145
  dir = File.dirname path
67
146
  FileUtils.mkdir_p dir
68
147
  FileUtils.touch path
69
148
  end
70
149
 
150
+ ##
151
+ # Remove a file if it exists. If no file exists,
152
+ # do nothing.
153
+ #
154
+ # @param path [File] Path to the file that should be removed.
71
155
  def remove_file(path=nil)
72
156
  if(path && File.exists?(path))
73
157
  FileUtils.rm_rf(path)
74
158
  end
75
159
  end
76
160
 
161
+ ##
162
+ # Assert that a file exists at +path+ and display +message+
163
+ # if it does not.
164
+ #
165
+ # @param path [File] Path to the file that should exist.
166
+ # @param message [String] The message that should be displayed if the expected file does not exist.
167
+ # @yield [String] The contents of the file.
168
+ #
169
+ # This method yields the file contents so that you can write
170
+ # readable tests like:
171
+ #
172
+ # assert_file File.join(fixtures, 'my_file') do |f|
173
+ # assert_matches /Johnny/, f
174
+ # end
175
+ #
77
176
  def assert_file(path, message=nil)
78
177
  message ||= "Expected file not found at #{path}"
79
178
  assert(File.exists?(path), message)
80
179
  yield File.read(path) if block_given?
81
180
  end
82
181
 
182
+ ##
183
+ # Assert that a directory exists at +path+ and display +message+
184
+ # if it does not.
185
+ #
186
+ # @param path [Dir] Path to the directory that should exist.
187
+ # @param message [String] The message that should be displayed if the expected directory does not exist.
188
+ #
189
+ # assert_directory File.join(fixtures, 'SomeDir')
190
+ #
83
191
  def assert_directory(path, message=nil)
84
192
  message ||= "Expected directory not found at #{path}"
85
193
  assert(File.directory?(path), message)
86
194
  end
87
195
 
196
+ ##
197
+ # Assert that a file exists at +path+ and is not empty. Display
198
+ # +message+ if the file does not exist or if it is empty.
199
+ # @param path [File] Path to the file that should exist.
200
+ # @param message [String] The message that should be displayed if
201
+ # the expected file does not exist or is empty.
202
+ #
203
+ # assert_not_empty File.join(fixtures, 'SomeFile')
204
+ #
88
205
  def assert_not_empty(path, message=nil)
89
206
  assert_file path, message
90
207
  files = FileList["#{path}/*"]
@@ -92,6 +209,14 @@ module SproutTestCase # :nodoc:[all]
92
209
  assert files.size > 0, message
93
210
  end
94
211
 
212
+ ##
213
+ # Assert that an expression matches the provided string.
214
+ #
215
+ # This helper mainly makes tests more readable and provides
216
+ # simpler failure messages without extra work.
217
+ #
218
+ # assert_matches /Fred/, 'Bill, Fred, Bob'
219
+ #
95
220
  def assert_matches(expression, string, message='')
96
221
  if(expression.is_a?(String))
97
222
  expresion = /#{expression}/
@@ -102,20 +227,52 @@ module SproutTestCase # :nodoc:[all]
102
227
  end
103
228
 
104
229
  ##
105
- # Add the skip method that was introduced in Ruby 1.9.1 Test::Unit
106
- # This doesn't really work all that well...
107
- if(RUBY_VERSION == '1.8.7')
108
- def skip message=""
109
- puts
110
- puts ">> SproutTestCase.skip called from: #{caller[0]} ( #{message} )"
111
- end
230
+ # Update the Sprout::Executable registry so that subsequent
231
+ # requests for an executable return a fake one instead of
232
+ # the real one.
233
+ #
234
+ # @param exe [Symbol] The executable that will be sent to the load request (e.g. :fdb, :mxmlc, etc.).
235
+ # @param fake_name [String] The path to the fake executable that should be used.
236
+ #
237
+ # Note: Calling this method will set a mocha expectation
238
+ # that the Sprout::Executable.load method will be called during
239
+ # the test method run.
240
+ #
241
+ def insert_fake_executable fake
242
+ # Comment the following and install the flashsdk gem
243
+ # to run test against actual executables instead of fakes:
244
+ path_response = OpenStruct.new(:path => fake)
245
+ Sprout::Executable.expects(:load).returns path_response
112
246
  end
113
247
 
248
+ ##
249
+ # Create and/or return sprout/cache directory relative to the
250
+ # fixtures folder nearest the file that calls this method.
251
+ # @return [Dir] The path to the cache directory.
114
252
  def temp_cache
115
253
  dir = File.dirname(Sprout.file_from_caller(caller.first))
116
254
  @temp_cache ||= File.join(fixtures(dir), 'sprout', 'cache')
117
255
  end
118
256
 
257
+ ##
258
+ # Execute a block as each available Sprout::System, any code
259
+ # within this block that calls Sprout.current_user will
260
+ # receive the currently active Sprout::System.
261
+ #
262
+ # as_each_system do
263
+ # puts ">> Sprout.home: #{Sprout.home}"
264
+ # end
265
+ #
266
+ # This method is primarily used to ensure that we create
267
+ # system-appropriate paths and processes.
268
+ #
269
+ # NOTE: This process automatically calls Mocha::Mockery.instance.teardown
270
+ # after the yield. This means that any mocks that have been created will
271
+ # no longer be available after the provided block is complete.
272
+ #
273
+ # @return [Sprout::System::BaseSystem] The concrete class that was created.
274
+ # @yield [Sprout::System::BaseSystem] The concrete subclass of BaseSystem
275
+ #
119
276
  def as_each_system
120
277
  [
121
278
  Sprout::System::VistaSystem.new,
@@ -131,9 +288,19 @@ module SproutTestCase # :nodoc:[all]
131
288
  # Doing it anyway b/c we need to get Windows support in place...
132
289
  # TODO: Implement this feature without clobbering all stubs/mocks
133
290
  Mocha::Mockery.instance.teardown
291
+ sys
134
292
  end
135
293
  end
136
294
 
295
+ ##
296
+ # Execute a block as a UnixSystem.
297
+ #
298
+ # as_a_unix_system do
299
+ # puts ">> Sprout.home: #{Sprout.home}"
300
+ # end
301
+ #
302
+ # @return [Sprout::System::UnixSystem] The Sprout::System that was created.
303
+ # @yield [Sprout::System::UnixSystem] The current Sprout::System.
137
304
  def as_a_unix_system
138
305
  sys = Sprout::System::UnixSystem.new
139
306
  expectation = Sprout::System.stubs(:create).returns sys
@@ -142,8 +309,18 @@ module SproutTestCase # :nodoc:[all]
142
309
  # Doing it anyway b/c we need to get Windows support in place...
143
310
  # TODO: Implement this feature without clobbering all stubs/mocks
144
311
  #Mocha::Mockery.instance.teardown
312
+ sys
145
313
  end
146
314
 
315
+ ##
316
+ # Execute a block as a OSXSystem.
317
+ #
318
+ # as_a_mac_system do
319
+ # puts ">> Sprout.home: #{Sprout.home}"
320
+ # end
321
+ #
322
+ # @return [Sprout::System::OSXSystem] The Sprout::System that was created.
323
+ # @yield [Sprout::System::OSXSystem] The current Sprout::System.
147
324
  def as_a_mac_system
148
325
  sys = Sprout::System::OSXSystem.new
149
326
  Sprout::System.stubs(:create).returns sys
@@ -152,8 +329,18 @@ module SproutTestCase # :nodoc:[all]
152
329
  # Doing it anyway b/c we need to get Windows support in place...
153
330
  # TODO: Implement this feature without clobbering all stubs/mocks
154
331
  #Mocha::Mockery.instance.teardown
332
+ sys
155
333
  end
156
334
 
335
+ ##
336
+ # Execute a block as a WinSystem.
337
+ #
338
+ # as_a_windows_system do
339
+ # puts ">> Sprout.home: #{Sprout.home}"
340
+ # end
341
+ #
342
+ # @return [Sprout::System::WinSystem] The Sprout::System that was created.
343
+ # @yield [Sprout::System::WinSystem] The current Sprout::System.
157
344
  def as_a_windows_system
158
345
  sys = Sprout::System::WinSystem.new
159
346
  Sprout::System.stubs(:create).returns sys
@@ -162,8 +349,18 @@ module SproutTestCase # :nodoc:[all]
162
349
  # Doing it anyway b/c we need to get Windows support in place...
163
350
  # TODO: Implement this feature without clobbering all stubs/mocks
164
351
  #Mocha::Mockery.instance.teardown
352
+ sys
165
353
  end
166
354
 
355
+ ##
356
+ # Execute a block as a WinNixSystem.
357
+ #
358
+ # as_a_win_nix_system do
359
+ # puts ">> Sprout.home: #{Sprout.home}"
360
+ # end
361
+ #
362
+ # @return [Sprout::System::WinNixSystem] The Sprout::System that was created.
363
+ # @yield [Sprout::System::WinNixSystem] The current Sprout::System.
167
364
  def as_a_win_nix_system
168
365
  sys = Sprout::System::WinNixSystem.new
169
366
  Sprout::System.stubs(:create).returns sys
@@ -172,11 +369,13 @@ module SproutTestCase # :nodoc:[all]
172
369
  # Doing it anyway b/c we need to get Windows support in place...
173
370
  # TODO: Implement this feature without clobbering all stubs/mocks
174
371
  #Mocha::Mockery.instance.teardown
372
+ sys
175
373
  end
176
374
 
177
375
 
178
376
  private
179
377
 
378
+ ##
180
379
  # Find the nearest fixtures folder to the provided
181
380
  # path by checking each parent directory.
182
381
  def find_fixtures path
@@ -225,8 +424,9 @@ end
225
424
  # bare_setup - place this in setup method to create the app_root folder for each test
226
425
  # bare_teardown - place this in teardown method to destroy the TMP_ROOT or app_root folder after each test
227
426
 
228
-
229
427
  # Prevent log messages from interrupting the test output:
230
- Sprout::Log.debug = true
428
+ Sprout.stdout = Sprout.stdout_test
429
+ Sprout.stderr = Sprout.stderr_test
430
+
231
431
  #Sprout::ProgressBar.debug = true
232
432
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Sprout
3
3
  NAME = 'sprout'
4
- module VERSION #:nodoc:
4
+ module VERSION
5
5
  STRING = File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION').strip)
6
6
  MAJOR = STRING.split('.')[0]
7
7
  MINOR = STRING.split('.')[1]