mig-rspec_abandoner 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 0.3 / 2008-06-27
2
+
3
+ * Three variations of describe blocks are now properly handled
4
+
1
5
  === 0.2 / 2008-06-26
2
6
 
3
7
  * Converted specs land in their own directory
@@ -3,5 +3,7 @@ Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
5
  bin/rspec_abandoner
6
+ lib/camelize.rb
6
7
  lib/rspec_abandoner.rb
8
+ test/test_camelize.rb
7
9
  test/test_rspec_abandoner.rb
@@ -0,0 +1,7 @@
1
+ # This gsub is taken straight from ActiveSupport::Inflector
2
+
3
+ class String
4
+ def camelize
5
+ self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
 
3
3
  class RspecAbandoner
4
- VERSION = '0.2'
4
+ VERSION = '0.3'
5
5
 
6
6
  def self.start
7
7
  abandoner = RspecAbandoner.new
@@ -20,7 +20,7 @@ class RspecAbandoner
20
20
  output = ""
21
21
  File.open(file) do |io|
22
22
  io.each_line do |line|
23
- output << go(line)
23
+ output << go(line, file)
24
24
  end
25
25
  end
26
26
 
@@ -30,8 +30,16 @@ class RspecAbandoner
30
30
  File.delete(file)
31
31
  end
32
32
 
33
- def describe_block
34
- /describe\s(.*)\s.*do/
33
+ def describe_string_block
34
+ /describe\s"(.*)"\s.*do/
35
+ end
36
+
37
+ def describe_class_block
38
+ /describe\s([A-Za-z]*)\s.*do/
39
+ end
40
+
41
+ def describe_class_and_string_block
42
+ /describe\s*([A-Za-z]*),\s*"(.*)"\s*do/
35
43
  end
36
44
 
37
45
  def it_block
@@ -66,11 +74,22 @@ class RspecAbandoner
66
74
  /(.*).should\s*be_(.*)/
67
75
  end
68
76
 
69
- def go(input)
77
+ def go(input, file = nil)
78
+
79
+ if input.match(describe_string_block)
80
+ file_name = File.basename(file).gsub(/\.rb/, "").gsub(/_spec/, "")
81
+ input.gsub!(describe_string_block) do
82
+ "class #{file_name.camelize}Test < Test::Unit::TestCase"
83
+ end
84
+ end
85
+
86
+ input.gsub!(describe_class_block) do
87
+ "class #{$1}Test < Test::Unit::TestCase"
88
+ end if input.match(describe_class_block)
70
89
 
71
- input.gsub!(describe_block) do
90
+ input.gsub!(describe_class_and_string_block) do
72
91
  "class #{$1}Test < Test::Unit::TestCase"
73
- end if input.match(describe_block)
92
+ end if input.match(describe_class_and_string_block)
74
93
 
75
94
  input.gsub!(it_block) do
76
95
  "def test_#{$2.split(' ').join('_')}"
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + "/../lib/camelize"
3
+
4
+ class CamelizeTest < Test::Unit::TestCase
5
+
6
+ def test_camelize_will_camelcase_my_underscored_string
7
+ assert_equal "RspecAbandoner", "rspec_abandoner".camelize
8
+ end
9
+
10
+ end
@@ -1,6 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
3
  require 'mocha'
4
+ require File.dirname(__FILE__) + "/../lib/camelize"
4
5
  require File.dirname(__FILE__) + "/../lib/rspec_abandoner"
5
6
 
6
7
  class TestRspecAbandoner < Test::Unit::TestCase
@@ -14,6 +15,17 @@ class TestRspecAbandoner < Test::Unit::TestCase
14
15
  @abandon.go(%[describe CrabShack do])
15
16
  end
16
17
 
18
+ def test_should_use_camelized_filename_if_describe_is_a_string
19
+ file = "crab_shack_spec.rb"
20
+ assert_equal %[class CrabShackTest < Test::Unit::TestCase],
21
+ @abandon.go(%[describe "class methods" do], file)
22
+ end
23
+
24
+ def test_should_use_class_name_over_string_if_describe_has_both
25
+ assert_equal %[class CrabShackTest < Test::Unit::TestCase],
26
+ @abandon.go(%[describe CrabShack, "with no crabs" do])
27
+ end
28
+
17
29
  def test_should_replace_it_blocks_with_a_test_method
18
30
  assert_equal %[def test_should_know_things_are_weird],
19
31
  @abandon.go(%[it "should know things are weird" do])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mig-rspec_abandoner
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mig Swasey
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-13 00:00:00 -07:00
12
+ date: 2008-06-27 00:00:00 -07:00
13
13
  default_executable: rspec_abandoner
14
14
  dependencies: []
15
15
 
@@ -30,7 +30,9 @@ files:
30
30
  - README.txt
31
31
  - Rakefile
32
32
  - bin/rspec_abandoner
33
+ - lib/camelize.rb
33
34
  - lib/rspec_abandoner.rb
35
+ - test/test_camelize.rb
34
36
  - test/test_rspec_abandoner.rb
35
37
  has_rdoc: true
36
38
  homepage: http://pggbee.com