clintegracon 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a353f14c43f8264fb73734b7a233f0b35c08856b
4
- data.tar.gz: 6815b80d19d019e4d8ce6e882d6c348b715d9958
2
+ SHA256:
3
+ metadata.gz: c109a85017b07bd104daa1df36db468a32c8aa8c3100fbb333cf8f9f3c8db6cc
4
+ data.tar.gz: 7db0ebd75c0065fc879602ebc290b5a9fb12133b4af83f6052298941f34c4249
5
5
  SHA512:
6
- metadata.gz: 817077bf1e86ecc36915b5bb04ca95300cde6a0c6d84618a8998abf6dcb7b877df532f0db2c99901582e9b6f609eb0a413d4b8fd8abfd34b5063f0a6da98e74f
7
- data.tar.gz: f75f9fe2a055d8bdc3e7d1a818f1eae681ee6a362d3c65b22e5968aa6323ea296f8a8b05cf28ab8dd8bb63aa60bc4b8690ccea0fbf1b22ec7a8429daab533671
6
+ metadata.gz: 1781e7d5690b30f839e8a15d261db1da46589b1b4b383f0fe24f8d256ec65db0c30b600348a243cc37b169605154a5640aed9473cb050470ecb39590ce1ba05a
7
+ data.tar.gz: 58c3fcc06f756d7d1eddc64320072a468b8852328a077981aed3b7f261e21040ceb8db7cae48299dcc6f01a8204a3b385c7a08128aa6b0919adec088b1520c64
@@ -1,10 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.5.0
3
4
  # OS X 10.9.5-10.10.0 (2.0.0-p481)
4
5
  - 2.0.0-p481
5
- # OS X 10.9.3-10.9.4
6
- - 2.0.0-p451
7
-
8
6
 
9
7
  #addons:
10
8
  # code_climate:
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clintegracon (0.8.1)
5
- colored (~> 1.2)
4
+ clintegracon (0.9.0)
5
+ colored2 (~> 3.1)
6
6
  diffy
7
7
 
8
8
  GEM
@@ -17,15 +17,15 @@ GEM
17
17
  bacon (1.2.0)
18
18
  claide (0.8.1)
19
19
  coderay (1.1.0)
20
- colored (1.2)
21
- diffy (3.0.7)
20
+ colored2 (3.1.2)
21
+ diffy (3.2.1)
22
22
  i18n (0.7.0)
23
23
  inch (0.6.1)
24
24
  pry
25
25
  sparkr (>= 0.2.0)
26
26
  term-ansicolor
27
27
  yard (~> 0.8.7.5)
28
- json (1.8.2)
28
+ json (1.8.6)
29
29
  metaclass (0.0.4)
30
30
  method_source (0.8.2)
31
31
  minitest (5.6.1)
@@ -33,6 +33,8 @@ GEM
33
33
  metaclass (~> 0.0.1)
34
34
  mocha-on-bacon (0.2.2)
35
35
  mocha (>= 0.13.0)
36
+ prettybacon (0.0.2)
37
+ bacon (~> 1.2)
36
38
  pry (0.10.1)
37
39
  coderay (~> 1.1.0)
38
40
  method_source (~> 0.8.1)
@@ -59,7 +61,8 @@ DEPENDENCIES
59
61
  clintegracon!
60
62
  inch
61
63
  mocha-on-bacon
64
+ prettybacon
62
65
  rake
63
66
 
64
67
  BUNDLED WITH
65
- 1.10.6
68
+ 1.16.6
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  begin
4
4
  require 'bundler/gem_tasks'
5
- require 'colored'
5
+ require 'colored2'
6
6
 
7
7
  namespace :spec do
8
8
 
@@ -22,14 +22,15 @@ Gem::Specification.new do |spec|
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.3"
26
- spec.add_development_dependency "rake"
25
+ spec.add_development_dependency 'activesupport', '>= 3.1'
27
26
  spec.add_development_dependency "bacon"
28
- spec.add_development_dependency "mocha-on-bacon"
27
+ spec.add_development_dependency "bundler", "~> 1.3"
29
28
  spec.add_development_dependency "claide", "~> 0.8" # Example CLI
30
29
  spec.add_development_dependency "inch"
31
- spec.add_development_dependency 'activesupport', '>= 3.1'
30
+ spec.add_development_dependency "mocha-on-bacon"
31
+ spec.add_development_dependency "prettybacon"
32
+ spec.add_development_dependency "rake"
32
33
 
33
- spec.add_runtime_dependency 'colored', '~> 1.2'
34
+ spec.add_runtime_dependency 'colored2', '~> 3.1'
34
35
  spec.add_runtime_dependency 'diffy'
35
36
  end
@@ -1,4 +1,4 @@
1
- require 'colored'
1
+ require 'colored2'
2
2
 
3
3
  # Layout structure
4
4
  module CLIntegracon
