rspec 0.5.8 → 0.5.9

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.
data/CHANGES CHANGED
@@ -1,5 +1,12 @@
1
1
  = RSpec Changelog
2
2
 
3
+ == Version 0.5.9
4
+ This release improves test2spec by allowing more control over the output
5
+
6
+ * Added --template option to test2spec, which allows for custom output driven by ERB
7
+ * Added --quiet option to test2spec
8
+ * Removed unnecessary dependency on RubyToC
9
+
3
10
  == Version 0.5.8
4
11
  This release features a new Test::Unit to RSpec translation tool.
5
12
  Also note that the RubyGem of the previous release (0.5.7) was corrupt.
data/README CHANGED
@@ -1 +1,17 @@
1
- See http://rspec.rubyforge.org for detailed documentation.
1
+ In order to run RSpec's tests and generate the website, you must have RubyGems.
2
+ Then you must install the following gems:
3
+
4
+ * rake
5
+ * rcov
6
+ * RubyInline
7
+ * ParseTree (Ignore the message: test/test_parse_tree.rb:190:38: ':' not followed by identified or operator)
8
+ * webgen
9
+ * RedCloth
10
+ * syntax
11
+
12
+ Note that RSpec itself - once built - doesn't have any dependencies outside the Ruby core
13
+ and stdlib - with a few exceptions:
14
+ * test2spec uses RubyInline, RubyToC and ParseTree
15
+ * The spectask needs rcov if rcov is enabled.
16
+
17
+ See http://rspec.rubyforge.org for further documentation.
data/Rakefile CHANGED
@@ -45,8 +45,13 @@ Rcov::RcovTask.new do |t|
45
45
  t.rcov_opts = []
46
46
  end
47
47
 
48
+ desc 'Translate our own tests to specs'
49
+ task :test2spec do
50
+ `bin/test2spec --template spec/test2spec.erb --specdir spec test`
51
+ end
52
+
48
53
  desc 'Generate HTML documentation'
49
- task :doc do
54
+ task :doc => :test2spec do
50
55
  sh %{pushd doc; webgen; popd}
51
56
  end
52
57
 
@@ -114,6 +119,7 @@ end
114
119
 
115
120
  task :clobber do
116
121
  rm_rf 'doc/output'
122
+ rm_rf 'spec/spec'
117
123
  end
118
124
 
119
125
  task :release => [:clobber, :verify_committed, :verify_user, :verify_password, :test, :publish_packages, :tag, :publish_website, :publish_news]
data/bin/test2spec CHANGED
@@ -25,6 +25,18 @@ opts = OptionParser.new do |opts|
25
25
  $test2spec_options[:specdir] = dir
26
26
  end
27
27
 
28
+ opts.on("-t", "--template FILE",
29
+ "ERB template that will be used to create each file. The template",
30
+ "has access toi the following variables:",
31
+ " translation : the translated source code",
32
+ " depth : the directory depth of the file to be written",
33
+ " relative_path : the relative name of the file to be written",
34
+ "Example:",
35
+ "<%= @translation %>"
36
+ ) do |file|
37
+ $test2spec_options[:template] = file
38
+ end
39
+
28
40
  opts.on("-c", "--chmod MODIFIERS", Integer, "Change file modifiers on written files (POSIX only)") do |mods|
29
41
  $test2spec_options[:chmod] = mods
30
42
  end
@@ -37,13 +49,17 @@ opts = OptionParser.new do |opts|
37
49
  $test2spec_options[:collision] = :force
38
50
  end
39
51
 
52
+ opts.on("-q", "--quiet", "Don't print anything to stdout") do
53
+ $test2spec_options[:quiet] = true
54
+ end
55
+
40
56
  opts.on("-v", "--version", "Show version") do
41
57
  puts "test2spec #{Spec::VERSION::DESCRIPTION}"
42
58
  exit
43
59
  end
44
60
 
45
61
  opts.on("-d", "--dry-run", "Don't write anything - just verify that translation works") do
46
- options.dry_run = true
62
+ $test2spec_options[:dry_run] = true
47
63
  end
48
64
 
