rspecify 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +16 -11
- data/README.rdoc +2 -0
- data/Rakefile +23 -0
- data/lib/rspecify/transformers/test_class_and_methods.rb +25 -19
- data/lib/rspecify/transformers/test_unit_assertions.rb +16 -16
- data/lib/rspecify/version.rb +1 -1
- data/spec/rspecify/transformers/test_class_and_methods_spec.rb +84 -0
- data/spec/rspecify/transformers/test_unit_assertions_spec.rb +7 -7
- metadata +29 -17
data/Gemfile.lock
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspecify (0.1.
|
5
|
-
activesupport (~> 3.0
|
4
|
+
rspecify (0.1.5)
|
5
|
+
activesupport (~> 3.0)
|
6
6
|
i18n (~> 0.6.0)
|
7
7
|
ruby_parser (~> 2.3.1)
|
8
|
-
ruby_scribe (~> 0.1.
|
9
|
-
ruby_transform (~> 0.1.
|
8
|
+
ruby_scribe (~> 0.1.4)
|
9
|
+
ruby_transform (~> 0.1.4)
|
10
10
|
thor (~> 0.13)
|
11
11
|
|
12
12
|
GEM
|
13
13
|
remote: http://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (3.
|
15
|
+
activesupport (3.2.3)
|
16
|
+
i18n (~> 0.6)
|
17
|
+
multi_json (~> 1.0)
|
16
18
|
diff-lcs (1.1.3)
|
17
19
|
i18n (0.6.0)
|
20
|
+
multi_json (1.2.0)
|
21
|
+
rake (0.9.2.2)
|
18
22
|
rspec (2.6.0)
|
19
23
|
rspec-core (~> 2.6.0)
|
20
24
|
rspec-expectations (~> 2.6.0)
|
@@ -25,23 +29,24 @@ GEM
|
|
25
29
|
rspec-mocks (2.6.0)
|
26
30
|
ruby_parser (2.3.1)
|
27
31
|
sexp_processor (~> 3.0)
|
28
|
-
ruby_scribe (0.1.
|
29
|
-
activesupport (~> 3.0
|
32
|
+
ruby_scribe (0.1.5)
|
33
|
+
activesupport (~> 3.0)
|
30
34
|
i18n (~> 0.6.0)
|
31
35
|
ruby_parser (~> 2.3.1)
|
32
36
|
thor (~> 0.13)
|
33
|
-
ruby_transform (0.1.
|
34
|
-
activesupport (~> 3.0
|
37
|
+
ruby_transform (0.1.4)
|
38
|
+
activesupport (~> 3.0)
|
35
39
|
i18n (~> 0.6.0)
|
36
40
|
ruby_parser (~> 2.3.1)
|
37
|
-
ruby_scribe (~> 0.1.
|
41
|
+
ruby_scribe (~> 0.1.4)
|
38
42
|
thor (~> 0.13)
|
39
|
-
sexp_processor (3.0
|
43
|
+
sexp_processor (3.1.0)
|
40
44
|
thor (0.14.6)
|
41
45
|
|
42
46
|
PLATFORMS
|
43
47
|
ruby
|
44
48
|
|
45
49
|
DEPENDENCIES
|
50
|
+
rake
|
46
51
|
rspec (~> 2.0)
|
47
52
|
rspecify!
|
data/README.rdoc
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
{<img src="https://secure.travis-ci.org/rubiety/rspecify.png?branch=master" alt="Build Status" />}[http://travis-ci.org/rubiety/rspecify]
|
2
|
+
|
1
3
|
= RSpecify
|
2
4
|
|
3
5
|
Converting your tests from Test::Unit to RSpec is a drag when done by hand. This utility intelligently converts them to get you (hopefully) 90% of the way there.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
desc 'Default: run unit tests.'
|
10
|
+
task :default => [:clean, :test]
|
11
|
+
|
12
|
+
desc "Run Specs"
|
13
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
14
|
+
end
|
15
|
+
|
16
|
+
task :test => :spec
|
17
|
+
|
18
|
+
desc "Clean up files."
|
19
|
+
task :clean do |t|
|
20
|
+
FileUtils.rm_rf "tmp"
|
21
|
+
Dir.glob("spec/db/*.sqlite3").each {|f| FileUtils.rm f }
|
22
|
+
Dir.glob("validates_lengths_from_database-*.gem").each {|f| FileUtils.rm f }
|
23
|
+
end
|
@@ -20,31 +20,37 @@ module RSpecify
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def transform_test_class(e)
|
23
|
+
name = e.body[0].to_s.gsub /Test$/, ""
|
24
|
+
class_body = e.body[2].body[0]
|
25
|
+
if class_body.kind == :block
|
26
|
+
new_block = Sexp.from_array([:block] + class_body.body.map {|e| transform_test_class_method_definition e })
|
27
|
+
else
|
28
|
+
new_block = transform_test_class_method_definition class_body
|
29
|
+
end
|
23
30
|
s(:iter,
|
24
|
-
s(:call, nil, :describe, s(:arglist, s(:const,
|
31
|
+
s(:call, nil, :describe, s(:arglist, s(:const, name.to_sym))),
|
25
32
|
nil,
|
26
|
-
|
33
|
+
new_block
|
27
34
|
)
|
28
35
|
end
|
29
36
|
|
30
|
-
def transform_test_class_method_definitions(e)
|
31
|
-
Sexp.from_array([e.kind] + e.body.map do |child|
|
32
|
-
if child.kind == :defn && child.body[0].to_s.starts_with?("test_") && child.body[1].body.empty?
|
33
|
-
transform_test_class_method_definition(child)
|
34
|
-
else
|
35
|
-
child
|
36
|
-
end
|
37
|
-
end)
|
38
|
-
end
|
39
|
-
|
40
37
|
def transform_test_class_method_definition(e)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
s(:
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
if e.kind == :defn && e.body[0].to_s.starts_with?("test_") && e.body[1].body.empty?
|
39
|
+
test_name = e.body[0].to_s.gsub(/^test_/, "").gsub("_", " ")
|
40
|
+
|
41
|
+
s(:iter,
|
42
|
+
s(:call, nil, :it, s(:arglist, s(:str, test_name))),
|
43
|
+
nil,
|
44
|
+
e.body[2].body[0]
|
45
|
+
)
|
46
|
+
elsif e.kind == :iter && e.body[0].kind == :call && e.body[0].body[1] == :test
|
47
|
+
# All we need to do is change the name of the invoked method
|
48
|
+
e.clone.tap do |e|
|
49
|
+
e.body[0][2] = :it
|
50
|
+
end
|
51
|
+
else
|
52
|
+
e
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
@@ -12,10 +12,10 @@ module RSpecify
|
|
12
12
|
|
13
13
|
def transform_test_unit_assertions(e)
|
14
14
|
case
|
15
|
-
when
|
16
|
-
|
17
|
-
when
|
18
|
-
|
15
|
+
when assert_equal_call?(e)
|
16
|
+
transform_assert_equal_call(e)
|
17
|
+
when assert_not_equal_call?(e)
|
18
|
+
transform_assert_not_equal_call(e)
|
19
19
|
when assert_not_nil_call?(e)
|
20
20
|
transform_assert_not_nil_call(e)
|
21
21
|
else
|
@@ -23,31 +23,31 @@ module RSpecify
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
27
|
-
def
|
28
|
-
e.kind == :call && e.body[0].nil? && e.body[1] == :
|
26
|
+
# assert_equal:
|
27
|
+
def assert_equal_call?(e)
|
28
|
+
e.kind == :call && e.body[0].nil? && e.body[1] == :assert_equal
|
29
29
|
end
|
30
|
-
def
|
30
|
+
def transform_assert_equal_call(e)
|
31
31
|
method_arguments = e.body[2].body
|
32
32
|
|
33
33
|
s(:call,
|
34
|
-
s(:call, method_arguments[
|
34
|
+
s(:call, method_arguments[1], :should, s(:arglist)),
|
35
35
|
:==,
|
36
|
-
s(:arglist, method_arguments[
|
36
|
+
s(:arglist, method_arguments[0])
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
41
|
-
def
|
42
|
-
e.kind == :call && e.body[0].nil? && e.body[1] == :
|
40
|
+
# assert_not_equal:
|
41
|
+
def assert_not_equal_call?(e)
|
42
|
+
e.kind == :call && e.body[0].nil? && e.body[1] == :assert_not_equal
|
43
43
|
end
|
44
|
-
def
|
44
|
+
def transform_assert_not_equal_call(e)
|
45
45
|
method_arguments = e.body[2].body
|
46
46
|
|
47
47
|
s(:call,
|
48
|
-
s(:call, method_arguments[
|
48
|
+
s(:call, method_arguments[1], :should_not, s(:arglist)),
|
49
49
|
:==,
|
50
|
-
s(:arglist, method_arguments[
|
50
|
+
s(:arglist, method_arguments[0])
|
51
51
|
)
|
52
52
|
end
|
53
53
|
|
data/lib/rspecify/version.rb
CHANGED
@@ -18,6 +18,22 @@ describe RSpecify::Transformers::TestClassAndMethods do
|
|
18
18
|
}) }
|
19
19
|
end
|
20
20
|
|
21
|
+
describe "class extending ActiveSupport::TestCase with Test naming convention" do
|
22
|
+
subject { %{
|
23
|
+
class MyClassTest < ActiveSupport::TestCase
|
24
|
+
do_something
|
25
|
+
something_else
|
26
|
+
end
|
27
|
+
} }
|
28
|
+
|
29
|
+
it { should transform_to("describe block", %{
|
30
|
+
describe MyClass do
|
31
|
+
do_something
|
32
|
+
something_else
|
33
|
+
end
|
34
|
+
}) }
|
35
|
+
end
|
36
|
+
|
21
37
|
describe "class extending ActiveSupport::TestCase with methods" do
|
22
38
|
subject { %{
|
23
39
|
class MyClass < ActiveSupport::TestCase
|
@@ -47,5 +63,73 @@ describe RSpecify::Transformers::TestClassAndMethods do
|
|
47
63
|
end
|
48
64
|
}) }
|
49
65
|
end
|
66
|
+
|
67
|
+
describe "class extending ActiveSupport::TestCase with single method" do
|
68
|
+
subject { %{
|
69
|
+
class MyClass < ActiveSupport::TestCase
|
70
|
+
def test_should_be_valid
|
71
|
+
something
|
72
|
+
1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
} }
|
76
|
+
|
77
|
+
it { should transform_to("describe block", %{
|
78
|
+
describe MyClass do
|
79
|
+
it "should be valid" do
|
80
|
+
something
|
81
|
+
1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
}) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "class extending ActiveSupport::TestCase with alternate methods naming" do
|
88
|
+
subject { %{
|
89
|
+
class MyClass < ActiveSupport::TestCase
|
90
|
+
test "should be valid" do
|
91
|
+
something
|
92
|
+
1
|
93
|
+
end
|
94
|
+
test "should not be valid" do
|
95
|
+
something
|
96
|
+
1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
} }
|
100
|
+
|
101
|
+
it { should transform_to("describe block", %{
|
102
|
+
describe MyClass do
|
103
|
+
it "should be valid" do
|
104
|
+
something
|
105
|
+
1
|
106
|
+
end
|
107
|
+
it "should not be valid" do
|
108
|
+
something
|
109
|
+
1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
}) }
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "class extending ActiveSupport::TestCase with single alternate method naming" do
|
116
|
+
subject { %{
|
117
|
+
class MyClass < ActiveSupport::TestCase
|
118
|
+
test "should be valid" do
|
119
|
+
something
|
120
|
+
1
|
121
|
+
end
|
122
|
+
end
|
123
|
+
} }
|
124
|
+
|
125
|
+
it { should transform_to("describe block", %{
|
126
|
+
describe MyClass do
|
127
|
+
it "should be valid" do
|
128
|
+
something
|
129
|
+
1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
}) }
|
133
|
+
end
|
50
134
|
|
51
135
|
end
|
@@ -2,24 +2,24 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe RSpecify::Transformers::TestUnitAssertions do
|
4
4
|
|
5
|
-
describe "short assert
|
6
|
-
subject { %{
|
5
|
+
describe "short assert equal" do
|
6
|
+
subject { %{assert_equal "One", @one} }
|
7
7
|
it { should transform_to("should ==", %{@one.should == "One"}) }
|
8
8
|
end
|
9
9
|
|
10
|
-
describe "long assert
|
10
|
+
describe "long assert equal" do
|
11
11
|
subject { %{
|
12
|
-
|
12
|
+
assert_equal @organization.people.first, Person.find_by_name_and_organization(
|
13
13
|
"Ben, Hughes",
|
14
14
|
"RailsGarden"
|
15
15
|
)
|
16
16
|
} }
|
17
17
|
|
18
|
-
it { should transform_to("should == ", %{
|
18
|
+
it { should transform_to("should == ", %{Person.find_by_name_and_organization("Ben, Hughes", "RailsGarden").should == @organization.people.first}) }
|
19
19
|
end
|
20
20
|
|
21
|
-
describe "short assert not
|
22
|
-
subject { %{
|
21
|
+
describe "short assert not equal" do
|
22
|
+
subject { %{assert_not_equal "One", @one} }
|
23
23
|
it { should transform_to("should_not ==", %{@one.should_not == "One"}) }
|
24
24
|
end
|
25
25
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspecify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-04-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70277469049040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.13'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70277469049040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70277469048560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70277469048560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: i18n
|
38
|
-
requirement: &
|
38
|
+
requirement: &70277469048080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.6.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70277469048080
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: ruby_parser
|
49
|
-
requirement: &
|
49
|
+
requirement: &70277469047600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.3.1
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70277469047600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: ruby_scribe
|
60
|
-
requirement: &
|
60
|
+
requirement: &70277469047120 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,21 +65,21 @@ dependencies:
|
|
65
65
|
version: 0.1.4
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70277469047120
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ruby_transform
|
71
|
-
requirement: &
|
71
|
+
requirement: &70277469046640 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 0.1.
|
76
|
+
version: 0.1.4
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70277469046640
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &70277469046160 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,18 @@ dependencies:
|
|
87
87
|
version: '2.0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70277469046160
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rake
|
93
|
+
requirement: &70277469045780 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70277469045780
|
91
102
|
description: Provides some automation to attempt to convert your Ruby Test::Unit tests
|
92
103
|
into RSpec.
|
93
104
|
email: ben@railsgarden.com
|
@@ -110,6 +121,7 @@ files:
|
|
110
121
|
- Gemfile
|
111
122
|
- Gemfile.lock
|
112
123
|
- LICENSE
|
124
|
+
- Rakefile
|
113
125
|
- README.rdoc
|
114
126
|
- bin/rspecify
|
115
127
|
homepage: http://github.com/rubiety/rspecify
|