rspecify 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspecify (0.1.1)
5
+ activesupport (~> 3.0.10)
6
+ i18n (~> 0.6.0)
7
+ ruby_parser (~> 2.3.1)
8
+ ruby_scribe (~> 0.1.0)
9
+ ruby_transform (~> 0.1.0)
10
+ thor (~> 0.13)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activesupport (3.0.10)
16
+ diff-lcs (1.1.3)
17
+ i18n (0.6.0)
18
+ rspec (2.6.0)
19
+ rspec-core (~> 2.6.0)
20
+ rspec-expectations (~> 2.6.0)
21
+ rspec-mocks (~> 2.6.0)
22
+ rspec-core (2.6.4)
23
+ rspec-expectations (2.6.0)
24
+ diff-lcs (~> 1.1.2)
25
+ rspec-mocks (2.6.0)
26
+ ruby_parser (2.3.1)
27
+ sexp_processor (~> 3.0)
28
+ ruby_scribe (0.1.2)
29
+ activesupport (~> 3.0.10)
30
+ i18n (~> 0.6.0)
31
+ ruby_parser (~> 2.3.1)
32
+ thor (~> 0.13)
33
+ ruby_transform (0.1.1)
34
+ activesupport (~> 3.0.10)
35
+ i18n (~> 0.6.0)
36
+ ruby_parser (~> 2.3.1)
37
+ ruby_scribe (~> 0.1.0)
38
+ thor (~> 0.13)
39
+ sexp_processor (3.0.7)
40
+ thor (0.14.6)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ rspec (~> 2.0)
47
+ rspecify!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ben Hughes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = RSpecify
2
+
3
+ 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.
4
+
5
+ == In-Progress
6
+
7
+ This gem is not useable and is being continually worked on. Will be released as 0.1.0 once reasonably working and stable.
8
+
9
+ DO NOT USE!
@@ -0,0 +1,21 @@
1
+ require "thor"
2
+ require "rspecify"
3
+
4
+ module RSpecify
5
+ class Runner < Thor
6
+ desc :cat, "Takes a single ruby file, parses it, and outputs the scribed version."
7
+ def cat(path)
8
+ sexp = RubyParser.new.parse(File.read(path))
9
+ sexp = RSpecify::Transformer.new.transform(sexp)
10
+ puts RubyScribe::Emitter.new.emit(sexp)
11
+ end
12
+
13
+ protected
14
+
15
+ def expand_paths(paths = [])
16
+ paths.map do |path|
17
+ [path] + Dir[path + "**/*.rb"]
18
+ end.flatten.uniq.reject {|f| File.directory?(f) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module RSpecify
2
+ class Transformer < RubyTransform::Transformer
3
+ def dependent_transformers
4
+ [
5
+ RSpecify::Transformers::TestClassAndMethods.new,
6
+ RSpecify::Transformers::TestUnitAssertions.new
7
+ ]
8
+ end
9
+
10
+ def transform(e)
11
+ super(dependent_transformers.inject(e) {|result, transformer|
12
+ transformer.transform(result)
13
+ })
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,52 @@
1
+ module RSpecify
2
+ module Transformers
3
+
4
+ # = Test Class And Methods Transformer
5
+ # Catches instances where a class is being defined extending ActiveSupport::TestClass and converts it into
6
+ # an RSpec describe block, then converts all methods contained therein beginning with "test_" to
7
+ # rspec "it" blocks.
8
+ #
9
+ class TestClassAndMethods < RubyTransform::Transformer
10
+ def transform(e)
11
+ super sexp?(e) ? transform_test_class_and_methods(e) : e
12
+ end
13
+
14
+ def transform_test_class_and_methods(e)
15
+ if e.kind == :class && e.body[1] == s(:colon2, s(:const, :ActiveSupport), :TestCase)
16
+ transform_test_class(e)
17
+ else
18
+ e
19
+ end
20
+ end
21
+
22
+ def transform_test_class(e)
23
+ s(:iter,
24
+ s(:call, nil, :describe, s(:arglist, s(:const, e.body[0]))),
25
+ nil,
26
+ transform_test_class_method_definitions(e.body[2].body[0])
27
+ )
28
+ end
29
+
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
+ def transform_test_class_method_definition(e)
41
+ test_name = e.body[0].to_s.gsub(/^test_/, "").gsub("_", " ")
42
+
43
+ s(:iter,
44
+ s(:call, nil, :it, s(:arglist, s(:str, test_name))),
45
+ nil,
46
+ e.body[2].body[0]
47
+ )
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,38 @@
1
+ module RSpecify
2
+ module Transformers
3
+
4
+ # = Test Unit Assertions Transformer
5
+ # Catches instances where Test::Unit assertions are being called (such as assert_equal) and morphs
6
+ # the calls to use the RSpec idiom.
7
+ #
8
+ class TestUnitAssertions < RubyTransform::Transformer
9
+ def transform(e)
10
+ super sexp?(e) ? transform_test_unit_assertions(e) : e
11
+ end
12
+
13
+ def transform_test_unit_assertions(e)
14
+ case
15
+ when assert_equals_call?(e)
16
+ transform_assert_equals_call(e)
17
+ else
18
+ e
19
+ end
20
+ end
21
+
22
+ def assert_equals_call?(e)
23
+ e.kind == :call && e.body[0].nil? && e.body[1] == :assert_equals
24
+ end
25
+
26
+ def transform_assert_equals_call(e)
27
+ method_arguments = e.body[2].body
28
+
29
+ s(:call,
30
+ s(:call, method_arguments[0], :should, s(:arglist)),
31
+ :==,
32
+ s(:arglist, method_arguments[1])
33
+ )
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module RSpecify
2
+ VERSION = "0.1.1"
3
+ end
data/lib/rspecify.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "rubygems"
2
+ require "ruby_parser"
3
+ require "ruby_scribe"
4
+ require "ruby_transform"
5
+
6
+ require "rspecify/transformer"
7
+
8
+ Dir[File.join(File.dirname(__FILE__), "rspecify/transformers/**/*.rb")].each do |file|
9
+ require file
10
+ end
@@ -0,0 +1,25 @@
1
+ RSpec::Matchers.define :transform_to do |desc, expected|
2
+ match do |actual|
3
+ actual_as_sexp = actual.is_a?(String) ? RubyParser.new.parse(actual) : actual
4
+ expected_as_sexp = expected.is_a?(String) ? RubyParser.new.parse(expected) : expected
5
+
6
+ @transformed = described_class.transform(actual_as_sexp)
7
+ @transformed == expected_as_sexp
8
+ end
9
+
10
+ failure_message_for_should do |actual|
11
+ "expected that:\n\n#{RubyParser.new.parse(actual)}\n\nwould transform to:\n\n#{RubyParser.new.parse(expected)}\n\nbut instead was:\n\n#{@transformed}\n\n#{transformed_as_ruby}"
12
+ end
13
+
14
+ failure_message_for_should_not do |actual|
15
+ "expected that:\n\n#{RubyParser.new.parse(actual)}\n\nwould not transform to:\n\n#{RubyParser.new.parse(expected)}\n\nbut instead was:\n\n#{@transformed}\n\n#{transformed_as_ruby}"
16
+ end
17
+
18
+ description do
19
+ "transform with to #{desc}"
20
+ end
21
+
22
+ def transformed_as_ruby
23
+ RubyScribe::Emitter.new.emit(@transformed) rescue nil
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpecify::Transformer.new do
4
+
5
+ end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpecify::Transformers::TestClassAndMethods.new do
4
+
5
+ describe "class extending ActiveSupport::TestCase" do
6
+ subject { %{
7
+ class MyClass < ActiveSupport::TestCase
8
+ do_something
9
+ something_else
10
+ end
11
+ } }
12
+
13
+ it { should transform_to("describe block", %{
14
+ describe MyClass do
15
+ do_something
16
+ something_else
17
+ end
18
+ }) }
19
+ end
20
+
21
+ describe "class extending ActiveSupport::TestCase with methods" do
22
+ subject { %{
23
+ class MyClass < ActiveSupport::TestCase
24
+ def test_should_be_valid
25
+ something
26
+ 1
27
+ end
28
+
29
+ def test_should_not_be_valid
30
+ something
31
+ 1
32
+ end
33
+ end
34
+ } }
35
+
36
+ it { should transform_to("describe block", %{
37
+ describe MyClass do
38
+ it "should be valid" do
39
+ something
40
+ 1
41
+ end
42
+
43
+ it "should not be valid" do
44
+ something
45
+ 1
46
+ end
47
+ end
48
+ }) }
49
+ end
50
+
51
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpecify::Transformers::TestUnitAssertions.new do
4
+
5
+ describe "short assert equals" do
6
+ subject { %{assert_equals @one, "One"} }
7
+ it { should transform_to("should ==", %{@one.should == "One"}) }
8
+ end
9
+
10
+ describe "long assert equals" do
11
+ subject { %{
12
+ assert_equals @organization.people.first, Person.find_by_name_and_organization(
13
+ "Ben, Hughes",
14
+ "RailsGarden"
15
+ )
16
+ } }
17
+
18
+ it { should transform_to("should == ", %{@organization.people.first.should == Person.find_by_name_and_organization("Ben, Hughes", "RailsGarden")}) }
19
+ end
20
+
21
+ end
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
2
+
3
+ require "rubygems"
4
+ require "rspec"
5
+ require "rspecify"
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/matchers/**/*.rb"].each {|f| require f}
10
+
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspecify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Hughes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70326759787600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.13'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70326759787600
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70326759786660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.10
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70326759786660
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ requirement: &70326759785980 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.6.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70326759785980
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruby_parser
49
+ requirement: &70326759785420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.1
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70326759785420
58
+ - !ruby/object:Gem::Dependency
59
+ name: ruby_scribe
60
+ requirement: &70326759784640 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.1.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70326759784640
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby_transform
71
+ requirement: &70326759783380 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.1.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70326759783380
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ requirement: &70326759780280 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '2.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70326759780280
91
+ description: Provides some automation to attempt to convert your Ruby Test::Unit tests
92
+ into RSpec.
93
+ email: ben@railsgarden.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - lib/rspecify/runner.rb
99
+ - lib/rspecify/transformer.rb
100
+ - lib/rspecify/transformers/test_class_and_methods.rb
101
+ - lib/rspecify/transformers/test_unit_assertions.rb
102
+ - lib/rspecify/version.rb
103
+ - lib/rspecify.rb
104
+ - spec/matchers/should_transform_to.rb
105
+ - spec/rspecify/transformer_spec.rb
106
+ - spec/rspecify/transformers/test_class_and_methods_spec.rb
107
+ - spec/rspecify/transformers/test_unit_assertions_spec.rb
108
+ - spec/spec_helper.rb
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE
112
+ - README.rdoc
113
+ homepage: http://github.com/rubiety/rspecify
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: 1.3.4
131
+ requirements: []
132
+ rubyforge_project: rspecify
133
+ rubygems_version: 1.8.10
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Intelligently converts your Test::Unit tests into RSpec.
137
+ test_files: []