cocaine 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of cocaine might be problematic. Click here for more details.

data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ platforms :ruby do
6
+ gem "posix-spawn"
7
+ end
data/LICENSE CHANGED
@@ -3,7 +3,7 @@ LICENSE
3
3
 
4
4
  The MIT License
5
5
 
6
- Copyright (c) 2011-2012 Jon Yurek and thoughtbot, inc.
6
+ Copyright (c) 2011-2013 Jon Yurek and thoughtbot, inc.
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
9
  of this software and associated documentation files (the "Software"), to deal
data/NEWS.md CHANGED
@@ -1,3 +1,13 @@
1
+ New for 0.5.0:
2
+
3
+ * Updated the copyrights to 2013
4
+ * Added UTF encoding markers on code files to ensure they're interpreted as
5
+ UTF-8 instead of ASCII.
6
+ * Swapped the ordering of the PATH and supplemental path. A binary in the
7
+ supplemental path will take precedence, now.
8
+ * Errors contain the output of the erroring command, for inspection.
9
+ * Use climate_control instead for environment management.
10
+
1
11
  New for 0.4.2:
2
12
 
3
13
  * Loggers that don't understand `tty?`, like `ActiveSupport::BufferedLogger`
data/README.md CHANGED
@@ -135,7 +135,7 @@ one of the `.spawn` runners don't work for you, you can override them manually
135
135
  by setting a new runner, like so:
136
136
 
137
137
  ```ruby
138
- Cocaine::CommandLine.runner = Cocaine::BackticksRunner.new
138
+ Cocaine::CommandLine.runner = Cocaine::CommandLine::BackticksRunner.new
139
139
  ```
140
140
 
141
141
  And if you really want to, you can define your own Runner, though I can't
@@ -173,7 +173,7 @@ Question? Idea? Problem? Bug? Comment? Concern? Like using question marks?
173
173
 
174
174
  ## License
175
175
 
176
- Copyright 2011-2012 Jon Yurek and thoughtbot, inc. This is free software, and
176
+ Copyright 2011-2013 Jon Yurek and thoughtbot, inc. This is free software, and
177
177
  may be redistributed under the terms specified in the
