splot 0.0.1 → 0.5.1
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.
- checksums.yaml +4 -4
- data/Rakefile +15 -0
- data/bin/splot +6 -83
- data/lib/splot.rb +24 -1
- data/lib/splot/command.rb +167 -0
- data/lib/splot/corresponding_file.rb +36 -0
- data/lib/splot/runner.rb +39 -0
- data/lib/splot/version.rb +1 -1
- data/test/corresponding_file_test.rb +80 -0
- data/test/fixtures/activesupport_example_test.rb +10 -0
- data/test/fixtures/fake_test_helper.rb +2 -0
- data/test/fixtures/test_unit_example_test.rb +10 -0
- data/test/splot_test.rb +117 -0
- data/test/test_helper.rb +13 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7239341b56f137cc8eb9e3ee90ad87f963c7be2
|
4
|
+
data.tar.gz: 1374d68cb52b2b77279b08e349a3ceae0de2402d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34b95e19ee56c4350fb7817d3f584076700a6f0d19b6f69807a70f15e9d5682ed6009366d9f29ba42e753f55eac4e9309bc46008fa397f22c8c65fbf9dddc2f7
|
7
|
+
data.tar.gz: b15e8603ce6d104a9084523831bfad7adcd51826b344a04558aa22f195185b9189d63b961f07783a91ad465c3492e9970d42da97ec45503dcd5fea668434cbc6
|
data/Rakefile
CHANGED
@@ -1 +1,16 @@
|
|
1
|
+
require "rake/testtask"
|
1
2
|
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
ENV['COVERAGE'] = '1'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.pattern = 'test/*_test.rb'
|
8
|
+
t.libs << 'test'
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Update ctags"
|
12
|
+
task :ctags do
|
13
|
+
`ctags -R --languages=Ruby --totals -f tags`
|
14
|
+
end
|
15
|
+
|
16
|
+
task default: :test
|
data/bin/splot
CHANGED
@@ -1,87 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
OptionParser.new do |opts|
|
9
|
-
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]"
|
10
|
-
|
11
|
-
opts.on('-f', '--file FILE', 'Run test for a given FILE') do |file|
|
12
|
-
options[:file] = file
|
13
|
-
end
|
14
|
-
|
15
|
-
opts.on('-l', '--line LINE', 'Only run test on LINE') do |line|
|
16
|
-
options[:line] = line.to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
opts.on('-p', '--preloader PRELOADER', 'Use e.g. zeus or spring to preload the environment') do |preloader|
|
20
|
-
options[:preloader] = preloader
|
21
|
-
end
|
22
|
-
end.parse!
|
23
|
-
|
24
|
-
module ContextTest
|
25
|
-
extend self
|
26
|
-
|
27
|
-
module MinitestCommand
|
28
|
-
extend self
|
29
|
-
|
30
|
-
ACTIVE_SUPPORT_TEST_CASE_MATCHER = %r{
|
31
|
-
\A\s*test\s+ # test
|
32
|
-
(?: #
|
33
|
-
"(?<double_quote>.*)" # "it should work"
|
34
|
-
| # OR
|
35
|
-
'(?<single_quote>.*)' # 'it should work'
|
36
|
-
) #
|
37
|
-
\s+do\s*\Z # do\n
|
38
|
-
}x
|
39
|
-
|
40
|
-
TEST_UNIT_MATCHER = %r{
|
41
|
-
\A\s*def\s+ # def
|
42
|
-
(?<test_name> #
|
43
|
-
test_ # test_
|
44
|
-
[a-zA-Z_]+ # it_should_work
|
45
|
-
[\?!=]? # ?
|
46
|
-
) #
|
47
|
-
\s*\Z # \n
|
48
|
-
}x
|
49
|
-
|
50
|
-
def command(file: nil, line: nil, preloader: nil)
|
51
|
-
command = [preloader, "rake test"].compact
|
52
|
-
command << file if file
|
53
|
-
command << parse_line(file, line) if line
|
54
|
-
command.join ' '
|
55
|
-
end
|
56
|
-
|
57
|
-
def parse_line(file, line)
|
58
|
-
test_name = nil
|
59
|
-
line_no = 0
|
60
|
-
File.open file do |io|
|
61
|
-
until io.eof?
|
62
|
-
line_text = io.gets
|
63
|
-
line_no += 1
|
64
|
-
line_text.match ACTIVE_SUPPORT_TEST_CASE_MATCHER do |matches|
|
65
|
-
match = matches[:double_quote] || matches[:single_quote]
|
66
|
-
test_name = "test_#{match.gsub(/\s+/, '_')}"
|
67
|
-
end
|
68
|
-
line_text.match TEST_UNIT_MATCHER do |matches|
|
69
|
-
test_name = matches[:test_name]
|
70
|
-
end
|
71
|
-
return to_arg(test_name) if line_no == line && test_name
|
72
|
-
end
|
73
|
-
end
|
74
|
-
fail "Could not find test for line #{line} of file #{file}"
|
75
|
-
end
|
76
|
-
|
77
|
-
def to_arg(test_name)
|
78
|
-
"TESTOPTS=\"-n #{test_name}\""
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def run(str)
|
83
|
-
exec str
|
84
|
-
end
|
3
|
+
begin
|
4
|
+
require "splot"
|
5
|
+
rescue LoadError
|
6
|
+
require "rubygems"
|
7
|
+
require "splot"
|
85
8
|
end
|
86
9
|
|
87
|
-
|
10
|
+
Kernel.exec Splot.build_command_from_argv
|
data/lib/splot.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
|
+
require "optparse"
|
2
|
+
require "pathname"
|
3
|
+
|
1
4
|
require "splot/version"
|
2
5
|
|
3
6
|
module Splot
|
4
|
-
|
7
|
+
autoload :Command, "splot/command"
|
8
|
+
autoload :CorrespondingFile, "splot/corresponding_file"
|
9
|
+
autoload :Runner, "splot/runner"
|
10
|
+
|
11
|
+
RunnerNotFoundError = Class.new StandardError
|
12
|
+
|
13
|
+
def self.command(params = {})
|
14
|
+
new_file = CorrespondingFile.fetch params[:file]
|
15
|
+
unless new_file == params[:file]
|
16
|
+
params[:file] = new_file
|
17
|
+
params.delete(:line)
|
18
|
+
end
|
19
|
+
Command.for(params[:file]).new(params).command
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.build_command_from_argv
|
23
|
+
Runner.new.tap(&:parse).command
|
24
|
+
rescue RunnerNotFoundError => e
|
25
|
+
warn "Warning: #{e}; will not run any test"
|
26
|
+
exit 2
|
27
|
+
end
|
5
28
|
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
module Splot
|
2
|
+
class Command
|
3
|
+
attr :include_path, :line_no, :file, :preloader
|
4
|
+
|
5
|
+
def initialize(params = {})
|
6
|
+
@file = params.fetch(:file).to_str
|
7
|
+
@include_path = params[:include_path]
|
8
|
+
@line_no = Integer(params[:line]) if params.has_key? :line
|
9
|
+
@preloader = params[:preloader].to_str if params.has_key? :preloader
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.for(file)
|
13
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }.each do |subklass|
|
14
|
+
return subklass if subklass.match? file
|
15
|
+
end
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.match?(file)
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def command
|
24
|
+
[
|
25
|
+
preloader, # "spring"
|
26
|
+
runner, # "rake test"
|
27
|
+
include_args, # "-Itest"
|
28
|
+
file_arg, # "TEST=\"/path/to/test.rb\""
|
29
|
+
line_no_arg, # "TESTOPTS=\"-n test_foo\""
|
30
|
+
].compact * ' '
|
31
|
+
end
|
32
|
+
|
33
|
+
def file_arg
|
34
|
+
file
|
35
|
+
end
|
36
|
+
|
37
|
+
def include_args
|
38
|
+
include_path ? "-I#{include_path}" : nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def line_no_arg
|
42
|
+
line_no ? "-l #{line_no}" : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def runner
|
46
|
+
raise RunnerNotFoundError, "cannot determine runner for #{file.inspect}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class CucumberCommand < Command
|
51
|
+
def self.match?(file)
|
52
|
+
file.match %r{\.feature\Z}
|
53
|
+
end
|
54
|
+
|
55
|
+
def include_args
|
56
|
+
return super if include_path.nil?
|
57
|
+
raise ArgumentError, "Cucumber does not support include arguments"
|
58
|
+
end
|
59
|
+
|
60
|
+
def runner
|
61
|
+
'cucumber'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class RSpecCommand < Command
|
66
|
+
def self.match?(file)
|
67
|
+
file.match /\_spec\.rb\Z/
|
68
|
+
end
|
69
|
+
|
70
|
+
def runner
|
71
|
+
'rspec'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class TestUnitCommand < Command
|
76
|
+
|
77
|
+
ACTIVE_SUPPORT_TEST_CASE_MATCHER = %r{
|
78
|
+
\A\s*test\s+ # test
|
79
|
+
(?: #
|
80
|
+
"(?<double_quote>.*)" # "it should work"
|
81
|
+
| # OR
|
82
|
+
'(?<single_quote>.*)' # 'it should work'
|
83
|
+
) #
|
84
|
+
\s+do\s*\Z # do\n
|
85
|
+
}x
|
86
|
+
|
87
|
+
TEST_UNIT_MATCHER = %r{
|
88
|
+
\A\s*def\s+ # def
|
89
|
+
(?<test_name> #
|
90
|
+
test_ # test_
|
91
|
+
[a-zA-Z_]+ # it_should_work
|
92
|
+
[\?!=]? # ?
|
93
|
+
) #
|
94
|
+
\s*\Z # \n
|
95
|
+
}x
|
96
|
+
|
97
|
+
def initialize(params = {})
|
98
|
+
@runner = params.fetch(:runner) { "rake test" }
|
99
|
+
super
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.match?(file)
|
103
|
+
file.match /\_test\.rb/
|
104
|
+
end
|
105
|
+
|
106
|
+
def file_arg
|
107
|
+
if rake?
|
108
|
+
"TEST=#{file}"
|
109
|
+
else
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def rake?
|
115
|
+
runner == "rake test"
|
116
|
+
end
|
117
|
+
|
118
|
+
def runner
|
119
|
+
@runner
|
120
|
+
end
|
121
|
+
|
122
|
+
def line_no_arg
|
123
|
+
test_name = catch(:test_name) { fetch_test_name }
|
124
|
+
return nil if test_name.nil?
|
125
|
+
arg = "--name=#{test_name}"
|
126
|
+
rake? ? "TESTOPTS=#{arg.inspect}" : arg
|
127
|
+
end
|
128
|
+
|
129
|
+
def fetch_test_name
|
130
|
+
return nil if line_no.nil?
|
131
|
+
current_test_name = nil
|
132
|
+
read_file do |current_line_no, line|
|
133
|
+
match_test_method(line) { |match| current_test_name = match }
|
134
|
+
throw :test_name, current_test_name if current_line_no == line_no
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def match_test_method(line, &block)
|
139
|
+
match_active_support line, &block
|
140
|
+
match_test_unit line, &block
|
141
|
+
end
|
142
|
+
|
143
|
+
def match_active_support(line)
|
144
|
+
line.match ACTIVE_SUPPORT_TEST_CASE_MATCHER do |matches|
|
145
|
+
quoted_bit = matches[:double_quote] || matches[:single_quote]
|
146
|
+
yield "test_#{quoted_bit.gsub(/\s+/, '_')}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def match_test_unit(line)
|
151
|
+
line.match TEST_UNIT_MATCHER do |matches|
|
152
|
+
yield matches[:test_name]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def read_file
|
157
|
+
current_line_no = 0
|
158
|
+
File.open file do |io|
|
159
|
+
until io.eof?
|
160
|
+
current_line_no += 1
|
161
|
+
line_text = io.gets
|
162
|
+
yield current_line_no, line_text
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Splot
|
2
|
+
class CorrespondingFile
|
3
|
+
def self.fetch(file)
|
4
|
+
catch :test_file do
|
5
|
+
root_path = Pathname.new File.expand_path Dir.pwd
|
6
|
+
file_path = Pathname.new File.expand_path file
|
7
|
+
relative_path = file_path.relative_path_from(root_path).to_s
|
8
|
+
if %r{\Alib/(?<bit>.*)\.rb} =~ relative_path
|
9
|
+
['test', 'spec'].each do |e|
|
10
|
+
try_file "#{e}/lib/#{bit}_#{e}.rb"
|
11
|
+
try_file "#{e}/#{bit}_#{e}.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
if %r{\Aapp/(?<subdir>[a-z_]+)/(?<bit>.*)\.rb} =~ relative_path
|
15
|
+
['test', 'spec'].each do |e|
|
16
|
+
alternate_subdir = {
|
17
|
+
models: "unit",
|
18
|
+
controllers: "functional",
|
19
|
+
}[subdir.to_sym]
|
20
|
+
try_file "#{e}/#{subdir}/#{bit}_#{e}.rb"
|
21
|
+
try_file "#{e}/#{alternate_subdir}/#{bit}_#{e}.rb" if alternate_subdir
|
22
|
+
end
|
23
|
+
end
|
24
|
+
file
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.try_file(test_path)
|
29
|
+
throw :test_file, test_path if file_exists? test_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.file_exists?(file)
|
33
|
+
File.size? file
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/splot/runner.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Splot
|
2
|
+
class Runner
|
3
|
+
attr :params
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@params = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def command
|
10
|
+
::Splot.command params
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]"
|
16
|
+
|
17
|
+
opts.on('-f', '--file FILE', 'Run test for a given FILE') do |file|
|
18
|
+
params[:file] = file
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-i', '--include-path PATH', 'Add an include PATH') do |path|
|
22
|
+
params[:include_path] = path
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-l', '--line LINE', 'Only run test on LINE') do |line|
|
26
|
+
params[:line] = line.to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-r', '--runner RUNNER', 'Specify alternate runner') do |runner|
|
30
|
+
params[:runner] = runner
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-p', '--preloader PRELOADER', 'Use e.g. zeus or spring to preload the environment') do |preloader|
|
34
|
+
params[:preloader] = preloader
|
35
|
+
end
|
36
|
+
end.parse!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/splot/version.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CorrespondingFileTest < Minitest::Test
|
4
|
+
include Splot
|
5
|
+
|
6
|
+
def test_looks_in_test_and_spec_when_file_is_in_lib
|
7
|
+
mock_files_existing "test/my_class_test.rb" do
|
8
|
+
assert_equal "test/my_class_test.rb",
|
9
|
+
CorrespondingFile.fetch("lib/my_class.rb")
|
10
|
+
end
|
11
|
+
mock_files_existing "spec/my_class_spec.rb" do
|
12
|
+
assert_equal "spec/my_class_spec.rb",
|
13
|
+
CorrespondingFile.fetch("lib/my_class.rb")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_lib_directory_priority
|
18
|
+
mock_files_existing "test/my_class_test.rb", "test/lib/my_class_test.rb" do
|
19
|
+
assert_equal "test/lib/my_class_test.rb",
|
20
|
+
CorrespondingFile.fetch("lib/my_class.rb")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_namespacing
|
25
|
+
mock_files_existing "test/lib/my_namespace/my_class_test.rb" do
|
26
|
+
assert_equal "test/lib/my_namespace/my_class_test.rb",
|
27
|
+
CorrespondingFile.fetch("lib/my_namespace/my_class.rb")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_rails_models
|
32
|
+
mock_files_existing "test/unit/my_model_test.rb" do
|
33
|
+
assert_equal "test/unit/my_model_test.rb",
|
34
|
+
CorrespondingFile.fetch("app/models/my_model.rb")
|
35
|
+
end
|
36
|
+
mock_files_existing "test/models/my_model_test.rb" do
|
37
|
+
assert_equal "test/models/my_model_test.rb",
|
38
|
+
CorrespondingFile.fetch("app/models/my_model.rb")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rails_controllers
|
43
|
+
mock_files_existing "test/functional/my_controller_test.rb" do
|
44
|
+
assert_equal "test/functional/my_controller_test.rb",
|
45
|
+
CorrespondingFile.fetch("app/controllers/my_controller.rb")
|
46
|
+
end
|
47
|
+
mock_files_existing "test/controllers/my_controller_test.rb" do
|
48
|
+
assert_equal "test/controllers/my_controller_test.rb",
|
49
|
+
CorrespondingFile.fetch("app/controllers/my_controller.rb")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_rails_custom_app_load_path
|
54
|
+
mock_files_existing "test/services/my_service_test.rb" do
|
55
|
+
assert_equal "test/services/my_service_test.rb",
|
56
|
+
CorrespondingFile.fetch("app/services/my_service.rb")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def mock_files_existing(*files)
|
63
|
+
File.singleton_class.class_eval <<-CLASS_EVAL, __FILE__, __LINE__
|
64
|
+
alias_method :size_orig?, :size?
|
65
|
+
|
66
|
+
def size?(file) # def size?(file)
|
67
|
+
#{files.inspect}.include?(file) # ["fileA", "my/fileB"].include?(file)
|
68
|
+
end # end
|
69
|
+
CLASS_EVAL
|
70
|
+
|
71
|
+
begin
|
72
|
+
yield
|
73
|
+
ensure
|
74
|
+
File.singleton_class.class_eval <<-CLASS_EVAL, __FILE__, __LINE__
|
75
|
+
alias_method :size?, :size_orig?
|
76
|
+
undef :size_orig?
|
77
|
+
CLASS_EVAL
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/test/splot_test.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SplotTest < Minitest::Test
|
4
|
+
def test_binary
|
5
|
+
assert_equal 0, run_binary(runner: "ruby", include_path: "test/fixtures", file: "test/fixtures/test_unit_example_test.rb", line: 5)
|
6
|
+
refute_equal 0, run_binary(runner: "ruby", include_path: "test/fixtures", file: "test/fixtures/test_unit_example_test.rb", line: 8)
|
7
|
+
assert_equal 2, run_binary(runner: "ruby", include_path: "test/fixtures", file: "non/existent/file.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_test_unit
|
11
|
+
assert_equal "rake test TEST=test/fixtures/test_unit_example_test.rb",
|
12
|
+
Splot.command(file: test_unit_rb)
|
13
|
+
|
14
|
+
assert_equal "rake test TEST=test/fixtures/test_unit_example_test.rb TESTOPTS=\"--name=test_always_passes\"",
|
15
|
+
Splot.command(file: test_unit_rb, line: 5)
|
16
|
+
assert_equal "rake test TEST=test/fixtures/test_unit_example_test.rb TESTOPTS=\"--name=test_always_fails\"",
|
17
|
+
Splot.command(file: test_unit_rb, line: 8)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_test_unit_with_ruby_runner
|
21
|
+
assert_equal "ruby test/fixtures/test_unit_example_test.rb",
|
22
|
+
Splot.command(runner: "ruby", file: test_unit_rb)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_test_unit_with_invalid_line_numbers
|
26
|
+
assert_equal "rake test TEST=test/fixtures/test_unit_example_test.rb",
|
27
|
+
Splot.command(file: test_unit_rb, line: 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_activesupport_test_unit
|
31
|
+
assert_equal "rake test TEST=test/fixtures/activesupport_example_test.rb",
|
32
|
+
Splot.command(file: activesupport_test_rb)
|
33
|
+
|
34
|
+
assert_equal "rake test TEST=test/fixtures/activesupport_example_test.rb TESTOPTS=\"--name=test_will_always_pass\"",
|
35
|
+
Splot.command(file: activesupport_test_rb, line: 5)
|
36
|
+
assert_equal "rake test TEST=test/fixtures/activesupport_example_test.rb TESTOPTS=\"--name=test_will_always_fail\"",
|
37
|
+
Splot.command(file: activesupport_test_rb, line: 8)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_cucumber
|
41
|
+
assert_equal "cucumber path/to/cucumber_example.feature",
|
42
|
+
Splot.command(file: cucumber_feature)
|
43
|
+
|
44
|
+
assert_equal "cucumber path/to/cucumber_example.feature -l 2",
|
45
|
+
Splot.command(file: cucumber_feature, line: 2)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_rspec
|
49
|
+
assert_equal "rspec path/to/rspec_example_spec.rb",
|
50
|
+
Splot.command(file: rspec_spec_rb)
|
51
|
+
|
52
|
+
assert_equal "rspec path/to/rspec_example_spec.rb -l 3",
|
53
|
+
Splot.command(file: rspec_spec_rb, line: 3)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_unknown
|
57
|
+
assert_raises Splot::RunnerNotFoundError do
|
58
|
+
Splot.command file: "path/to/any_old_ruby_file.rb"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_preloader
|
63
|
+
assert_equal "spring rspec my_spec.rb",
|
64
|
+
Splot.command(file: "my_spec.rb", preloader: "spring")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_adding_include_paths
|
68
|
+
assert_equal "rake test -Imy_lib_dir TEST=test/fixtures/test_unit_example_test.rb",
|
69
|
+
Splot.command(file: test_unit_rb, include_path: "my_lib_dir")
|
70
|
+
assert_equal "rspec -Imy_lib_dir path/to/rspec_example_spec.rb",
|
71
|
+
Splot.command(file: rspec_spec_rb, include_path: "my_lib_dir")
|
72
|
+
assert_raises ArgumentError do
|
73
|
+
assert_equal "cucumber -Imy_lib_dir TEST=path/to/cucumber_example.feature",
|
74
|
+
Splot.command(file: cucumber_feature, include_path: "my_lib_dir")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_lib_files_automatically_translate_to_corresponding_test
|
79
|
+
assert_equal "rake test TEST=test/splot_test.rb",
|
80
|
+
Splot.command(file: "lib/splot.rb")
|
81
|
+
# Forget the line number when we change files
|
82
|
+
assert_equal "rake test TEST=test/splot_test.rb",
|
83
|
+
Splot.command(file: "lib/splot.rb", line: 5)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def run_binary(params = {})
|
89
|
+
Process::fork do
|
90
|
+
command = params.each_with_object 'bin/splot' do |(k,v), str|
|
91
|
+
str << " --#{k.to_s.gsub('_', '-')} #{v}"
|
92
|
+
end
|
93
|
+
$stdout.reopen File.open("/dev/null", "w+")
|
94
|
+
$stderr.reopen File.open("/dev/null", "w+")
|
95
|
+
command.insert 0, "RUBYLIB=#{File.expand_path('../../lib', __FILE__)}:$RUBYLIB "
|
96
|
+
exec command
|
97
|
+
end
|
98
|
+
Process::wait
|
99
|
+
$?.exitstatus
|
100
|
+
end
|
101
|
+
|
102
|
+
def activesupport_test_rb
|
103
|
+
"test/fixtures/activesupport_example_test.rb"
|
104
|
+
end
|
105
|
+
|
106
|
+
def cucumber_feature
|
107
|
+
"path/to/cucumber_example.feature"
|
108
|
+
end
|
109
|
+
|
110
|
+
def rspec_spec_rb
|
111
|
+
"path/to/rspec_example_spec.rb"
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_unit_rb
|
115
|
+
"test/fixtures/test_unit_example_test.rb"
|
116
|
+
end
|
117
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'simplecov' if ENV['COVERAGE']
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/reporters'
|
6
|
+
|
7
|
+
require 'ostruct'
|
8
|
+
require 'pp'
|
9
|
+
require 'stringio'
|
10
|
+
|
11
|
+
require 'splot'
|
12
|
+
|
13
|
+
Minitest::Reporters.use! MiniTest::Reporters::DefaultReporter.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ntl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,8 +109,17 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- bin/splot
|
111
111
|
- lib/splot.rb
|
112
|
+
- lib/splot/command.rb
|
113
|
+
- lib/splot/corresponding_file.rb
|
114
|
+
- lib/splot/runner.rb
|
112
115
|
- lib/splot/version.rb
|
113
116
|
- splot.gemspec
|
117
|
+
- test/corresponding_file_test.rb
|
118
|
+
- test/fixtures/activesupport_example_test.rb
|
119
|
+
- test/fixtures/fake_test_helper.rb
|
120
|
+
- test/fixtures/test_unit_example_test.rb
|
121
|
+
- test/splot_test.rb
|
122
|
+
- test/test_helper.rb
|
114
123
|
homepage: ''
|
115
124
|
licenses:
|
116
125
|
- MIT
|
@@ -135,4 +144,10 @@ rubygems_version: 2.1.11
|
|
135
144
|
signing_key:
|
136
145
|
specification_version: 4
|
137
146
|
summary: Run any test from any file from any project :)
|
138
|
-
test_files:
|
147
|
+
test_files:
|
148
|
+
- test/corresponding_file_test.rb
|
149
|
+
- test/fixtures/activesupport_example_test.rb
|
150
|
+
- test/fixtures/fake_test_helper.rb
|
151
|
+
- test/fixtures/test_unit_example_test.rb
|
152
|
+
- test/splot_test.rb
|
153
|
+
- test/test_helper.rb
|