single_test 0.3.7 → 0.4.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/Gemfile +6 -4
- data/Gemfile.lock +13 -10
- data/Rakefile +2 -2
- data/Readme.md +7 -5
- data/VERSION +1 -1
- data/lib/single_test.rb +20 -23
- data/single_test.gemspec +16 -18
- data/spec/single_test_spec.rb +20 -9
- data/spec/spec_helper.rb +2 -2
- metadata +13 -8
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
json_pure
|
4
|
+
diff-lcs (1.1.2)
|
6
5
|
git (1.2.5)
|
7
|
-
jeweler (1.
|
8
|
-
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
9
8
|
git (>= 1.2.5)
|
10
|
-
|
11
|
-
json_pure (1.4.3)
|
9
|
+
rake
|
12
10
|
rake (0.8.7)
|
13
|
-
rspec (
|
14
|
-
|
15
|
-
|
11
|
+
rspec (2.4.0)
|
12
|
+
rspec-core (~> 2.4.0)
|
13
|
+
rspec-expectations (~> 2.4.0)
|
14
|
+
rspec-mocks (~> 2.4.0)
|
15
|
+
rspec-core (2.4.0)
|
16
|
+
rspec-expectations (2.4.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.4.0)
|
16
19
|
|
17
20
|
PLATFORMS
|
18
21
|
ruby
|
@@ -20,4 +23,4 @@ PLATFORMS
|
|
20
23
|
DEPENDENCIES
|
21
24
|
jeweler
|
22
25
|
rake
|
23
|
-
rspec
|
26
|
+
rspec (~> 2)
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
task :default do
|
2
2
|
options = "--colour"
|
3
3
|
files = FileList['spec/**/*_spec.rb'].map{|f| f.sub(%r{^spec/},'') }
|
4
|
-
|
4
|
+
exec "cd spec && rspec #{options} #{files}"
|
5
5
|
end
|
6
6
|
|
7
7
|
begin
|
@@ -18,4 +18,4 @@ begin
|
|
18
18
|
Jeweler::GemcutterTasks.new
|
19
19
|
rescue LoadError
|
20
20
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
21
|
-
end
|
21
|
+
end
|
data/Readme.md
CHANGED
@@ -14,10 +14,12 @@ As Gem:
|
|
14
14
|
|
15
15
|
|
16
16
|
###Single test/spec
|
17
|
-
|
17
|
+
Searchs for test-files matching the given name.
|
18
|
+
|
19
|
+
rake spec:user #run spec/model/user_spec.rb
|
18
20
|
rake test:users_c #run test/functional/users_controller_test.rb
|
19
21
|
rake spec:admin/users_c #run spec/controllers/admin/users_controller_spec.rb
|
20
|
-
rake test:u*hel #run test/helpers/user_helper_test.rb
|
22
|
+
rake test:u*hel #run test/helpers/user_helper_test.rb
|
21
23
|
|
22
24
|
###Single test-case/example
|
23
25
|
rake spec:user:token #run the first spec in user_spec.rb that matches /token/
|
@@ -45,6 +47,6 @@ TODO
|
|
45
47
|
|
46
48
|
AUTHOR
|
47
49
|
======
|
48
|
-
[Michael Grosser](http://pragmatig.wordpress.com)
|
49
|
-
grosser.michael@gmail.com
|
50
|
-
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
50
|
+
[Michael Grosser](http://pragmatig.wordpress.com)
|
51
|
+
grosser.michael@gmail.com
|
52
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/single_test.rb
CHANGED
@@ -3,10 +3,6 @@ require 'rake'
|
|
3
3
|
module SingleTest
|
4
4
|
extend self
|
5
5
|
CMD_LINE_MATCHER = /^(spec|test)\:.*(\:.*)?$/
|
6
|
-
SEARCH_ORDER = {
|
7
|
-
'test'=> %w(unit functional integration *),
|
8
|
-
'spec'=> %w(models controllers views helpers *),
|
9
|
-
}
|
10
6
|
|
11
7
|
def load_tasks
|
12
8
|
load File.join(File.dirname(__FILE__), 'tasks', 'single_test.rake')
|
@@ -42,11 +38,6 @@ module SingleTest
|
|
42
38
|
file = find_test_file(type,file)
|
43
39
|
return unless file
|
44
40
|
|
45
|
-
#when spec, convert test_name regex to actual test_name
|
46
|
-
if type == 'spec' && test_name
|
47
|
-
test_name = find_example_in_spec(file, test_name) || test_name
|
48
|
-
end
|
49
|
-
|
50
41
|
#run the file
|
51
42
|
puts "running: #{file}"
|
52
43
|
ENV['RAILS_ENV'] = 'test' #current EVN['RAILS_ENV'] is 'development', and will also exist in all called commands
|
@@ -64,18 +55,15 @@ module SingleTest
|
|
64
55
|
]
|
65
56
|
end
|
66
57
|
|
58
|
+
# find files matching the given name,
|
59
|
+
# prefer lower folders and short names, since deep/long names
|
60
|
+
# can be found via a more precise search string
|
67
61
|
def find_test_file(type,file_name)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
found = FileList["#{base}#{exactness}_#{type}?rb"].first
|
74
|
-
return found if found
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
nil
|
62
|
+
regex = /#{file_name.gsub('*','.*').gsub('?','.')}/ # support *? syntax for search
|
63
|
+
all_tests(type).grep(regex).sort_by do |path|
|
64
|
+
parts = path.split('/')
|
65
|
+
[parts.size, parts.last.size]
|
66
|
+
end.first
|
79
67
|
end
|
80
68
|
|
81
69
|
def find_example_in_spec(file, test_name)
|
@@ -89,11 +77,12 @@ module SingleTest
|
|
89
77
|
case type.to_s
|
90
78
|
when 'test' then sh "ruby -Ilib:test #{file} -n /#{test_name}/"
|
91
79
|
when 'spec' then
|
80
|
+
executable = spec_executable
|
92
81
|
options_file = "spec/spec.opts"
|
93
82
|
options_file = (File.exist?(options_file) ? " --options #{options_file}" : "")
|
94
|
-
command = "export RAILS_ENV=test ; #{
|
95
|
-
command += (
|
96
|
-
command +=
|
83
|
+
command = "export RAILS_ENV=test ; #{executable}#{options_file} #{file}"
|
84
|
+
command += test_name_matcher(executable, file, test_name)
|
85
|
+
command += " -X" if ENV['X'] # run via drb ?
|
97
86
|
sh command
|
98
87
|
else raise "Unknown: #{type}"
|
99
88
|
end
|
@@ -118,6 +107,14 @@ module SingleTest
|
|
118
107
|
|
119
108
|
private
|
120
109
|
|
110
|
+
def test_name_matcher(executable, file, test_name)
|
111
|
+
if test_name and not executable.include?('rspec')
|
112
|
+
# rspec 1 only supports full test names -> find a matching test-name
|
113
|
+
test_name = find_example_in_spec(file, test_name) || test_name
|
114
|
+
end
|
115
|
+
test_name ? %Q( -e "#{test_name.sub('"',"\\\"")}") : ''
|
116
|
+
end
|
117
|
+
|
121
118
|
# copied from http://github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile
|
122
119
|
def self.bundler_enabled?
|
123
120
|
return true if Object.const_defined?(:Bundler)
|
data/single_test.gemspec
CHANGED
@@ -1,44 +1,42 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{single_test}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-16}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.files = [
|
15
15
|
"Gemfile",
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
"Gemfile.lock",
|
17
|
+
"Rakefile",
|
18
|
+
"Readme.md",
|
19
|
+
"VERSION",
|
20
|
+
"lib/single_test.rb",
|
21
|
+
"lib/tasks/single_test.rake",
|
22
|
+
"single_test.gemspec",
|
23
|
+
"spec/example_finder_test.txt",
|
24
|
+
"spec/single_test_spec.rb",
|
25
|
+
"spec/spec_helper.rb"
|
26
26
|
]
|
27
27
|
s.homepage = %q{http://github.com/grosser/single_test}
|
28
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
29
28
|
s.require_paths = ["lib"]
|
30
|
-
s.rubygems_version = %q{1.
|
29
|
+
s.rubygems_version = %q{1.4.2}
|
31
30
|
s.summary = %q{Rake tasks to invoke single tests/specs with rakish syntax}
|
32
31
|
s.test_files = [
|
33
32
|
"spec/single_test_spec.rb",
|
34
|
-
|
33
|
+
"spec/spec_helper.rb"
|
35
34
|
]
|
36
35
|
|
37
36
|
if s.respond_to? :specification_version then
|
38
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
37
|
s.specification_version = 3
|
40
38
|
|
41
|
-
if Gem::Version.new(Gem::
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
40
|
else
|
43
41
|
end
|
44
42
|
else
|
data/spec/single_test_spec.rb
CHANGED
@@ -60,15 +60,15 @@ describe SingleTest do
|
|
60
60
|
SingleTest.find_test_file('spec','xxx').should == 'spec/mixins/xxx_spec.rb'
|
61
61
|
end
|
62
62
|
|
63
|
-
it "finds
|
63
|
+
it "finds short matches first" do
|
64
64
|
make_file 'spec/models/xxx_spec.rb'
|
65
65
|
make_file 'spec/controllers/xxx_controller_spec.rb'
|
66
66
|
SingleTest.find_test_file('spec','xx').should == 'spec/models/xxx_spec.rb'
|
67
67
|
end
|
68
68
|
|
69
|
-
it "finds with
|
69
|
+
it "finds with wildcards" do
|
70
70
|
make_file 'spec/controllers/admin/xxx_controller_spec.rb'
|
71
|
-
SingleTest.find_test_file('spec','ad*/
|
71
|
+
SingleTest.find_test_file('spec','ad*/x?x').should == 'spec/controllers/admin/xxx_controller_spec.rb'
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -142,18 +142,28 @@ describe SingleTest do
|
|
142
142
|
SingleTest.run_test('spec','xxx')
|
143
143
|
end
|
144
144
|
|
145
|
-
it "runs
|
146
|
-
|
145
|
+
it "runs all matching specs through -e for rspec 2" do
|
146
|
+
File.should_receive(:file?).with('script/spec').and_return false
|
147
|
+
File.stub!(:readlines).and_return ['it "bla yyy" do']
|
148
|
+
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; bundle exec rspec xxx -e "yyy"')
|
149
|
+
SingleTest.run_test('spec','xxx', 'yyy')
|
150
|
+
end
|
151
|
+
|
152
|
+
it "runs full single specs through -e for rspec 1" do
|
153
|
+
File.stub!(:readlines).and_return ['it "bla yyy" do']
|
154
|
+
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; script/spec xxx -e "bla yyy"')
|
147
155
|
SingleTest.run_test('spec','xxx', 'yyy')
|
148
156
|
end
|
149
157
|
|
150
158
|
it "runs single specs through -e with -X" do
|
159
|
+
File.stub!(:readlines).and_return []
|
151
160
|
ENV['X']=''
|
152
161
|
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; script/spec xxx -e "yyy" -X')
|
153
162
|
SingleTest.run_test('spec','xxx', 'yyy')
|
154
163
|
end
|
155
164
|
|
156
165
|
it "runs quoted specs though -e" do
|
166
|
+
File.stub!(:readlines).and_return []
|
157
167
|
SingleTest.should_receive(:sh).with(%Q(export RAILS_ENV=test ; script/spec xxx -e "y\\\"yy"))
|
158
168
|
SingleTest.run_test('spec','xxx', 'y"yy')
|
159
169
|
end
|
@@ -167,23 +177,24 @@ describe SingleTest do
|
|
167
177
|
it "runs with bundled spec if script/spec is not found" do
|
168
178
|
File.stub!(:file?).and_return false
|
169
179
|
File.should_receive(:file?).with('script/spec').and_return false
|
170
|
-
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; bundle exec
|
180
|
+
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; bundle exec rspec xxx')
|
171
181
|
SingleTest.run_test('spec','xxx')
|
172
182
|
end
|
173
183
|
|
174
184
|
it "uses bundler if Gemfile is present" do
|
175
185
|
File.stub!(:file?).and_return false
|
176
186
|
SingleTest.should_receive(:bundler_enabled?).and_return true
|
177
|
-
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; bundle exec
|
187
|
+
SingleTest.should_receive(:sh).with('export RAILS_ENV=test ; bundle exec rspec xxx')
|
178
188
|
SingleTest.run_test('spec','xxx')
|
179
189
|
end
|
180
190
|
end
|
181
191
|
|
182
192
|
describe :load_tasks do
|
183
193
|
it "can load em" do
|
184
|
-
|
194
|
+
result = Rake::Task['spec:one_by_one'] rescue nil
|
195
|
+
result.should == nil
|
185
196
|
SingleTest.load_tasks
|
186
197
|
Rake::Task['spec:one_by_one'].should_not == nil
|
187
198
|
end
|
188
199
|
end
|
189
|
-
end
|
200
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,7 @@ SPEC_ROOT = File.dirname(__FILE__)
|
|
3
3
|
$LOAD_PATH << File.expand_path("../lib", SPEC_ROOT)
|
4
4
|
|
5
5
|
# ---- rspec
|
6
|
-
|
6
|
+
RSpec.configure do |config|
|
7
7
|
config.before do
|
8
8
|
`mkdir -p #{SPEC_ROOT}/script`
|
9
9
|
`touch #{SPEC_ROOT}/script/spec`
|
@@ -13,4 +13,4 @@ Spec::Runner.configure do |config|
|
|
13
13
|
`rm -rf #{SPEC_ROOT}/app`
|
14
14
|
`rm -rf #{SPEC_ROOT}/spec`
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: single_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Grosser
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-04-16 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -43,28 +44,32 @@ homepage: http://github.com/grosser/single_test
|
|
43
44
|
licenses: []
|
44
45
|
|
45
46
|
post_install_message:
|
46
|
-
rdoc_options:
|
47
|
-
|
47
|
+
rdoc_options: []
|
48
|
+
|
48
49
|
require_paths:
|
49
50
|
- lib
|
50
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
51
53
|
requirements:
|
52
54
|
- - ">="
|
53
55
|
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
54
57
|
segments:
|
55
58
|
- 0
|
56
59
|
version: "0"
|
57
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
58
62
|
requirements:
|
59
63
|
- - ">="
|
60
64
|
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
61
66
|
segments:
|
62
67
|
- 0
|
63
68
|
version: "0"
|
64
69
|
requirements: []
|
65
70
|
|
66
71
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.4.2
|
68
73
|
signing_key:
|
69
74
|
specification_version: 3
|
70
75
|
summary: Rake tasks to invoke single tests/specs with rakish syntax
|