testrbl 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testrbl (0.1.2)
4
+ testrbl (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -2,8 +2,8 @@ require 'testrbl/version'
2
2
 
3
3
  module Testrbl
4
4
  PATTERNS = [
5
- /^\s+(?:should|context)\s+['"](.*)['"]\s+do\s*$/,
6
- /^\s+def\s+test_([a-z_\d]+)\s*$/
5
+ /^(\s+)(?:should|context|test)\s+['"](.*)['"]\s+do\s*$/,
6
+ /^(\s+)def\s+test_([a-z_\d]+)\s*$/
7
7
  ]
8
8
 
9
9
  def self.run_from_cli(argv)
@@ -13,7 +13,8 @@ module Testrbl
13
13
  end
14
14
 
15
15
  file, line = argv.first.split(':')
16
- run "testrb #{file} #{pattern_from_file(file, line)}"
16
+ file = "./#{file}" if file =~ /^[a-z]/ # fix 1.9 not being able to load local files
17
+ run "testrb #{file} -n '/#{pattern_from_file(file, line)}/'"
17
18
  end
18
19
 
19
20
  def self.run(command)
@@ -28,12 +29,24 @@ module Testrbl
28
29
  def self.pattern_from_file(file, line)
29
30
  content = File.readlines(file)
30
31
  search = content[0..(line.to_i-1)].reverse
31
- search.each do |line|
32
- PATTERNS.each do |r|
33
- return "-n '/#{Regexp.escape($1.gsub('\'',"."))}/'" if line =~ r
34
- end
32
+
33
+ last_spaces = " " * 100
34
+ found = search.map{|line| pattern_from_line(line) }.compact
35
+ puts found.inspect
36
+
37
+ found.select! do |spaces, name|
38
+ last_spaces = spaces if spaces.size < last_spaces.size
35
39
  end
36
40
 
41
+ return found.reverse.map(&:last).join(".*") if found.size > 0
42
+
37
43
  raise "no test found before line #{line}"
38
44
  end
45
+
46
+ def self.pattern_from_line(line)
47
+ PATTERNS.each do |r|
48
+ return [$1, Regexp.escape($2).gsub("'",".").gsub("\\ "," ")] if line =~ r
49
+ end
50
+ nil
51
+ end
39
52
  end
@@ -1,3 +1,3 @@
1
1
  module Testrbl
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -77,6 +77,35 @@ describe Testrbl do
77
77
  end
78
78
  end
79
79
 
80
+ context "test with string" do
81
+ before do
82
+ write "a_test.rb", <<-RUBY
83
+ require 'test/unit'
84
+
85
+ class Xxx < Test::Unit::TestCase
86
+ test "a" do
87
+ puts 'ABC'
88
+ end
89
+
90
+ test "b" do
91
+ puts 'BCD'
92
+ end
93
+
94
+ test "c" do
95
+ puts 'CDE'
96
+ end
97
+ end
98
+ RUBY
99
+ end
100
+
101
+ it "runs test" do
102
+ result = testrbl "a_test.rb:8"
103
+ result.should_not include "ABC\n"
104
+ result.should include "BCD\n"
105
+ result.should_not include "CDE\n"
106
+ end
107
+ end
108
+
80
109
  context "shoulda" do
81
110
  before do
82
111
  write "a_test.rb", <<-RUBY
@@ -100,6 +129,16 @@ describe Testrbl do
100
129
  should "e" do
101
130
  puts 'DEF'
102
131
  end
132
+
133
+ should "..'?! [(" do
134
+ puts 'EFG'
135
+ end
136
+ end
137
+
138
+ context "g" do
139
+ should "a" do
140
+ puts "FGH"
141
+ end
103
142
  end
104
143
  end
105
144
  RUBY
@@ -112,6 +151,12 @@ describe Testrbl do
112
151
  result.should_not include "CDE\n"
113
152
  end
114
153
 
154
+ it "runs stuff with regex special chars" do
155
+ result = testrbl "a_test.rb:22"
156
+ result.should_not include "DEF\n"
157
+ result.should include "EFG\n"
158
+ end
159
+
115
160
  it "runs context" do
116
161
  result = testrbl "a_test.rb:13"
117
162
  result.should_not include "ABC\n"
@@ -119,6 +164,13 @@ describe Testrbl do
119
164
  result.should include "CDE\n"
120
165
  result.should include "DEF\n"
121
166
  end
167
+
168
+ it "runs via nested context" do
169
+ result = testrbl "a_test.rb:28"
170
+ result.should_not include "ABC\n"
171
+ result.should_not include "EFG\n"
172
+ result.should include "FGH\n"
173
+ end
122
174
  end
123
175
 
124
176
  context "multiple files / folders" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testrbl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-31 00:00:00.000000000 Z
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  segments:
46
46
  - 0
47
- hash: 4365681573052435573
47
+ hash: 2668541531595975452
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 4365681573052435573
56
+ hash: 2668541531595975452
57
57
  requirements: []
58
58
  rubyforge_project:
59
59
  rubygems_version: 1.8.24