@@ -85,8 +85,7 @@ module CLIntegracon::Adapter::Bacon
85
85
  #
86
86
  def cli_spec(spec_dir, head_args=nil, tail_args=nil, based_on: nil)
87
87
  file_spec(spec_dir, based_on: based_on) do
88
- output = subject.launch(head_args, tail_args)
89
- status = $?
88
+ output, status = subject.launch(head_args, tail_args)
90
89
 
91
90
  args = [head_args, tail_args].compact
92
91
  it "$ #{subject.name} #{args.join(' ')}" do
@@ -1,5 +1,5 @@
1
1
  require 'pathname'
2
- require 'colored'
2
+ require 'colored2'
3
3
  require 'diffy'
4
4
 
5
5
  module CLIntegracon
@@ -1,4 +1,4 @@
1
- require 'colored'
1
+ require 'colored2'
2
2
 
3
3
  module CLIntegracon
4
4
 
@@ -151,7 +151,7 @@ module CLIntegracon
151
151
  when /^\+/ then line.green
152
152
  when /^-/ then line.red
153
153
  else line
154
- end.gsub("\n",'')
154
+ end.gsub("\n",'').gsub("\r", '\r')
155
155
  end
156
156
  description << "--- END ".ljust(max_width, '-')
157
157
  description << ''
@@ -1,6 +1,14 @@
1
1
  module CLIntegracon
2
2
  class Subject
3
3
 
4
+ ReplacementPattern = Struct.new(:pattern, :replacement) do
5
+ # Applies the replacement pattern to the given output, returning
6
+ # a new string with the replacement applied
7
+ def replace(output)
8
+ output.gsub(pattern, replacement)
9
+ end
10
+ end
11
+
4
12
  #-----------------------------------------------------------------------------#
5
13
 
6
14
  # @!group Attributes
@@ -24,9 +32,8 @@ module CLIntegracon
24
32
  # Those are added behind the arguments given on +launch+.
25
33
  attr_accessor :default_args
26
34
 
27
- # @return [Hash<String|Regexp,String>]
28
- # The replace patterns, whose keys are expected to occur in the output,
29
- # which should be redacted, when the subject will be executed. These are
35
+ # @return [Array<ReplacementPattern>]
36
+ # The replace patterns that are redacted when the subject is executed. These are
30
37
  # e.g. paths were side-effects occur, like manipulation of user configurations
31
38
  # in dot files or caching-specific directories or just dates and times.
32
39
  attr_accessor :replace_patterns
@@ -53,7 +60,7 @@ module CLIntegracon
53
60
  self.executable = executable || name
54
61
  self.environment_vars = {}
55
62
  self.default_args = []
56
- self.replace_patterns = {}
63
+ self.replace_patterns = []
57
64
  self.output_path = 'execution_output.txt'
58
65
  end
59
66
 
@@ -72,7 +79,7 @@ module CLIntegracon
72
79
  # The replacement
73
80
  #
74
81
  def replace_pattern(pattern, replacement)
75
- self.replace_patterns[replacement] = pattern
82
+ self.replace_patterns << ReplacementPattern.new(pattern, replacement)
76
83
  end
77
84
 
78
85
  # Define a path, whose occurrences in the output should be replaced by
@@ -122,9 +129,10 @@ module CLIntegracon
122
129
  #
123
130
  def launch(head_arguments='', tail_arguments='')
124
131
  command = command_line(head_arguments, tail_arguments)
125
- output = apply_replacements(run(command))
132
+ output, status = run(command)
133
+ output = apply_replacements(output)
126
134
  write_output(command, output)
127
- output
135
+ [output, status]
128
136
  end
129
137
 
130
138
  #-----------------------------------------------------------------------------#
@@ -147,11 +155,13 @@ module CLIntegracon
147
155
  # @param [String] command_line
148
156
  # THe command line to execute
149
157
  #
150
- # @return [String]
151
- # The output, which is emitted while execution.
158
+ # @return [[String, Process::Status]]
159
+ # The output, which is emitted during execution, and the exit status.
152
160
  #
153
161
  def run(command_line)
154
- `#{environment_var_assignments} #{command_line} 2>&1`
162
+ require 'open3'
163
+ env = Hash[environment_vars.map { |k, v| [k.to_s, v.to_s] }]
164
+ Open3.capture2e(env, command_line.to_s)
155
165
  end
156
166
 
157
167
  # Merges the given with the configured arguments and returns the command
@@ -180,10 +190,9 @@ module CLIntegracon
180
190
  # The redacted output.
181
191
  #
182
192
  def apply_replacements(output)
183
- replace_patterns.each do |key, path|
184
- output = output.gsub(path, key)
193
+ replace_patterns.reduce(output) do |output, replacement_pattern|
194
+ replacement_pattern.replace(output)
185
195
  end
186
- output
187
196
  end
188
197
 
189
198
  # Saves the output in a file called #output_path, relative to current dir.
