dcadenas-rspec2rr 0.1.0
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 +9 -0
- data/Rakefile +15 -0
- data/bin/rspec2rr +16 -0
- data/lib/rspec2rr.rb +33 -0
- data/rspec2rr.gemspec +19 -0
- data/spec/integration/rspec2rr_spec.rb +72 -0
- data/spec/unit/rspec2rr_spec.rb +71 -0
- metadata +59 -0
data/Manifest.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
require './lib/rspec2rr.rb'
|
7
|
+
|
8
|
+
Hoe.new('rspec2rr', RSpec2RR::VERSION) do |p|
|
9
|
+
p.developer('Daniel Cadenas', 'dcadenas@gmail.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
Spec::Rake::SpecTask.new do |t|
|
13
|
+
end
|
14
|
+
|
15
|
+
# vim: syntax=Ruby
|
data/bin/rspec2rr
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
require 'lib/rspec2rr'
|
4
|
+
|
5
|
+
Dir['spec/**/*_spec.rb'].each do |filename|
|
6
|
+
puts "Converting #{filename}"
|
7
|
+
content = File.read(filename)
|
8
|
+
result = RSpec2RR.to_rr(content)
|
9
|
+
if result != content
|
10
|
+
File.open(filename, 'w') do |f|
|
11
|
+
f << result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts
|
16
|
+
puts "Done"
|
data/lib/rspec2rr.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class RSpec2RR
|
2
|
+
VERSION = '0.1.0'
|
3
|
+
|
4
|
+
def self.to_rr spec
|
5
|
+
return unless spec
|
6
|
+
spec = convert_stub(spec)
|
7
|
+
spec = convert_should_receive(spec)
|
8
|
+
spec = convert_should_not_receive(spec)
|
9
|
+
spec = convert_with(spec)
|
10
|
+
spec = convert_and_return(spec)
|
11
|
+
spec
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.convert_stub(spec)
|
15
|
+
spec.gsub(/([\S]+)\.stub!\(:?([^\)]+)\)(.*)/, 'stub(\1).\2\3')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.convert_should_receive(spec)
|
19
|
+
spec.gsub(/([\S]+)\.should_receive\(:?([^\)]+)\)(.*)/, 'mock(\1).\2\3')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.convert_should_not_receive(spec)
|
23
|
+
spec.gsub(/([\S]+)\.should_not_receive\(:?([^\)]+)\)(.*)/, 'dont_allow(\1).\2\3')
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.convert_with(spec)
|
27
|
+
spec.gsub(/((stub|mock|dont_allow).+)\.with\((.+)\)(.*)/, '\1(\3)\4')
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.convert_and_return(spec)
|
31
|
+
spec.gsub(/\.and_return(.+)(.*)/, ' {\1}\2').gsub(/\{\((.+)\)\}/, '{\1}')
|
32
|
+
end
|
33
|
+
end
|
data/rspec2rr.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "rspec2rr"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2008-11-10"
|
5
|
+
s.summary = "Helps converting from rspec doubles to rr doubles"
|
6
|
+
s.email = "dcadenas@gmail.com"
|
7
|
+
s.homepage = "http://github.com/dcadenas/rspec2rr"
|
8
|
+
s.description = "rspec2rr is a Ruby script that helps you in the migration process from rspec dobules ro rr trying to reduce your manual work"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["Daniel Cadenas"]
|
11
|
+
s.files = [ "Manifest.txt",
|
12
|
+
"README.txt",
|
13
|
+
"Rakefile",
|
14
|
+
"rspec2rr.gemspec",
|
15
|
+
"lib/rspec2rr.rb",
|
16
|
+
"bin/rspec2rr"]
|
17
|
+
s.test_files = ["spec/unit/rspec2rr_spec.rb",
|
18
|
+
"spec/integration/rspec2rr_spec.rb"]
|
19
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '../..'))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'lib/rspec2rr'
|
6
|
+
require 'filetesthelper'
|
7
|
+
|
8
|
+
include FileTestHelper
|
9
|
+
|
10
|
+
def spec_file_content
|
11
|
+
<<-SPECFILECONTENT
|
12
|
+
a_string = 'this line is here just to represent a line that should not be changed by rspec2rr'
|
13
|
+
|
14
|
+
a.stub!(:asdf).with(1234)
|
15
|
+
b.stub!(:asdf)
|
16
|
+
b.should_not_receive(:asdf).with(1234)
|
17
|
+
b.should_not_receive(:asdf)
|
18
|
+
AModule::AClass.should_receive(:asdf).with(1234)
|
19
|
+
AModule::AClass.should_receive(:asdf)
|
20
|
+
|
21
|
+
a_string = 'this line is here just to represent a line that should not be changed by rspec2rr'
|
22
|
+
a_string = 'this line is here just to represent a line that should not be changed by rspec2rr'
|
23
|
+
SPECFILECONTENT
|
24
|
+
end
|
25
|
+
|
26
|
+
def expected_spec_file_content
|
27
|
+
<<-EXPECTEDSPECFILECONTENT
|
28
|
+
a_string = 'this line is here just to represent a line that should not be changed by rspec2rr'
|
29
|
+
|
30
|
+
stub(a).asdf(1234)
|
31
|
+
stub(b).asdf
|
32
|
+
dont_allow(b).asdf(1234)
|
33
|
+
dont_allow(b).asdf
|
34
|
+
mock(AModule::AClass).asdf(1234)
|
35
|
+
mock(AModule::AClass).asdf
|
36
|
+
|
37
|
+
a_string = 'this line is here just to represent a line that should not be changed by rspec2rr'
|
38
|
+
a_string = 'this line is here just to represent a line that should not be changed by rspec2rr'
|
39
|
+
EXPECTEDSPECFILECONTENT
|
40
|
+
end
|
41
|
+
|
42
|
+
TOOLPATH = File.expand_path(File.join(File.dirname(__FILE__), '..' , '..', 'bin' , 'rspec2rr'))
|
43
|
+
|
44
|
+
def run_rspec2rr
|
45
|
+
`#{TOOLPATH}`
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "rspec2rr" do
|
49
|
+
it "should convert a spec file rrspec doubles to rr syntax" do
|
50
|
+
with_files 'spec/test_spec.rb' => spec_file_content do
|
51
|
+
run_rspec2rr
|
52
|
+
changed_spec_file_content = File.read 'spec/test_spec.rb'
|
53
|
+
changed_spec_file_content.should == expected_spec_file_content
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not convert a spec file if it is not located in the spec dir" do
|
58
|
+
with_files 'a_dir/test_spec.rb' => spec_file_content do
|
59
|
+
run_rspec2rr
|
60
|
+
changed_spec_file_content = File.read 'a_dir/test_spec.rb'
|
61
|
+
changed_spec_file_content.should_not == expected_spec_file_content
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should not convert rb files that are not specs" do
|
66
|
+
with_files 'spec/only_specs_should_change_so_this_file_shouldnt_change.rb' => 'AModule.stub!(:method_name)' do
|
67
|
+
run_rspec2rr
|
68
|
+
unaltered_file_content = File.read 'spec/only_specs_should_change_so_this_file_shouldnt_change.rb'
|
69
|
+
unaltered_file_content.should == 'AModule.stub!(:method_name)'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '../..'))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'lib/rspec2rr'
|
6
|
+
|
7
|
+
def more_lines string = ''
|
8
|
+
<<-FAKEFILE
|
9
|
+
asd.asdf.asdfadsf
|
10
|
+
#{string}
|
11
|
+
asfd.asdf.asdf
|
12
|
+
|
13
|
+
FAKEFILE
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_converts actual, expected
|
17
|
+
RSpec2RR.to_rr(more_lines(actual)).should == more_lines(expected)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'rspec2rr' do
|
21
|
+
it 'should not change a nil string' do
|
22
|
+
RSpec2RR.to_rr(nil).should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should not change an empty string' do
|
26
|
+
RSpec2RR.to_rr('').should == ''
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not change a string with no rspec mocks' do
|
30
|
+
RSpec2RR.to_rr(more_lines).should == more_lines
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should convert stub!(:method_name) to rr syntax' do
|
34
|
+
rspec_mock_string = 'A::Class.stub!(:stubbed_method)'
|
35
|
+
|
36
|
+
assert_converts rspec_mock_string, 'stub(A::Class).stubbed_method'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should convert should_receive(:method_name) to rr syntax' do
|
40
|
+
rspec_mock_string = 'A::Class.should_receive(:stubbed_method)'
|
41
|
+
|
42
|
+
assert_converts rspec_mock_string, 'mock(A::Class).stubbed_method'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should convert stub!(:method_name).with(something) to rr syntax' do
|
46
|
+
rspec_mock_string = 'A::Class.stub!(:stubbed_method).with(something)'
|
47
|
+
|
48
|
+
assert_converts rspec_mock_string, 'stub(A::Class).stubbed_method(something)'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should convert should_receive(:method_name).with(something) to rr syntax' do
|
52
|
+
rspec_mock_string = 'A::Class.should_receive(:stubbed_method).with(something)'
|
53
|
+
|
54
|
+
assert_converts rspec_mock_string, 'mock(A::Class).stubbed_method(something)'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should convert should_not_receive(:method_name).with(something) to rr syntax' do
|
58
|
+
rspec_mock_string = 'A::Class.should_not_receive(:stubbed_method).with(something)'
|
59
|
+
|
60
|
+
assert_converts rspec_mock_string, 'dont_allow(A::Class).stubbed_method(something)'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should convert and_return to block' do
|
64
|
+
rspec_mock_string = 'User.stub!(:find_by_email).and_return(@user)'
|
65
|
+
|
66
|
+
assert_converts rspec_mock_string, 'stub(User).find_by_email {@user}'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dcadenas-rspec2rr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Cadenas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-10 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: rspec2rr is a Ruby script that helps you in the migration process from rspec dobules ro rr trying to reduce your manual work
|
17
|
+
email: dcadenas@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Manifest.txt
|
26
|
+
- README.txt
|
27
|
+
- Rakefile
|
28
|
+
- rspec2rr.gemspec
|
29
|
+
- lib/rspec2rr.rb
|
30
|
+
- bin/rspec2rr
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://github.com/dcadenas/rspec2rr
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Helps converting from rspec doubles to rr doubles
|
57
|
+
test_files:
|
58
|
+
- spec/unit/rspec2rr_spec.rb
|
59
|
+
- spec/integration/rspec2rr_spec.rb
|