splot 0.5.4 → 0.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a02e6293df35f85f64deee512f9cf1578ed9ff5e
4
- data.tar.gz: 4d6a6370d513eae9ba1f8d90ef298490132cffdc
3
+ metadata.gz: e923fdd3cece99b795b726968ab664c2b5f85735
4
+ data.tar.gz: 5a97b017eb3ac14269012ab42f6afcdb3c6be1cf
5
5
  SHA512:
6
- metadata.gz: f46537a99393fe4abe1cbd8463269e0507e94f820a807017de0d1b97c2154d4c8e1e1e912387260907403a067aabbfa770eef5b8c052405144c0f564e9c7ed8a
7
- data.tar.gz: 6b8bb95b26328f36a6ac07adbb1866484714a3add2681831477fab6687258b7d9180adefc42da91ac5a54053b6c7041ef0221aa92effa98bcd9c18b9cbc344ed
6
+ metadata.gz: 303d126166adb7a7d324020c7972fb479dc1b1ab798e5b8c94d6a47e7b37d77e954e43ffd966979b71d951357f0c5fc1abb878826c43a763c06688586e90cb52
7
+ data.tar.gz: c7aa78bc509abc917051e998e12aa61e8a3ccce8de7498c2a8974193d7ddcfbbf4e2c8b14882d3192c981e03b25c9cbcae5d2f143af00adf1578e9bce83669fc
data/bin/splot CHANGED
@@ -7,4 +7,4 @@ rescue LoadError
7
7
  require "splot"
8
8
  end
9
9
 
10
- Splot.exec_command_from_argv
10
+ Splot::Runner.run!
@@ -1,6 +1,8 @@
1
1
  module Splot
2
- class CorrespondingFile
3
- def self.fetch(file)
2
+ module CorrespondingFile
3
+ extend self
4
+
5
+ def fetch(file)
4
6
  catch :test_file do
5
7
  root_path = Pathname.new File.expand_path Dir.pwd
6
8
  file_path = Pathname.new File.expand_path file
@@ -9,6 +11,9 @@ module Splot
9
11
  ['test', 'spec'].each do |e|
10
12
  try_file "#{e}/lib/#{bit}_#{e}.rb"
11
13
  try_file "#{e}/#{bit}_#{e}.rb"
14
+ bit_without_gem_name = extract_gem_name bit
15
+ try_file "#{e}/lib/#{bit_without_gem_name}_#{e}.rb"
16
+ try_file "#{e}/#{bit_without_gem_name}_#{e}.rb"
12
17
  end
13
18
  end
14
19
  if %r{\Aapp/(?<subdir>[a-z_]+)/(?<bit>.*)\.rb} =~ relative_path
@@ -25,11 +30,16 @@ module Splot
25
30
  end
26
31
  end
27
32
 
28
- def self.try_file(test_path)
33
+ # my_gem/foo.rb -> foo.rb
34
+ def extract_gem_name(lib_file)
35
+ File.join File.split(lib_file).tap(&:shift)
36
+ end
37
+
38
+ def try_file(test_path)
29
39
  throw :test_file, test_path if file_exists? test_path
30
40
  end
31
41
 
32
- def self.file_exists?(file)
42
+ def file_exists?(file)
33
43
  File.size? file
34
44
  end
35
45
  end
data/lib/splot/runner.rb CHANGED
@@ -2,6 +2,10 @@ module Splot
2
2
  class Runner
3
3
  attr :params
4
4
 
5
+ def self.run!
6
+ new.tap(&:parse).run!
7
+ end
8
+
5
9
  def initialize
6
10
  @params = {}
7
11
  end
@@ -45,6 +49,13 @@ module Splot
45
49
  params[:config_file] = splotrc if File.size? splotrc
46
50
  end
47
51
 
52
+ def run!
53
+ Kernel.exec command
54
+ rescue RunnerNotFoundError => e
55
+ warn "Warning: #{e}; will not run any test"
56
+ exit 2
57
+ end
58
+
48
59
  private
49
60
 
50
61
  def splotrc
data/lib/splot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Splot
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
data/lib/splot.rb CHANGED
@@ -21,11 +21,4 @@ module Splot
21
21
  Command.for(params[:file]).new(params).command
22
22
  end
23
23
 
24
- def self.exec_command_from_argv
25
- command = Runner.new.tap(&:parse).command
26
- Kernel.exec command
27
- rescue RunnerNotFoundError => e
28
- warn "Warning: #{e}; will not run any test"
29
- exit 2
30
- end
31
24
  end
@@ -21,6 +21,13 @@ class CorrespondingFileTest < Minitest::Test
21
21
  end
22
22
  end
23
23
 
24
+ def test_gem_lib_dir
25
+ mock_files_existing "test/my_class_test.rb" do
26
+ assert_equal "test/my_class_test.rb",
27
+ CorrespondingFile.fetch("lib/gem_name/my_class.rb")
28
+ end
29
+ end
30
+
24
31
  def test_namespacing