178
178
  [LICENSE](https://github.com/thoughtbot/cocaine/blob/master/LICENSE)
179
179
  file.
data/cocaine.gemspec CHANGED
@@ -16,11 +16,11 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
+ s.add_dependency('climate_control', '>= 0.0.3', '< 1.0')
19
20
  s.add_development_dependency('rspec')
20
21
  s.add_development_dependency('bourne')
21
22
  s.add_development_dependency('mocha')
22
23
  s.add_development_dependency('rake')
23
- s.add_development_dependency('posix-spawn')
24
24
  s.add_development_dependency('active_support')
25
25
  s.add_development_dependency('pry')
26
26
  end
data/lib/cocaine.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # coding: UTF-8
2
+
1
3
  require 'rbconfig'
2
4
  require 'cocaine/command_line'
3
5
  require 'cocaine/command_line/runners'
@@ -1,3 +1,5 @@
1
+ # coding: UTF-8
2
+
1
3
  module Cocaine
2
4
  class CommandLine
3
5
  class << self
@@ -6,10 +8,11 @@ module Cocaine
6
8
  def path
7
9
  @supplemental_path
8
10
  end
11
+
9
12
  def path=(supplemental_path)
10
13
  @supplemental_path = supplemental_path
11
14
  @supplemental_environment ||= {}
12
- @supplemental_environment['PATH'] = [ENV['PATH'], *supplemental_path].join(File::PATH_SEPARATOR)
15
+ @supplemental_environment['PATH'] = [*supplemental_path, ENV['PATH']].join(File::PATH_SEPARATOR)
13
16
  end
14
17
 
15
18
  def posix_spawn_available?
@@ -45,6 +48,7 @@ module Cocaine
45
48
  BackticksRunner.new
46
49
  end
47
50
  end
51
+
48
52
  @environment = {}
49
53
 
50
54
  attr_reader :exit_status, :runner
@@ -83,7 +87,12 @@ module Cocaine
83
87
  raise Cocaine::CommandNotFoundError
84
88
  end
85
89
  unless @expected_outcodes.include?($?.exitstatus)
86
- raise Cocaine::ExitStatusError, "Command '#{command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}"
90
+ message = [
91
+ "Command '#{full_command}' returned #{$?.exitstatus}. Expected #{@expected_outcodes.join(", ")}",
92
+ "Here is the command output:\n",
93
+ output
94
+ ].join("\n")
95
+ raise Cocaine::ExitStatusError, message
87
96
  end
88
97
  output
89
98
  end
@@ -1,4 +1,6 @@
1
+ # coding: UTF-8
2
+
1
3
  require 'cocaine/command_line/runners/backticks_runner'
2
4
  require 'cocaine/command_line/runners/process_runner'
3
5
  require 'cocaine/command_line/runners/posix_runner'
4
- require 'cocaine/command_line/runners/fake_runner'
6
+ require 'cocaine/command_line/runners/fake_runner'
@@ -1,3 +1,7 @@
1
+ # coding: UTF-8
2
+
3
+ require 'climate_control'
4
+
1
5
  module Cocaine
2
6
  class CommandLine
3
7
  class BackticksRunner
@@ -10,14 +14,8 @@ module Cocaine
10
14
 
11
15
  private
12
16
 
13
- def with_modified_environment(env)
14
- begin
15
- saved_env = ENV.to_hash
16
- ENV.update(env)
17
- yield
18
- ensure
19
- ENV.update(saved_env)
20
- end
17
+ def with_modified_environment(env, &block)
18
+ ClimateControl.modify(env, &block)
21
19
  end
22
20
 
23
21
  end
@@ -1,7 +1,9 @@
1
+ # coding: UTF-8
2
+
1
3
  module Cocaine
2
4
  class CommandLine
3
5
  class FakeRunner
4
-
6
+
5
7
  attr_reader :commands
6
8
 
7
9
  def initialize
@@ -19,4 +21,4 @@ module Cocaine
19
21
 
20
22
  end
21
23
  end
22
- end
24
+ end
@@ -1,3 +1,5 @@
1
+ # coding: UTF-8
2
+
1
3
  module Cocaine
2
4
  class CommandLine
3
5
  class PosixRunner
@@ -1,3 +1,5 @@
1
+ # coding: UTF-8
2
+
1
3
  module Cocaine
2
4
  class CommandLine
3
5
  class ProcessRunner
@@ -1,3 +1,5 @@
1
+ # coding: UTF-8
2
+
1
3
  module Cocaine
2
4
  class CommandLineError < StandardError; end
3
5
  class CommandNotFoundError < CommandLineError; end
@@ -1,3 +1,5 @@
1
+ # coding: UTF-8
2
+
1
3
  module Cocaine
2
- VERSION = "0.4.2".freeze
4
+ VERSION = "0.5.0".freeze
3
5
  end
@@ -12,11 +12,17 @@ describe Cocaine::CommandLine do
12
12
  end
13
13
 
14
14
  it "specifies the $PATH where the command can be found" do
15
- Cocaine::CommandLine.path = "/path/to/command/dir"
16
- cmd = Cocaine::CommandLine.new("ruby", "-e 'puts ENV[%{PATH}]'")
17
- cmd.command.should == "ruby -e 'puts ENV[%{PATH}]'"
18
- output = cmd.run
19
- output.should match(%r{/path/to/command/dir})
15
+ saved_path = ENV['PATH']
16
+ begin
17
+ ENV['PATH'] = "/the/environment/path:/other/bin"
18
+ Cocaine::CommandLine.path = "/path/to/command/dir"
19
+ cmd = Cocaine::CommandLine.new("echo", "$PATH")
20
+ cmd.command.should == "echo $PATH"
21
+ output = cmd.run
22
+ output.should match(%r{/path/to/command/dir:/the/environment/path:/other/bin})
23
+ ensure
24
+ ENV['PATH'] = saved_path
25
+ end
20
26
  end
21
27
 
22
28
  it "specifies more than one path where the command can be found" do
@@ -150,6 +156,21 @@ describe Cocaine::CommandLine do
150
156
  end
151
157
  end
152
158
 
159
+ it "adds command output to exception message if the result code is nonzero" do
160
+ cmd = Cocaine::CommandLine.new("convert",
161
+ "a.jpg b.png",
162
+ :swallow_stderr => false)
163
+ error_output = "Error 315"
164
+ cmd.stubs(:execute).with("convert a.jpg b.png").returns(error_output)
165
+ with_exitstatus_returning(1) do
166
+ begin
167
+ cmd.run
168
+ rescue Cocaine::ExitStatusError => e
169
+ e.message.should =~ /#{error_output}/
170
+ end
171
+ end
172
+ end
173
+
153
174
  it "should keep result code in #exitstatus" do
154
175
  cmd = Cocaine::CommandLine.new("convert")
155
176
  cmd.stubs(:execute).with("convert").returns(:correct_value)
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'timeout'
6
6
  require 'tempfile'
7
7
  require 'pry'
8
8
  require 'active_support/buffered_logger'
9
+ require 'thread'
9
10
 
10
11
  Dir[File.dirname(__FILE__) + "/support/**.rb"].each{|support_file| require support_file }
11
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocaine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,26 +9,32 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-19 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
15
+ name: climate_control
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
21
+ version: 0.0.3
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '1.0'
25
+ type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  none: false
26
29
  requirements:
27
30
  - - ! '>='
28
31
  - !ruby/object:Gem::Version
29
- version: '0'
32
+ version: 0.0.3
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
30
36
  - !ruby/object:Gem::Dependency
31
- name: bourne
37
+ name: rspec
32
38
  requirement: !ruby/object:Gem::Requirement
33
39
  none: false
34
40
  requirements:
@@ -44,7 +50,7 @@ dependencies:
44
50
  - !ruby/object:Gem::Version
45
51
  version: '0'
46
52
  - !ruby/object:Gem::Dependency
47
- name: mocha
53
+ name: bourne
48
54
  requirement: !ruby/object:Gem::Requirement
49
55
  none: false
50
56
  requirements:
@@ -60,7 +66,7 @@ dependencies:
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
68
  - !ruby/object:Gem::Dependency
63
- name: rake
69
+ name: mocha
64
70
  requirement: !ruby/object:Gem::Requirement
65
71
  none: false
66
72
  requirements:
@@ -76,7 +82,7 @@ dependencies:
76
82
  - !ruby/object:Gem::Version
77
83
  version: '0'
78
84
  - !ruby/object:Gem::Dependency
79
- name: posix-spawn
85
+ name: rake
80
86
  requirement: !ruby/object:Gem::Requirement
81
87
  none: false
82
88
  requirements:
@@ -177,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
183
  version: '0'
178
184
  requirements: []
179
185
  rubyforge_project:
180
- rubygems_version: 1.8.24
186
+ rubygems_version: 1.8.23
181
187
  signing_key:
182
188
  specification_version: 3
183
189
  summary: A small library for doing (command) lines