File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717 runs-on : ubuntu-latest
1818 name : Ruby ${{ matrix.ruby }}
1919 strategy :
20+ fail-fast : false
2021 matrix :
2122 ruby :
2223 - " 2.7.0"
Original file line number Diff line number Diff line change @@ -3,3 +3,12 @@ inherit_gem:
33
44Metrics/MethodLength :
55 Enabled : false
6+
7+ Metrics/BlockLength :
8+ Enabled : false
9+
10+ Metrics/AbcSize :
11+ Enabled : false
12+
13+ Style/ConditionalAssignment :
14+ Enabled : false
Original file line number Diff line number Diff line change @@ -13,4 +13,6 @@ gem "rspec", "~> 3.0"
1313
1414gem "rubocop" , "~> 1.21"
1515
16- gem "rubocop-config-crystal"
16+ gem "rubocop-config-crystal" , "~> 0.0.3"
17+
18+ gem "multi_io" , "~> 0.0.1.pre2"
Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- rb-process (0.1.0 )
4+ rb-process (0.1.1 )
55
66GEM
77 remote: https://rubygems.org/
1111 json (2.15.2 )
1212 language_server-protocol (3.17.0.5 )
1313 lint_roller (1.1.0 )
14+ multi_io (0.0.1.pre2 )
1415 parallel (1.27.0 )
1516 parser (3.3.10.0 )
1617 ast (~> 2.4.1 )
4748 rubocop-ast (1.47.1 )
4849 parser (>= 3.3.7.2 )
4950 prism (~> 1.4 )
50- rubocop-config-crystal (0.0.1 )
51+ rubocop-config-crystal (0.0.3 )
5152 ruby-progressbar (1.13.0 )
5253 unicode-display_width (3.2.0 )
5354 unicode-emoji (~> 4.1 )
@@ -58,11 +59,12 @@ PLATFORMS
5859
5960DEPENDENCIES
6061 bundler (~> 2.4 )
62+ multi_io (~> 0.0.1.pre2 )
6163 rake (~> 13.0 )
6264 rb-process !
6365 rspec (~> 3.0 )
6466 rubocop (~> 1.21 )
65- rubocop-config-crystal
67+ rubocop-config-crystal ( ~> 0.0.3 )
6668
6769BUNDLED WITH
6870 2.4.22
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3+ require "multi_io"
34require_relative "process/version"
45
56module Process
6- def self . run ( *args , **options )
7+ def self . run ( *args , log_file : nil , **options )
8+ if log_file && !log_file . is_a? ( File )
9+ raise ArgumentError . new ( "log_file must be a File with mode" )
10+ end
11+
12+ mio = log_file ? MultiIO . new ( $stdout, log_file ) : $stdout
713 result = String . new
14+
815 IO . popen ( *args , **options ) do |pipe |
916 if block_given?
1017 yield pipe
1118 pipe . close_write
1219 end
1320 while !pipe . eof
1421 line = pipe . gets
15- print line
22+ mio . write ( line )
1623 result << line
1724 end
1825 end
26+
27+ log_file . close if log_file
1928 result
2029 end
2130
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module Process
4- VERSION = "0.1.0 "
4+ VERSION = "0.1.1 "
55end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3+ require "tempfile"
4+
35RSpec . describe Process do
46 it "has a version number" do
57 expect ( Process ::VERSION ) . not_to be nil
2830 it "answer with cmd with ruby style" do
2931 expect ( Process . run ( "bash" , "r+" ) { |pipe | pipe . puts "uname" } ) . to eq "Linux\n "
3032 end
33+
34+ it "print and also log to file" do
35+ tempfile = Tempfile . new ( [ "test_" , ".log" ] )
36+ Process . run ( "uname" , log_file : File . open ( tempfile . path , "w" ) )
37+
38+ expect ( tempfile . readlines ) . to eq [ "Linux\n " ]
39+ tempfile . delete
40+ end
3141end
You can’t perform that action at this time.
0 commit comments