@@ -1,3 +1,3 @@
1
1
  module CLIntegracon
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  #encoding: utf-8
2
2
 
3
3
  require 'claide'
4
- require 'colored'
4
+ require 'colored2'
5
5
  require 'yaml'
6
6
 
7
7
  # Don’t worry, this makes no sense, just an example
@@ -63,6 +63,20 @@ $before
63
63
  \e[31m- $removed\e[0m
64
64
  $after
65
65
  --- END ------------
66
+ EOS
67
+ end
68
+
69
+ it 'should show carriage returns' do
70
+ diff = ['$before', "+ $blah\radd", "- $blah\rremoved", '$after']
71
+ diff.stubs(:relative_path => '$relative_path')
72
+ @formatter.describe_file_diff(diff, 20).to_s.should.be.eql? <<-EOS
73
+ File comparison error `$relative_path` for $spec_folder:
74
+ --- DIFF -----------
75
+ $before
76
+ \e[32m+ $blah\\radd\e[0m
77
+ \e[31m- $blah\\rremoved\e[0m
78
+ $after
79
+ --- END ------------
66
80
  EOS
67
81
  end
68
82
  end
@@ -1,3 +1,4 @@
1
+ require 'pretty_bacon'
1
2
  require 'CLIntegracon'
2
3
  require 'mocha-on-bacon'
3
4
  require 'active_support/core_ext/string/strip'
@@ -16,11 +16,11 @@ describe CLIntegracon::Subject do
16
16
  /Users/marius/.im/chat.log
17
17
  /tmp/im/chat.log
18
18
  eos
19
- @subject.expects(:`).returns(output)
19
+ Open3.expects(:capture2e).returns([output, mock()])
20
20
  @subject.stubs(:write_output)
21
21
  @subject.replace_user_path '.im/chat.log'
22
22
  @subject.replace_path '/tmp', '$TMP'
23
- @subject.launch.should.be == <<-eos.strip_heredoc
23
+ @subject.launch.first.should.be == <<-eos.strip_heredoc
24
24
  $HOME/.im/chat.log
25
25
  $TMP/im/chat.log
26
26
  eos
@@ -32,16 +32,33 @@ describe CLIntegracon::Subject do
32
32
  Fri Nov 14 22:46:54 - @olivier > Hi
33
33
  Fri Nov 14 22:47:13 - @marius > hey
34
34
  eos
35
- @subject.expects(:`).returns(output)
35
+ Open3.expects(:capture2e).returns([output, mock()])
36
36
  @subject.stubs(:write_output)
37
37
  @subject.replace_pattern /\w{3} \w{3} \d{2} \d{2}:\d{2}:\d{2}/, '<#DATE#>'
38
38
  @subject.replace_pattern /@\w+/, '<REDACTED>'
39
- @subject.launch.should.be == <<-eos.strip_heredoc
39
+ @subject.launch.first.should.be == <<-eos.strip_heredoc
40
40
  <#DATE#> - <REDACTED> > ¡Hola!
41
41
  <#DATE#> - <REDACTED> > Hi
42
42
  <#DATE#> - <REDACTED> > hey
43
43
  eos
44
44
  end
45
+
46
+ it 'should replace multiple patterns with the same replacement string' do
47
+ output = <<-eos.strip_heredoc
48
+ abc
49
+ cde
50
+ efg
51
+ eos
52
+ Open3.expects(:capture2e).returns([output, mock()])
53
+ @subject.stubs(:write_output)
54
+ @subject.replace_pattern /b/, ''
55
+ @subject.replace_pattern /f/, ''
56
+ @subject.launch.first.should == <<-eos.strip_heredoc
57
+ ac
58
+ cde
59
+ eg
60
+ eos
61
+ end
45
62
  end
46
63
 
47
64
  end
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clintegracon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Rackwitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '3.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bacon
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,21 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bacon
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mocha-on-bacon
56
+ name: claide
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: inch
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,21 +81,21 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: claide
84
+ name: mocha-on-bacon
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '0.8'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '0.8'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: inch
98
+ name: prettybacon
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,33 +109,33 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: activesupport
112
+ name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: '3.1'
117
+ version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '3.1'
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: colored
126
+ name: colored2
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '1.2'
131
+ version: '3.1'
118
132
  type: :runtime
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '1.2'
138
+ version: '3.1'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: diffy
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -216,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
230
  version: '0'
217
231
  requirements: []
218
232
  rubyforge_project:
219
- rubygems_version: 2.4.5
233
+ rubygems_version: 2.7.7
220
234
  signing_key:
221
235
  specification_version: 4
222
236
  summary: Integration specs for your CLI
@@ -255,4 +269,3 @@ test_files:
255
269
  - spec/unit/formatter_spec.rb
256
270
  - spec/unit/spec_helper.rb
257
271
  - spec/unit/subject_spec.rb
258
- has_rdoc: