testrbl 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/.travis.yml +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/Rakefile +22 -0
- data/Readme.md +24 -0
- data/bin/testrbl +4 -0
- data/lib/testrbl/version.rb +3 -0
- data/lib/testrbl.rb +37 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/testrbl_spec.rb +190 -0
- data/testrbl.gemspec +13 -0
- metadata +63 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
testrbl (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rake (0.9.2)
|
11
|
+
rspec (2.6.0)
|
12
|
+
rspec-core (~> 2.6.0)
|
13
|
+
rspec-expectations (~> 2.6.0)
|
14
|
+
rspec-mocks (~> 2.6.0)
|
15
|
+
rspec-core (2.6.4)
|
16
|
+
rspec-expectations (2.6.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.6.0)
|
19
|
+
shoulda (3.0.1)
|
20
|
+
shoulda-context (~> 1.0.0)
|
21
|
+
shoulda-matchers (~> 1.0.0)
|
22
|
+
shoulda-context (1.0.0)
|
23
|
+
shoulda-matchers (1.0.0)
|
24
|
+
test-unit (2.4.4)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
rake
|
31
|
+
rspec (~> 2)
|
32
|
+
shoulda
|
33
|
+
test-unit
|
34
|
+
testrbl!
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
task :default do
|
4
|
+
sh "rspec spec/"
|
5
|
+
end
|
6
|
+
|
7
|
+
# extracted from https://github.com/grosser/project_template
|
8
|
+
rule /^version:bump:.*/ do |t|
|
9
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
10
|
+
index = ['major', 'minor','patch'].index(t.name.split(':').last)
|
11
|
+
file = 'lib/testrbl/version.rb'
|
12
|
+
|
13
|
+
version_file = File.read(file)
|
14
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
15
|
+
version_parts[index] = version_parts[index].to_i + 1
|
16
|
+
version_parts[2] = 0 if index < 2 # remove patch for minor
|
17
|
+
version_parts[1] = 0 if index < 1 # remove minor for major
|
18
|
+
new_version = version_parts * '.'
|
19
|
+
File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
|
20
|
+
|
21
|
+
sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
|
22
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Run ruby Test::Unit/Shoulda tests by line-number / folder / the dozen.<br/>
|
2
|
+
(everything not matching "file:line" is simply passed to testrb)
|
3
|
+
|
4
|
+
Install
|
5
|
+
=======
|
6
|
+
gem install testrbl
|
7
|
+
|
8
|
+
Usage
|
9
|
+
=====
|
10
|
+
testrbl test/unit/xxx_test.rb:123 # test by line number
|
11
|
+
testrbl test/unit # everything _test.rb in a folder (on 1.8 this would be test/unit/*)
|
12
|
+
testrbl xxx_test.rb yyy_test.rb # multiple files
|
13
|
+
|
14
|
+
TODO
|
15
|
+
====
|
16
|
+
- make colors show in 1.9 (without using bundle exec and adding test-runit to gemfile) [stackoverflow](http://stackoverflow.com/questions/10810107/ruby-how-to-get-colors-in-testrb)
|
17
|
+
- prepend shoulda contexts to search -n '/OUTER-CONTEXT.*INNER-CONTEXT.*SHOULD/', make sure indentation is decreasing by 1 every step to avoid fetching everything
|
18
|
+
|
19
|
+
Author
|
20
|
+
======
|
21
|
+
[Michael Grosser](http://grosser.it)<br/>
|
22
|
+
michael@grosser.it<br/>
|
23
|
+
License: MIT<br/>
|
24
|
+
[](http://travis-ci.org/grosser/testrbl)
|
data/bin/testrbl
ADDED
data/lib/testrbl.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'testrbl/version'
|
2
|
+
|
3
|
+
module Testrbl
|
4
|
+
PATTERNS = [
|
5
|
+
/^\s+(?:should|context)\s+['"](.*)['"]\s+do\s*$/,
|
6
|
+
/^\s+def\s+test_([a-z_\d]+)\s*$/
|
7
|
+
]
|
8
|
+
|
9
|
+
def self.run_from_cli(argv)
|
10
|
+
# we only work with 1 file with line-number, everything else gets passed thourgh
|
11
|
+
if argv.join(" ") !~ /^\S+:\d+$/
|
12
|
+
run "testrb #{argv.map{|a| a.include?(' ') ? "'#{a}'" : a }.join(' ')}"
|
13
|
+
end
|
14
|
+
|
15
|
+
file, line = argv.first.split(':')
|
16
|
+
run "testrb #{file} #{pattern_from_file(file, line)}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.run(command)
|
20
|
+
puts command
|
21
|
+
exec command
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.pattern_from_file(file, line)
|
27
|
+
content = File.readlines(file)
|
28
|
+
search = content[0..(line.to_i-1)].reverse
|
29
|
+
search.each do |line|
|
30
|
+
PATTERNS.each do |r|
|
31
|
+
return "-n '/#{Regexp.escape($1.gsub('\'',"."))}/'" if line =~ r
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
raise "no test found before line #{line}"
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Testrbl do
|
4
|
+
around do |example|
|
5
|
+
run "rm -rf tmp && mkdir tmp"
|
6
|
+
Dir.chdir "tmp" do
|
7
|
+
example.call
|
8
|
+
end
|
9
|
+
run "rm -rf tmp"
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(cmd, options={})
|
13
|
+
result = `#{cmd} 2>&1`
|
14
|
+
raise "FAILED #{cmd} --> #{result}" if $?.success? != !options[:fail]
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def testrbl(command, options={})
|
19
|
+
run "#{File.expand_path("../../bin/testrbl", __FILE__)} #{command}", options
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(file, content)
|
23
|
+
folder = File.dirname(file)
|
24
|
+
run "mkdir -p #{folder}" unless File.exist?(folder)
|
25
|
+
File.open(file, 'w'){|f| f.write content }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a VERSION" do
|
29
|
+
Testrbl::VERSION.should =~ /^[\.\da-z]+$/
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with a simple setup" do
|
33
|
+
before do
|
34
|
+
write "a_test.rb", <<-RUBY
|
35
|
+
require 'test/unit'
|
36
|
+
|
37
|
+
class Xxx < Test::Unit::TestCase
|
38
|
+
def test_xxx
|
39
|
+
puts 'ABC'
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_yyy
|
43
|
+
puts 'BCD'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RUBY
|
47
|
+
end
|
48
|
+
|
49
|
+
it "runs by exact line" do
|
50
|
+
result = testrbl "a_test.rb:4"
|
51
|
+
result.should include "ABC\n"
|
52
|
+
result.should_not include "BCD"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "runs by above a line" do
|
56
|
+
result = testrbl "a_test.rb:5"
|
57
|
+
result.should include "ABC\n"
|
58
|
+
result.should_not include "BCD"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "does not run when line is before test" do
|
62
|
+
result = testrbl "a_test.rb:3", :fail => true
|
63
|
+
result.should include "no test found before line 3"
|
64
|
+
result.should_not include "ABC"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "runs whole file without number" do
|
68
|
+
result = testrbl "a_test.rb"
|
69
|
+
result.should include "ABC\n"
|
70
|
+
result.should include "BCD"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "runs with options" do
|
74
|
+
result = testrbl "a_test.rb -n '/xxx/'"
|
75
|
+
result.should include "ABC"
|
76
|
+
result.should_not include "BCD"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "shoulda" do
|
81
|
+
before do
|
82
|
+
write "a_test.rb", <<-RUBY
|
83
|
+
require 'test/unit'
|
84
|
+
require 'shoulda'
|
85
|
+
|
86
|
+
class Xxx < Test::Unit::TestCase
|
87
|
+
should "a" do
|
88
|
+
puts 'ABC'
|
89
|
+
end
|
90
|
+
|
91
|
+
should "b" do
|
92
|
+
puts 'BCD'
|
93
|
+
end
|
94
|
+
|
95
|
+
context "c" do
|
96
|
+
should "d" do
|
97
|
+
puts 'CDE'
|
98
|
+
end
|
99
|
+
|
100
|
+
should "e" do
|
101
|
+
puts 'DEF'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
RUBY
|
106
|
+
end
|
107
|
+
|
108
|
+
it "runs should" do
|
109
|
+
result = testrbl "a_test.rb:9"
|
110
|
+
result.should_not include "ABC\n"
|
111
|
+
result.should include "BCD\n"
|
112
|
+
result.should_not include "CDE\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "runs context" do
|
116
|
+
result = testrbl "a_test.rb:13"
|
117
|
+
result.should_not include "ABC\n"
|
118
|
+
result.should_not include "BCD\n"
|
119
|
+
result.should include "CDE\n"
|
120
|
+
result.should include "DEF\n"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "multiple files / folders" do
|
125
|
+
before do
|
126
|
+
write "a_test.rb", <<-RUBY
|
127
|
+
require 'test/unit'
|
128
|
+
|
129
|
+
class Xxx1 < Test::Unit::TestCase
|
130
|
+
def test_xxx
|
131
|
+
puts 'ABC'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
RUBY
|
135
|
+
|
136
|
+
write "a/a_test.rb", <<-RUBY
|
137
|
+
require 'test/unit'
|
138
|
+
|
139
|
+
class Xxx2 < Test::Unit::TestCase
|
140
|
+
def test_xxx
|
141
|
+
puts 'BCD'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
RUBY
|
145
|
+
|
146
|
+
write "a/b/c_test.rb", <<-RUBY
|
147
|
+
require 'test/unit'
|
148
|
+
|
149
|
+
class Xxx3 < Test::Unit::TestCase
|
150
|
+
def test_xxx
|
151
|
+
puts 'CDE'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
RUBY
|
155
|
+
|
156
|
+
write "a/c/c_test.rb", <<-RUBY
|
157
|
+
require 'test/unit'
|
158
|
+
|
159
|
+
class Xxx4 < Test::Unit::TestCase
|
160
|
+
def test_xxx
|
161
|
+
puts 'DEF'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
RUBY
|
165
|
+
end
|
166
|
+
|
167
|
+
it "runs a folder with subfolders" do
|
168
|
+
result = testrbl "a"
|
169
|
+
result.should_not include "ABC\n"
|
170
|
+
result.should include "BCD\n"
|
171
|
+
result.should include "CDE\n"
|
172
|
+
end
|
173
|
+
|
174
|
+
it "runs files and folders" do
|
175
|
+
result = testrbl "a/b a/c/c_test.rb"
|
176
|
+
result.should_not include "ABC\n"
|
177
|
+
result.should_not include "BCD\n"
|
178
|
+
result.should include "CDE\n"
|
179
|
+
result.should include "DEF\n"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "runs multiple files" do
|
183
|
+
result = testrbl "a/b/c_test.rb a/c/c_test.rb"
|
184
|
+
result.should_not include "ABC\n"
|
185
|
+
result.should_not include "BCD\n"
|
186
|
+
result.should include "CDE\n"
|
187
|
+
result.should include "DEF\n"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
data/testrbl.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
name = "testrbl"
|
3
|
+
require "#{name}/version"
|
4
|
+
|
5
|
+
Gem::Specification.new name, Testrbl::VERSION do |s|
|
6
|
+
s.summary = "Run ruby Test::Unit/Shoulda tests by line-number / folder / the dozen"
|
7
|
+
s.authors = ["Michael Grosser"]
|
8
|
+
s.email = "michael@grosser.it"
|
9
|
+
s.homepage = "http://github.com/grosser/#{name}"
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.executables = ["testrbl"]
|
12
|
+
s.license = 'MIT'
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testrbl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Grosser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: michael@grosser.it
|
16
|
+
executables:
|
17
|
+
- testrbl
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .travis.yml
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- Rakefile
|
25
|
+
- Readme.md
|
26
|
+
- bin/testrbl
|
27
|
+
- lib/testrbl.rb
|
28
|
+
- lib/testrbl/version.rb
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
- spec/testrbl_spec.rb
|
31
|
+
- testrbl.gemspec
|
32
|
+
homepage: http://github.com/grosser/testrbl
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
hash: -2640591623303812180
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
hash: -2640591623303812180
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.24
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Run ruby Test::Unit/Shoulda tests by line-number / folder / the dozen
|
63
|
+
test_files: []
|