49
65
  opts.on_tail("-h", "--help", "You're looking at it") do
@@ -7,7 +7,7 @@ h2. Test::Unit migration
7
7
  RSpec's test2spec command line tool translates existing Test::Unit classes to RSpec.
8
8
 
9
9
  Before you can use test2spec you must gem install ParseTree and RubyInline.
10
- RubyInline only work on systems that have a C compiler - i.e. most anything except Windows.
10
+ RubyInline only works on systems that have a C compiler - i.e. most anything except Windows.
11
11
 
12
12
  If you're stuck on Windows, ask a friend who has a POSIX system to translate your specs.
13
13
  Once translated they can run on any Ruby platform (including Windows). After all, it's
@@ -23,17 +23,24 @@ test2spec --help
23
23
  A typical invocation might look like this:
24
24
 
25
25
  <pre>
26
- test2spec --specdir spec test
26
+ test2spec --template spec/test2spec.erb --specdir spec test
27
27
  </pre>
28
28
 
29
- h2. Sample output
29
+ Where spec/test2spec.erb contains the following:
30
+
31
+ <pre>
32
+ {includeFile: {filename: ../../../spec/test2spec.erb, processOutput: false}}
33
+ </pre>
34
+
35
+
36
+ h2. Sample translation
30
37
 
31
38
  <notextile>
32
39
  <table>
33
40
  <thead>
34
41
  <tr>
35
- <td>Test::Unit</td>
36
- <td>RSpec (translated by test2spec)</td>
42
+ <td>Test::Unit (input)</td>
43
+ <td>RSpec (output)</td>
37
44
  </tr>
38
45
  </thead>
39
46
  <tbody>
@@ -42,13 +49,22 @@ h2. Sample output
42
49
  <ruby file="../test/spec/tool/test_unit_api_test.rb"/>
43
50
  </td>
44
51
  <td>
45
- <ruby file="../test/spec/tool/test_unit_api_spec.rb"/>
52
+ <ruby file="../spec/spec/tool/test_unit_api_spec.rb"/>
46
53
  </td>
47
54
  </tr>
48
55
  </tbody>
49
56
  </table>
50
57
  </notextile>
51
58
 
59
+ h2. What's translated?
60
+
61
+ test2spec only translates classes that extend from Test::Unit - and their methods. It will not bring over any
62
+ code that isn't inside a Test::Unit class. This means that require statements at the top of your file, any other
63
+ classes in the same file as the test class etc *will not be translated*.
64
+
65
+ So, there is a fair chance that you will have to do some manual editing after test2spec has run. We're only
66
+ aiming to get most of the translation job done for you - not all of it.
67
+
52
68
  h2. Troubleshooting
53
69
 
54
70
  In some cases, test2spec will not be able to translate a test class. In that case, please submit a bug report
@@ -1,10 +1,12 @@
1
1
  # Taken from http://dark.fhtr.org/ruby2ruby.rb
2
2
 
3
3
  require 'rubygems'
4
- require 'parse_tree'
5
- require 'support'
6
- require 'sexp_processor'
7
-
4
+ begin
5
+ require 'parse_tree'
6
+ require 'sexp_processor'
7
+ rescue LoadError
8
+ $stderr.puts "You must gem install ParseTree (and RubyInline)"
9
+ end
8
10
 
9
11
  class RubySource < String
10
12
 
@@ -72,7 +74,6 @@ class RubyToRuby < SexpProcessor
72
74
 
73
75
  def initialize
74
76
  super
75
- @env = Environment.new
76
77
  @indent = " "
77
78
  self.auto_shift_type = true
78
79
  self.strict = true
@@ -1,5 +1,6 @@
1
1
  require 'spec/tool/test_unit_translator'
2
2
  require 'fileutils'
3
+ require 'erb'
3
4
 
4
5
  module Spec
5
6
  module Tool
@@ -12,7 +13,7 @@ module Spec
12
13
  end
13
14
 
14
15
  def initialize(suite)
15
- puts "Writing translated specs to #{$test2spec_options[:specdir]}"
16
+ log "Writing translated specs to #{$test2spec_options[:specdir]}"
16
17
  translator = TestUnitTranslator.new