25
32
  mock_files_existing "test/lib/my_namespace/my_class_test.rb" do
26
33
  assert_equal "test/lib/my_namespace/my_class_test.rb",
@@ -56,25 +63,4 @@ class CorrespondingFileTest < Minitest::Test
56
63
  CorrespondingFile.fetch("app/services/my_service.rb")
57
64
  end
58
65
  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
66
  end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class RunnerTest < Minitest::Test
4
+
5
+ def setup
6
+ @runner = Splot::Runner.new
7
+ end
8
+
9
+ def test_config_file_set_if_present
10
+ mock_files_existing ".splotrc" do
11
+ @runner.parse_splotrc
12
+ assert_equal ".splotrc", @runner.params[:config_file]
13
+ end
14
+ end
15
+
16
+ def test_config_file_not_set_if_not_present
17
+ @runner.parse_splotrc
18
+ refute_equal ".splotrc", @runner.params[:config_file]
19
+ end
20
+
21
+ end
data/test/splot_test.rb CHANGED
@@ -2,9 +2,8 @@ require "test_helper"
2
2
 
3
3
  class SplotTest < Minitest::Test
4
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")
5
+ assert_equal 0, run_binary("-r ruby --include-path test/fixtures -f test/fixtures/test_unit_example_test.rb --line 5")
6
+ refute_equal 0, run_binary("-r ruby --include-path test/fixtures -f test/fixtures/test_unit_example_test.rb --line 8")
8
7
  end
9
8
 
10
9
  def test_test_unit
@@ -91,21 +90,18 @@ class SplotTest < Minitest::Test
91
90
  def test_auto_loads_dot_splotrc
92
91
  splotrc = File.expand_path('../../.splotrc', __FILE__)
93
92
  File.write splotrc, "include_path: test/fixtures"
94
- assert_equal 0, run_binary(runner: "ruby", file: "test/fixtures/test_unit_example_test.rb", line: 5)
93
+ assert_equal 0, run_binary("-r ruby -f test/fixtures/test_unit_example_test.rb --line 5")
95
94
  ensure
96
95
  File.unlink splotrc if File.exist? splotrc
97
96
  end
98
97
 
99
98
  private
100
99
 
101
- def run_binary(params = {})
100
+ def run_binary(command)
102
101
  Process::fork do
103
- command = params.each_with_object 'bin/splot' do |(k,v), str|
104
- str << " --#{k.to_s.gsub('_', '-')} #{v}"
105
- end
102
+ command.insert 0, "RUBYLIB=#{File.expand_path('../../lib', __FILE__)}:$RUBYLIB bin/splot "
106
103
  $stdout.reopen File.open("/dev/null", "w+")
107
104
  $stderr.reopen File.open("/dev/null", "w+")
108
- command.insert 0, "RUBYLIB=#{File.expand_path('../../lib', __FILE__)}:$RUBYLIB "
109
105
  exec command
110
106
  end
111
107
  Process::wait
data/test/test_helper.rb CHANGED
@@ -11,3 +11,26 @@ require 'stringio'
11
11
  require 'splot'
12
12
 
13
13
  Minitest::Reporters.use! MiniTest::Reporters::DefaultReporter.new
14
+
15
+ class Minitest::Test
16
+ private
17
+
18
+ def mock_files_existing(*files)
19
+ File.singleton_class.class_eval <<-CLASS_EVAL, __FILE__, __LINE__
20
+ alias_method :size_orig?, :size?
21
+
22
+ def size?(file) # def size?(file)
23
+ #{files.inspect}.include?(file) # ["fileA", "my/fileB"].include?(file)
24
+ end # end
25
+ CLASS_EVAL
26
+
27
+ begin
28
+ yield
29
+ ensure
30
+ File.singleton_class.class_eval <<-CLASS_EVAL, __FILE__, __LINE__
31
+ alias_method :size?, :size_orig?
32
+ undef :size_orig?
33
+ CLASS_EVAL
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ntl
@@ -122,6 +122,7 @@ files:
122
122
  - test/fixtures/config_example_rc
123
123
  - test/fixtures/fake_test_helper.rb
124
124
  - test/fixtures/test_unit_example_test.rb
125
+ - test/runner_test.rb
125
126
  - test/splot_test.rb
126
127
  - test/test_helper.rb
127
128
  - tmp/.gitkeep
@@ -155,5 +156,6 @@ test_files:
155
156
  - test/fixtures/config_example_rc
156
157
  - test/fixtures/fake_test_helper.rb
157
158
  - test/fixtures/test_unit_example_test.rb
159
+ - test/runner_test.rb
158
160
  - test/splot_test.rb
159
161
  - test/test_helper.rb