mig-rspec_abandoner 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,8 @@
1
+ === 0.2 / 2008-06-26
2
+
3
+ * Converted specs land in their own directory
4
+
5
+ === 0.1 / 2008-06-13
6
+
7
+ * Initial release
8
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/rspec_abandoner
6
+ lib/rspec_abandoner.rb
7
+ test/test_rspec_abandoner.rb
data/README.txt ADDED
@@ -0,0 +1,44 @@
1
+ = RspecAbandoner
2
+
3
+ == DESCRIPTION:
4
+
5
+ This is a script, that when run inside of your project, will convert your RSpec specs to Test::Unit tests.
6
+
7
+ == FEATURES/PROBLEMS:
8
+
9
+ * Not every "should" scenario has been covered
10
+ * The formatting for output could use some work
11
+
12
+ == SYNOPSIS:
13
+
14
+ cd /my/ruby_or_rails_project
15
+ rspec_abandoner
16
+
17
+ == INSTALL:
18
+
19
+ gem install mig-rspec_abandoner --source=http://gems.github.com
20
+
21
+ == LICENSE:
22
+
23
+ (The MIT License)
24
+
25
+ Copyright (c) 2008 Mig Swasey
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining
28
+ a copy of this software and associated documentation files (the
29
+ 'Software'), to deal in the Software without restriction, including
30
+ without limitation the rights to use, copy, modify, merge, publish,
31
+ distribute, sublicense, and/or sell copies of the Software, and to
32
+ permit persons to whom the Software is furnished to do so, subject to
33
+ the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be
36
+ included in all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
39
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require './lib/rspec_abandoner.rb'
4
+
5
+ Hoe.new('RspecAbandoner', RspecAbandoner::VERSION) do |p|
6
+ p.developer('Mig Swasey', 'mig@pggbee.com')
7
+ p.summary = "A script that will convert your rspec specs into Test::Unit tests"
8
+ p.url = "http://pggbee.com"
9
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rspec_abandoner'
4
+ RspecAbandoner.start
@@ -0,0 +1,110 @@
1
+ require 'fileutils'
2
+
3
+ class RspecAbandoner
4
+ VERSION = '0.2'
5
+
6
+ def self.start
7
+ abandoner = RspecAbandoner.new
8
+ abandoner.start
9
+ end
10
+
11
+ def start
12
+ FileUtils.cp_r("spec", "spec_converted")
13
+ specs = Dir.glob("spec_converted/**/*_spec.rb")
14
+ specs.each do |spec|
15
+ read_spec_file(spec)
16
+ end
17
+ end
18
+
19
+ def read_spec_file(file)
20
+ output = ""
21
+ File.open(file) do |io|
22
+ io.each_line do |line|
23
+ output << go(line)
24
+ end
25
+ end
26
+
27
+ File.open(file.gsub(/_spec/, "_test"), "w") do |io|
28
+ io.write(output)
29
+ end
30
+ File.delete(file)
31
+ end
32
+
33
+ def describe_block
34
+ /describe\s(.*)\s.*do/
35
+ end
36
+
37
+ def it_block
38
+ /it\s*(\'|\")(.*)(\'|\")\s*do/
39
+ end
40
+
41
+ def before_block
42
+ /before.*do/
43
+ end
44
+
45
+ def should_equal_block
46
+ /(.*).should\s*(==|equal)[\s\(]([\w\'\"]*)(.*)/
47
+ end
48
+
49
+ def should_eql_block
50
+ /(.*).should\s*(===|eql)[\s\(]([\w\'\"]*)(.*)/
51
+ end
52
+
53
+ def should_not_block
54
+ /(.*).should_not\s*(==|equal)[\s\(]([\w\'\"]*)(.*)/
55
+ end
56
+
57
+ def should_be_kind_of_block
58
+ /(.*).should\s*be_a_kind_of[\s\(]([\w]*)(.*)/
59
+ end
60
+
61
+ def should_be_nil_block
62
+ /(.*).should(_not)?\s*be_nil/
63
+ end
64
+
65
+ def should_be_whatever_block
66
+ /(.*).should\s*be_(.*)/
67
+ end
68
+
69
+ def go(input)
70
+
71
+ input.gsub!(describe_block) do
72
+ "class #{$1}Test < Test::Unit::TestCase"
73
+ end if input.match(describe_block)
74
+
75
+ input.gsub!(it_block) do
76
+ "def test_#{$2.split(' ').join('_')}"
77
+ end if input.match(it_block)
78
+
79
+ input.gsub!(before_block) do
80
+ "def setup"
81
+ end if input.match(before_block)
82
+
83
+ input.gsub!(should_equal_block) do
84
+ "assert_equal #{$3}, #{$1}"
85
+ end if input.match(should_equal_block)
86
+
87
+ input.gsub!(should_eql_block) do
88
+ "assert_same #{$3}, #{$1}"
89
+ end if input.match(should_eql_block)
90
+
91
+ input.gsub!(should_not_block) do
92
+ "assert ! #{$3} == #{$1}"
93
+ end if input.match(should_not_block)
94
+
95
+ input.gsub!(should_be_kind_of_block) do
96
+ "assert_kind_of #{$2}, #{$1}"
97
+ end if input.match(should_be_kind_of_block)
98
+
99
+ input.gsub!(should_be_nil_block) do
100
+ "assert#{$2}_nil #{$1}"
101
+ end
102
+
103
+ input.gsub!(should_be_whatever_block) do
104
+ "assert_#{$2} #{$1}"
105
+ end
106
+
107
+ input
108
+ end
109
+
110
+ end
@@ -0,0 +1,62 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require File.dirname(__FILE__) + "/../lib/rspec_abandoner"
5
+
6
+ class TestRspecAbandoner < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @abandon = RspecAbandoner.new
10
+ end
11
+
12
+ def test_should_replace_describe_block_with_class_declaration
13
+ assert_equal %[class CrabShackTest < Test::Unit::TestCase],
14
+ @abandon.go(%[describe CrabShack do])
15
+ end
16
+
17
+ def test_should_replace_it_blocks_with_a_test_method
18
+ assert_equal %[def test_should_know_things_are_weird],
19
+ @abandon.go(%[it "should know things are weird" do])
20
+ assert_equal %[def test_should_know_things_are_chill],
21
+ @abandon.go(%[it 'should know things are chill' do])
22
+ end
23
+
24
+ def test_should_replace_before_and_before_each_blocks_with_setup
25
+ assert_equal %[def setup], @abandon.go(%[before do])
26
+ assert_equal %[def setup], @abandon.go(%[before(:each) do])
27
+ end
28
+
29
+ def test_should_replace_should_equals_with_assert_equals
30
+ assert_equal %[assert_equal "hi", say_hi], @abandon.go(%[say_hi.should == "hi"])
31
+ end
32
+
33
+ def test_should_replace_should_equals_spelled_out_with_assert_equals
34
+ assert_equal %[assert_equal "hi", say_hi], @abandon.go(%[say_hi.should equal("hi")])
35
+ end
36
+
37
+ def test_should_replace_should_eql_with_assert_same
38
+ assert_equal %[assert_same me, you], @abandon.go(%[you.should eql(me)])
39
+ assert_equal %[assert_same me, you], @abandon.go(%[you.should === me])
40
+ end
41
+
42
+ def test_should_replace_should_not_with_assert_bang
43
+ assert_equal %[assert ! true == false], @abandon.go(%[false.should_not == true])
44
+ end
45
+
46
+ def test_should_replace_should_be_a_kind_of_with_assert_kind_of
47
+ assert_equal %[assert_kind_of Hash, rocket], @abandon.go(%[rocket.should be_a_kind_of(Hash)])
48
+ end
49
+
50
+ def test_should_replace_should_be_nil_and_should_not_be_nil_with_assert_nil_or_assert_not_nil
51
+ assert_equal %[assert_nil personality], @abandon.go(%[personality.should be_nil])
52
+ assert_equal %[assert_not_nil ego], @abandon.go(%[ego.should_not be_nil])
53
+ end
54
+
55
+ def test_should_replace_should_be_valid_with_assert_valid
56
+ assert_equal %[assert_valid @post], @abandon.go(%[@post.should be_valid])
57
+ end
58
+
59
+ def test_should_replace_should_be_whatever_with_assert_whatever
60
+ assert_equal %[assert_crazy @dad], @abandon.go(%[@dad.should be_crazy])
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mig-rspec_abandoner
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.2"
5
+ platform: ruby
6
+ authors:
7
+ - Mig Swasey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-13 00:00:00 -07:00
13
+ default_executable: rspec_abandoner
14
+ dependencies: []
15
+
16
+ description: This is a script, that when run inside of your project, will convert your RSpec specs to Test::Unit tests.
17
+ email:
18
+ - mig@pggbee.com
19
+ executables:
20
+ - rspec_abandoner
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - History.txt
25
+ - Manifest.txt
26
+ - README.txt
27
+ files:
28
+ - History.txt
29
+ - Manifest.txt
30
+ - README.txt
31
+ - Rakefile
32
+ - bin/rspec_abandoner
33
+ - lib/rspec_abandoner.rb
34
+ - test/test_rspec_abandoner.rb
35
+ has_rdoc: true
36
+ homepage: http://pggbee.com
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --main
40
+ - README.txt
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A script that will convert your rspec specs into Test::Unit tests
62
+ test_files:
63
+ - test/test_rspec_abandoner.rb