17
18
  ObjectSpace.each_object(Class) do |klass|
18
19
  if klass < ::Test::Unit::TestCase
@@ -21,14 +22,17 @@ module Spec
21
22
 
22
23
  unless $test2spec_options[:dry_run]
23
24
  relative_path = underscore(klass.name)
25
+ template = $test2spec_options[:template] ? IO.read($test2spec_options[:template]) : nil
26
+ source = render(translation, relative_path, template)
27
+
24
28
  relative_path.gsub! /_test$/, "_spec"
25
29
  relative_path += ".rb"
26
- write(translation, relative_path)
30
+ write(source, relative_path)
27
31
  else
28
- puts "Successfully translated #{klass}"
32
+ log "Successfully translated #{klass}"
29
33
  end
30
34
  rescue SexpProcessorError => e
31
- puts "Failed to translate #{klass}"
35
+ log "Failed to translate #{klass}"
32
36
  end
33
37
  end
34
38
  end
@@ -40,6 +44,24 @@ module Spec
40
44
  end
41
45
 
42
46
  private
47
+
48
+ def render(translation, relative_path, template)
49
+ unless template.nil?
50
+ depth = relative_path.split('/').length-1
51
+ erb = ERB.new(template)
52
+ erb.result(binding)
53
+ else
54
+ translation
55
+ end
56
+ end
57
+
58
+ def log(msg)
59
+ puts msg unless quiet?
60
+ end
61
+
62
+ def quiet?
63
+ $test2spec_options[:quiet] == true
64
+ end
43
65
 
44
66
  def destination_path(relative_destination)
45
67
  File.join($test2spec_options[:specdir], relative_destination)
@@ -49,7 +71,7 @@ module Spec
49
71
  destination = destination_path(relative_destination)
50
72
  destination_exists = File.exists?(destination)
51
73
  if destination_exists and identical?(source, destination)
52
- return puts("Identical : #{relative_destination}")
74
+ return log("Identical : #{relative_destination}")
53
75
  end
54
76
 
55
77
  if destination_exists
@@ -57,21 +79,19 @@ module Spec
57
79
  when :ask then force_file_collision?(relative_destination)
58
80
  when :force then :force
59
81
  when :skip then :skip
60
- else raise "Invalid collision option: #{$test2spec_options[:collision].inspect}"
61
82
  end
62
83
 
63
84
  case choice
64
- when :force then puts("Forcing : #{relative_destination}")
65
- when :skip then return(puts("Skipping : #{relative_destination}"))
66
- else raise "Invalid collision choice: #{choice}.inspect"
85
+ when :force then log("Forcing : #{relative_destination}")
86
+ when :skip then return(log("Skipping : #{relative_destination}"))
67
87
  end
68
88
  else
69
89
  dir = File.dirname(destination)
70
90
  unless File.directory?(dir)
71
- puts "Creating : #{dir}"
91
+ log "Creating : #{dir}"
72
92
  mkdir_p dir
73
93
  end
74
- puts "Creating : #{destination}"
94
+ log "Creating : #{destination}"
75
95
  end
76
96
 
77
97
  File.open(destination, 'w') do |df|
@@ -96,10 +116,10 @@ module Spec
96
116
  case $stdin.gets
97
117
  when /a/i
98
118
  $test2spec_options[:collision] = :force
99
- $stdout.puts "Forcing ALL"
119
+ log "Forcing ALL"
100
120
  :force
101
121
  when /q/i
102
- $stdout.puts "Quitting"
122
+ puts "Quitting"
103
123
  raise SystemExit
104
124
  when /n/i then :skip
105
125
  else :force
data/lib/spec/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 8
6
+ TINY = 9
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.8
6
+ version: 0.5.9
7
7
  date: 2006-06-09 00:00:00 -05:00
8
- summary: RSpec-0.5.8 - BDD for Ruby http://rspec.rubyforge.org/
8
+ summary: RSpec-0.5.9 - BDD for Ruby http://rspec.rubyforge.org/
9
9
  require_paths:
10
10
  - lib
11
11
  email: rspec-devel@rubyforge.org