spec-converter 0.0.1
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/Manifest.txt +6 -0
- data/README.txt +47 -0
- data/Rakefile +56 -0
- data/bin/spec_converter +5 -0
- data/lib/spec_converter.rb +60 -0
- data/test/spec_converter_test.rb +146 -0
- metadata +68 -0
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,47 @@
|
|
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 committed to SVN 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
|
+
* trac: http://opensource.thinkrelevance.com/wiki/spec-converter
|
21
|
+
* svn trunk: https://opensource.thinkrelevance.com/svn/spec_converter/trunk
|
22
|
+
* rdoc: http://spec-converter.rubyforge.org/rdoc
|
23
|
+
|
24
|
+
== LICENSE:
|
25
|
+
|
26
|
+
(The MIT License)
|
27
|
+
|
28
|
+
Copyright (c) 2007 Relevance
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require 'lib/spec_converter'
|
6
|
+
require 'rcov/rcovtask'
|
7
|
+
|
8
|
+
Hoe.new('SpecConverter', SpecConverter::VERSION) do |p|
|
9
|
+
p.rubyforge_name = "spec-converter"
|
10
|
+
p.name = 'spec-converter'
|
11
|
+
p.remote_rdoc_dir = 'rdoc'
|
12
|
+
p.summary = "Convert your tests to test/spec specs"
|
13
|
+
p.author = "Relevance"
|
14
|
+
p.email = "opensource@thinkrelevance.com"
|
15
|
+
p.url = "http://opensource.thinkrelevance.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Default: run unit tests.'
|
19
|
+
task :default => :test
|
20
|
+
|
21
|
+
desc 'Default for CruiseControl'
|
22
|
+
task :cruise => ['test', 'test:flog']
|
23
|
+
|
24
|
+
desc 'Test for flog failure'
|
25
|
+
namespace :test do
|
26
|
+
task :flog do
|
27
|
+
threshold = (ENV['FLOG_THRESHOLD'] || 120).to_i
|
28
|
+
dirs = %w(lib tasks test)
|
29
|
+
result = IO.popen("flog #{dirs.join(' ')} 2>/dev/null | grep \"(\" | grep -v \"main#none\" | head -n 1").readlines.join('')
|
30
|
+
result =~ /\((.*)\)/
|
31
|
+
flog = $1.to_i
|
32
|
+
result =~ /^(.*):/
|
33
|
+
method = $1
|
34
|
+
if flog > threshold
|
35
|
+
raise "FLOG failed for #{method} with score of #{flog} (threshold is #{threshold})."
|
36
|
+
end
|
37
|
+
puts "FLOG passed, with highest score being #{flog} for #{method}."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Test the relevance_tools plugin.'
|
42
|
+
Rake::TestTask.new(:test) do |t|
|
43
|
+
t.libs << 'lib'
|
44
|
+
t.pattern = 'test/**/*_test.rb'
|
45
|
+
t.verbose = true
|
46
|
+
end
|
47
|
+
|
48
|
+
Rcov::RcovTask.new("rcov") do |t|
|
49
|
+
rcov_output = "tmp/coverage"
|
50
|
+
FileUtils.mkdir_p rcov_output unless File.exist? rcov_output
|
51
|
+
t.libs << "lib"
|
52
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
53
|
+
t.output_dir = "#{rcov_output}/"
|
54
|
+
t.verbose = true
|
55
|
+
t.rcov_opts = ["-x", "^/Library", "--sort coverage"]
|
56
|
+
end
|
data/bin/spec_converter
ADDED
@@ -0,0 +1,60 @@
|
|
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.1"
|
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
|
+
line
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def convert_rspec_old_style_names(line)
|
44
|
+
line.gsub!(/(^\s*)context(\s.*do)/, '\1describe\2')
|
45
|
+
line.gsub!(/(^\s*)specify(\s.*do)/, '\1it\2')
|
46
|
+
end
|
47
|
+
|
48
|
+
def convert_test_unit_class_name(line)
|
49
|
+
line.gsub!(/^class\s*([\w:]+)Test\s*<\s*Test::Unit::TestCase/, 'describe "\1" do')
|
50
|
+
line.gsub!(/^class\s*([\w:]+)Test\s*<\s*ActionController::IntegrationTest/, 'describe "\1", ActionController::IntegrationTest do')
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert_test_unit_methods(line)
|
54
|
+
line.gsub!(/(^\s*)def\s*test_([\w_!?,$]+)/) { %{#{$1}it "#{$2.split('_').join(' ')}" do} }
|
55
|
+
end
|
56
|
+
|
57
|
+
def convert_dust_style(line)
|
58
|
+
line.gsub!(/(^\s*)test(\s.*do)/, '\1it\2')
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/spec'
|
3
|
+
require 'mocha'
|
4
|
+
require 'tempfile'
|
5
|
+
require File.dirname(__FILE__) + '/../lib/spec_converter'
|
6
|
+
|
7
|
+
describe "converting from test/spec old style to new style names" do
|
8
|
+
setup do
|
9
|
+
@converter = SpecConverter.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "replaces spec context with describe" do
|
13
|
+
@converter.convert_line(%[context "should foo bar" do]).should == %[describe "should foo bar" do]
|
14
|
+
@converter.convert_line(%[ context "should foo bar" do]).should == %[ describe "should foo bar" do]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "ignores unrelated uses of 'context'" do
|
18
|
+
@converter.convert_line(%[# here is a comment with context]).should == %[# here is a comment with context]
|
19
|
+
@converter.convert_line(%[contexts.each do |context|]).should == %[contexts.each do |context|]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "replaces spec specify with it" do
|
23
|
+
@converter.convert_line(%[ specify "remember me saves the user" do]).should == %[ it "remember me saves the user" do]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "ignores unrelated uses of 'specify'" do
|
27
|
+
@converter.convert_line(%[# I like to specify things]).should == %[# I like to specify things]
|
28
|
+
@converter.convert_line(%[ @user.should.specify.stuff]).should == %[ @user.should.specify.stuff]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "SpecConverter.start" do
|
34
|
+
it "creates an instance and calls convert" do
|
35
|
+
SpecConverter.expects(:new).returns(converter = stub)
|
36
|
+
converter.expects(:convert)
|
37
|
+
SpecConverter.start
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "translate file overwrites old file with translated stuff" do
|
42
|
+
it "works" do
|
43
|
+
file = Tempfile.open("some_file.rb")
|
44
|
+
file << "Here is some stuff that is cool!"
|
45
|
+
file.close
|
46
|
+
|
47
|
+
converter = SpecConverter.new
|
48
|
+
converter.expects(:convert_line).with(anything).returns("Translated to be super awesome")
|
49
|
+
converter.translate_file(file.path)
|
50
|
+
|
51
|
+
File.open(file.path).read.should == "Translated to be super awesome"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "converting dust style to test/spec style" do
|
56
|
+
setup do
|
57
|
+
@converter = SpecConverter.new
|
58
|
+
end
|
59
|
+
|
60
|
+
it "changes test...do to it...do" do
|
61
|
+
@converter.convert_line(%[test "should do something cool and fun!!" do]).should == %[it "should do something cool and fun!!" do]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "ignores unrelated lines" do
|
65
|
+
@converter.convert_line(%[# test that this class can do something right]).should == %[# test that this class can do something right]
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "converting ActionController::IntegrationTest style to describe blocks" do
|
71
|
+
setup do
|
72
|
+
@converter = SpecConverter.new
|
73
|
+
end
|
74
|
+
|
75
|
+
it "replaces class FooTest < ActionController::IntegrationTest with describe foo do" do
|
76
|
+
@converter.convert_line(%[class ResearchTest < ActionController::IntegrationTest]).should == %[describe "Research", ActionController::IntegrationTest do]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "converting Test::Unit style to describe blocks" do
|
81
|
+
setup do
|
82
|
+
@converter = SpecConverter.new
|
83
|
+
end
|
84
|
+
|
85
|
+
it "replaces class FooTest < Test::Unit::TestCase with describe foo do" do
|
86
|
+
@converter.convert_line(%[class ResearchTest < Test::Unit::TestCase]).should == %[describe "Research" do]
|
87
|
+
end
|
88
|
+
|
89
|
+
it "replaces class FooTest < Test::Unit::TestCase with silly whitespacing with describe foo do" do
|
90
|
+
@converter.convert_line(%[class ResearchTest < Test::Unit::TestCase]).should == %[describe "Research" do]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "converts namespaced test unit classes" do
|
94
|
+
@converter.convert_line(%[class Admin::DashboardControllerTest < Test::Unit::TestCase]).should == %[describe "Admin::DashboardController" do]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "ignores unrelated classes" do
|
98
|
+
@converter.convert_line(%[class Foo]).should == %[class Foo]
|
99
|
+
@converter.convert_line(%[class Bar < ActiveRecord::Base]).should == %[class Bar < ActiveRecord::Base]
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "converting Test::Unit methods to it blocks" do
|
105
|
+
setup do
|
106
|
+
@converter = SpecConverter.new
|
107
|
+
end
|
108
|
+
|
109
|
+
it "replaces class def test_something? with it something? do" do
|
110
|
+
@converter.convert_line(%[def test_something?]).should == %[it "something?" do]
|
111
|
+
end
|
112
|
+
|
113
|
+
it "replaces class def test_something with it something do" do
|
114
|
+
@converter.convert_line(%[def test_something]).should == %[it "something" do]
|
115
|
+
end
|
116
|
+
|
117
|
+
it "replaces class def test_something with it something do when it has leading whitespace" do
|
118
|
+
@converter.convert_line(%[ def test_something_here]).should == %[ it "something here" do]
|
119
|
+
end
|
120
|
+
|
121
|
+
it "ignores unrelated lines" do
|
122
|
+
@converter.convert_line(%[def foo]).should == %[def foo]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "ignores unrelated lines with leading whitespace" do
|
126
|
+
@converter.convert_line(%[ def foo]).should == %[ def foo]
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "converting things in batch" do
|
132
|
+
setup do
|
133
|
+
@converter = SpecConverter.new
|
134
|
+
end
|
135
|
+
|
136
|
+
it "takes convert all test files in the test subdirectory" do
|
137
|
+
@convert.expects(:convert_line).never
|
138
|
+
files = %w[test/foo_test.rb test/models/another_test.rb]
|
139
|
+
files.each do |file|
|
140
|
+
@converter.expects(:translate_file).with(file)
|
141
|
+
end
|
142
|
+
Dir.expects(:glob).with(anything()).returns(files)
|
143
|
+
File.stubs(:directory?).with("test").returns(true)
|
144
|
+
@converter.convert
|
145
|
+
end
|
146
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spec-converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Relevance
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-04 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
description: The author was too lazy to write a description
|
25
|
+
email: opensource@thinkrelevance.com
|
26
|
+
executables:
|
27
|
+
- spec_converter
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- Manifest.txt
|
32
|
+
- README.txt
|
33
|
+
files:
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- bin/spec_converter
|
38
|
+
- lib/spec_converter.rb
|
39
|
+
- test/spec_converter_test.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://opensource.thinkrelevance.com
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.txt
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: spec-converter
|
63
|
+
rubygems_version: 1.0.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: Convert your tests to test/spec specs
|
67
|
+
test_files: []
|
68
|
+
|