spec_convertor 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ pkg
@@ -0,0 +1,7 @@
1
+ v0.5.1. Moved to github
2
+
3
+ v0.5. converting to echoe for gem-ing
4
+
5
+ v0.0.4. added history.txt to track things -- is there some way to do this easily and automatically via trac change logs? ; added conversion for ActionController::TestCase ; added conversion for ActiveSupport::TestCase ; move from rubyforge project spec-converter to thinkrelevance package spec_converter
6
+
7
+ v0.0.3. added more assert -> should conversions
@@ -0,0 +1,6 @@
1
+ README.rdoc
2
+ CHANGELOG
3
+ bin/spec_converter
4
+ lib/spec_converter.rb
5
+ test/spec_converter_test.rb
6
+ Manifest
@@ -0,0 +1,46 @@
1
+ = spec_converter
2
+
3
+ == DESCRIPTION
4
+ Simple converter to go from test-unit or dust style tests to test-spec (http://rubyforge.org/projects/test-spec) specs.
5
+
6
+ == FEATURES/PROBLEMS
7
+ This will change all files in place!! Make sure you are properly backed up and/or checked in before running.
8
+
9
+ == INSTALL
10
+ sudo gem install spec_converter
11
+
12
+ == USAGE
13
+ Assuming your project is at ~/work/project/:
14
+
15
+ cd ~/work/project
16
+ spec_converter
17
+
18
+ == URLS:
19
+ * test/spec: http://rubyforge.org/projects/test-spec
20
+ * git clone url: git://github.com/relevance/spec_converter.git
21
+ * rdoc: http://thinkrelevance.rubyforge.org/spec_converter/
22
+
23
+ == LICENSE:
24
+
25
+ (The MIT License)
26
+
27
+ Copyright (c) 2007-09 Relevance
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining
30
+ a copy of this software and associated documentation files (the
31
+ 'Software'), to deal in the Software without restriction, including
32
+ without limitation the rights to use, copy, modify, merge, publish,
33
+ distribute, sublicense, and/or sell copies of the Software, and to
34
+ permit persons to whom the Software is furnished to do so, subject to
35
+ the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be
38
+ included in all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
41
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
44
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
45
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "spec_convertor"
7
+ gem.summary = "Convert your tests to test/spec specs. See http://github.com/relevance/spec_converter/ for details."
8
+ gem.email = "rsanheim@gmail.com"
9
+ gem.homepage = "http://github.com/relevance/spec_converter"
10
+ gem.authors = ["Relevance"]
11
+ gem.add_development_dependency "mocha", ">= 0.9.0"
12
+ gem.add_development_dependency "micronaut", ">= 0.3.0"
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'micronaut/rake_task'
20
+ Micronaut::RakeTask.new(:examples) do |examples|
21
+ examples.pattern = 'examples/**/*_example.rb'
22
+ examples.ruby_opts << '-Ilib -Iexamples'
23
+ end
24
+
25
+ Micronaut::RakeTask.new(:rcov) do |examples|
26
+ examples.pattern = 'examples/**/*_example.rb'
27
+ examples.rcov_opts = '-Ilib -Iexamples'
28
+ examples.rcov = true
29
+ end
30
+
31
+ task :default => [:check_dependencies, :examples]
32
+ task :release => ['gemcutter:release']
33
+
34
+ begin
35
+ %w{sdoc sdoc-helpers rdiscount}.each { |name| gem name }
36
+ require 'sdoc_helpers'
37
+ rescue LoadError => ex
38
+ puts "sdoc support not enabled:"
39
+ puts ex.inspect
40
+ end
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "chatterbox #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.2
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spec_converter'
4
+
5
+ SpecConverter.start
@@ -0,0 +1,211 @@
1
+ require 'rubygems'
2
+ gem "micronaut"
3
+ require 'micronaut'
4
+ require 'mocha'
5
+ require 'tempfile'
6
+
7
+ require File.dirname(__FILE__) + '/../lib/spec_converter'
8
+
9
+ Micronaut.configure do |config|
10
+ config.mock_with :mocha
11
+ config.color_enabled = true
12
+ config.formatter = :documentation
13
+ end
14
+
15
+ describe "converting from test/spec old style to new style names" do
16
+ before do
17
+ @converter = SpecConverter.new
18
+ end
19
+
20
+ it "replaces spec context with describe" do
21
+ @converter.convert_line(%[context "should foo bar" do]).should == %[describe "should foo bar" do]
22
+ @converter.convert_line(%[ context "should foo bar" do]).should == %[ describe "should foo bar" do]
23
+ end
24
+
25
+ it "ignores unrelated uses of 'context'" do
26
+ @converter.convert_line(%[# here is a comment with context]).should == %[# here is a comment with context]
27
+ @converter.convert_line(%[contexts.each do |context|]).should == %[contexts.each do |context|]
28
+ end
29
+
30
+ it "replaces spec specify with it" do
31
+ @converter.convert_line(%[ specify "remember me saves the user" do]).should == %[ it "remember me saves the user" do]
32
+ end
33
+
34
+ it "ignores unrelated uses of 'specify'" do
35
+ @converter.convert_line(%[# I like to specify things]).should == %[# I like to specify things]
36
+ @converter.convert_line(%[ @user.should.specify.stuff]).should == %[ @user.should.specify.stuff]
37
+ end
38
+
39
+ end
40
+
41
+ describe "SpecConverter.start" do
42
+ it "creates an instance and calls convert" do
43
+ SpecConverter.expects(:new).returns(converter = stub)
44
+ converter.expects(:convert)
45
+ SpecConverter.start
46
+ end
47
+ end
48
+
49
+ describe "translate file overwrites old file with translated stuff" do
50
+ it "works" do
51
+ file = Tempfile.open("some_file.rb")
52
+ file << "Here is some stuff that is cool!"
53
+ file.close
54
+
55
+ converter = SpecConverter.new
56
+ converter.expects(:convert_line).with(anything).returns("Translated to be super awesome")
57
+ converter.translate_file(file.path)
58
+
59
+ File.open(file.path).read.should == "Translated to be super awesome"
60
+ end
61
+ end
62
+
63
+ describe "converting dust style to test/spec style" do
64
+ before do
65
+ @converter = SpecConverter.new
66
+ end
67
+
68
+ it "changes test...do to it...do" do
69
+ @converter.convert_line(%[test "should do something cool and fun!!" do]).should == %[it "should do something cool and fun!!" do]
70
+ end
71
+
72
+ it "ignores unrelated lines" do
73
+ @converter.convert_line(%[# test that this class can do something right]).should == %[# test that this class can do something right]
74
+ end
75
+
76
+ end
77
+
78
+ describe "converting ActionController tests to describe blocks" do
79
+ before do
80
+ @converter = SpecConverter.new
81
+ end
82
+
83
+ it "replaces class FooTest < ActionController::IntegrationTest with describe foo do" do
84
+ @converter.convert_line(%[class ResearchTest < ActionController::IntegrationTest]).should == %[describe "Research", ActionController::IntegrationTest do]
85
+ end
86
+
87
+ it "replaces class FooControllerTest < ActionController::TestCase with describe foo do" do
88
+ @converter.convert_line(%[class ResearchControllerTest < ActionController::TestCase]).should == %[describe "ResearchController", ActionController::TestCase do]
89
+ end
90
+
91
+ it "replaces class FooControllerTest < ActiveSupport::TestCase with describe foo do" do
92
+ @converter.convert_line(%[class ResearchControllerTest < ActiveSupport::TestCase]).should == %[describe "ResearchController", ActiveSupport::TestCase do]
93
+ end
94
+ end
95
+
96
+ describe "converting Test::Unit style to describe blocks" do
97
+ before do
98
+ @converter = SpecConverter.new
99
+ end
100
+
101
+ it "replaces class FooTest < Test::Unit::TestCase with describe foo do" do
102
+ @converter.convert_line(%[class ResearchTest < Test::Unit::TestCase]).should == %[describe "Research" do]
103
+ end
104
+
105
+ it "replaces class FooTest < Test::Unit::TestCase with silly whitespacing with describe foo do" do
106
+ @converter.convert_line(%[class ResearchTest < Test::Unit::TestCase]).should == %[describe "Research" do]
107
+ end
108
+
109
+ it "converts namespaced test unit classes" do
110
+ @converter.convert_line(%[class Admin::DashboardControllerTest < Test::Unit::TestCase]).should == %[describe "Admin::DashboardController" do]
111
+ end
112
+
113
+ it "ignores unrelated classes" do
114
+ @converter.convert_line(%[class Foo]).should == %[class Foo]
115
+ @converter.convert_line(%[class Bar < ActiveRecord::Base]).should == %[class Bar < ActiveRecord::Base]
116
+ end
117
+
118
+ end
119
+
120
+ describe "converting Test::Unit methods to it blocks" do
121
+ before do
122
+ @converter = SpecConverter.new
123
+ end
124
+
125
+ it "replaces def setup with before do" do
126
+ @converter.convert_line(%[def setup\n]).should == %[before do\n]
127
+ end
128
+
129
+ it "ignores method definitions that only start with setup" do
130
+ @converter.convert_line(%[def setup_my_object]).should == %[def setup_my_object]
131
+ end
132
+
133
+ it "replaces class def test_something? with it something? do" do
134
+ @converter.convert_line(%[def test_something?]).should == %[it "something?" do]
135
+ end
136
+
137
+ it "replaces class def test_something? with it something? do" do
138
+ @converter.convert_line(%[def test_something?]).should == %[it "something?" do]
139
+ end
140
+
141
+ it "replaces class def test_something with it something do" do
142
+ @converter.convert_line(%[def test_something]).should == %[it "something" do]
143
+ end
144
+
145
+ it "replaces class def test_something with it something do when it has leading whitespace" do
146
+ @converter.convert_line(%[ def test_something_here]).should == %[ it "something here" do]
147
+ end
148
+
149
+ it "ignores unrelated lines" do
150
+ @converter.convert_line(%[def foo]).should == %[def foo]
151
+ end
152
+
153
+ it "ignores unrelated lines with leading whitespace" do
154
+ @converter.convert_line(%[ def foo]).should == %[ def foo]
155
+ end
156
+
157
+ end
158
+
159
+ describe "converting assertions" do
160
+ before do
161
+ @converter = SpecConverter.new
162
+ end
163
+
164
+ it "replaces assert !foo to foo.should == false" do
165
+ @converter.convert_line(%[ assert !foo]).should == %[ foo.should.not == true]
166
+ end
167
+
168
+ it "replaces assert_equal y, x, bar to x.should == y" do
169
+ @converter.convert_line(%[ assert_equal "$1,490.00", x["price"]\n]).should == %[ x["price"].should == "$1,490.00"\n]
170
+ end
171
+
172
+ it "replaces assert foo to foo.should == true" do
173
+ @converter.convert_line(%[ assert foo]).should == %[ foo.should.not == nil]
174
+ end
175
+
176
+ it "replaces assert_nil foo to foo.should == nil" do
177
+ @converter.convert_line(%[ assert_nil foo]).should == %[ foo.should == nil]
178
+ end
179
+
180
+ it "replaces assert_true foo to foo.should == true" do
181
+ @converter.convert_line(%[ assert_true foo]).should == %[ foo.should == true]
182
+ end
183
+
184
+ it "replaces assert_false foo to foo.should == false" do
185
+ @converter.convert_line(%[ assert_false foo]).should == %[ foo.should == false]
186
+ end
187
+
188
+ it "replaces assert_not_nil foo to foo.should.not == nil" do
189
+ @converter.convert_line(%[ assert_not_nil foo]).should == %[ foo.should.not == nil]
190
+ end
191
+ it "replaces assert foo > 20 to foo.should > 20" do
192
+ @converter.convert_line(%[ assert foo > 20]).should == %[ foo.should > 20]
193
+ end
194
+ end
195
+
196
+ describe "converting things in batch" do
197
+ before do
198
+ @converter = SpecConverter.new
199
+ end
200
+
201
+ it "takes convert all test files in the test subdirectory" do
202
+ @convert.expects(:convert_line).never
203
+ files = %w[test/foo_test.rb test/models/another_test.rb]
204
+ files.each do |file|
205
+ @converter.expects(:translate_file).with(file)
206
+ end
207
+ Dir.expects(:glob).with(anything()).returns(files)
208
+ File.stubs(:directory?).with("test").returns(true)
209
+ @converter.convert
210
+ end
211
+ end
@@ -0,0 +1,74 @@
1
+ # Simple converter to go to test/spec style
2
+ # This will change all files in place, so make sure you are properly backed up and/or committed to SVN!
3
+ class SpecConverter
4
+ VERSION = "0.0.4"
5
+
6
+ def self.start
7
+ spec_converter = SpecConverter.new
8
+ spec_converter.convert
9
+ end
10
+
11
+ # Convert tests from old spec style to new style -- assumes you are in your project root and globs all tests
12
+ # in your test directory.
13
+ def convert
14
+ raise "No test diretory - you must run this script from your project root, which should also contain a test directory." unless File.directory?("test")
15
+ tests = Dir.glob('test/**/*_test.rb')
16
+ tests.each do |test_file|
17
+ translate_file(test_file)
18
+ end
19
+ end
20
+
21
+ def translate_file(file)
22
+ translation = ""
23
+ File.open(file) do |io|
24
+ io.each_line do |line|
25
+ translation << convert_line(line)
26
+ end
27
+ end
28
+ File.open(file, "w") do |io|
29
+ io.write(translation)
30
+ end
31
+ end
32
+
33
+ def convert_line(line)
34
+ convert_rspec_old_style_names(line)
35
+ convert_dust_style(line)
36
+ convert_test_unit_class_name(line)
37
+ convert_test_unit_methods(line)
38
+ convert_def_setup(line)
39
+ convert_assert(line)
40
+ line
41
+ end
42
+
43
+ private
44
+
45
+ def convert_def_setup(line)
46
+ line.gsub!(/(^\s*)def setup(\s*)$/, '\1before do\2')
47
+ end
48
+
49
+ def convert_rspec_old_style_names(line)
50
+ line.gsub!(/(^\s*)context(\s.*do)/, '\1describe\2')
51
+ line.gsub!(/(^\s*)specify(\s.*do)/, '\1it\2')
52
+ end
53
+
54
+ def convert_test_unit_class_name(line)
55
+ line.gsub!(/^class\s*([\w:]+)Test\s*<\s*Test::Unit::TestCase/, 'describe "\1" do')
56
+ line.gsub!(/^class\s*([\w:]+)Test\s*<\s*(ActiveSupport|ActionController)::(IntegrationTest|TestCase)/, 'describe "\1", \2::\3 do')
57
+ end
58
+
59
+ def convert_test_unit_methods(line)
60
+ line.gsub!(/(^\s*)def\s*test_([\w_!?,$]+)/) { %{#{$1}it "#{$2.split('_').join(' ')}" do} }
61
+ end
62
+
63
+ def convert_dust_style(line)
64
+ line.gsub!(/(^\s*)test(\s.*do)/, '\1it\2')
65
+ end
66
+
67
+ def convert_assert(line)
68
+ line.gsub!(/(^\s*)assert\s+([^\s]*)\s*([<=>~]+)\s*(.*)$/, '\1\2.should \3 \4' )
69
+ line.gsub!(/(^\s*)assert\s+\!(.*)$/, '\1\2.should.not == true' )
70
+ line.gsub!(/(^\s*)assert(_not_nil){0,1}\s+(.*)$/, '\1\3.should.not == nil' )
71
+ line.gsub!(/(^\s*)assert_(nil|true|false)\s+(.*)$/, '\1\3.should == \2' )
72
+ line.gsub!(/(^\s*)assert_equal\s+("[^"]+"|[^,]+),\s*("[^"]+"|[^,\n]+)$/, '\1\3.should == \2' )
73
+ end
74
+ end
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{spec_convertor}
8
+ s.version = "0.5.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Relevance"]
12
+ s.date = %q{2009-10-09}
13
+ s.default_executable = %q{spec_converter}
14
+ s.email = %q{rsanheim@gmail.com}
15
+ s.executables = ["spec_converter"]
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "CHANGELOG",
22
+ "Manifest",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/spec_converter",
27
+ "examples/spec_converter_example.rb",
28
+ "lib/spec_converter.rb",
29
+ "spec_convertor.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/relevance/spec_converter}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Convert your tests to test/spec specs. See http://github.com/relevance/spec_converter/ for details.}
36
+ s.test_files = [
37
+ "examples/spec_converter_example.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<mocha>, [">= 0.9.0"])
46
+ s.add_development_dependency(%q<micronaut>, [">= 0.3.0"])
47
+ else
48
+ s.add_dependency(%q<mocha>, [">= 0.9.0"])
49
+ s.add_dependency(%q<micronaut>, [">= 0.3.0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<mocha>, [">= 0.9.0"])
53
+ s.add_dependency(%q<micronaut>, [">= 0.3.0"])
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spec_convertor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Relevance
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-09 00:00:00 -04:00
13
+ default_executable: spec_converter
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mocha
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: micronaut
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ version:
35
+ description:
36
+ email: rsanheim@gmail.com
37
+ executables:
38
+ - spec_converter
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - .gitignore
45
+ - CHANGELOG
46
+ - Manifest
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - bin/spec_converter
51
+ - examples/spec_converter_example.rb
52
+ - lib/spec_converter.rb
53
+ - spec_convertor.gemspec
54
+ has_rdoc: true
55
+ homepage: http://github.com/relevance/spec_converter
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Convert your tests to test/spec specs. See http://github.com/relevance/spec_converter/ for details.
82
+ test_files:
83
+ - examples/spec_converter_example.rb