specinfra 2.0.0.beta9 → 2.0.0.beta10

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: 572f8250ba4ca99acbaa3740b61bb646103cd041
4
- data.tar.gz: d8cec18e50e69cd12c3186dbcbc7835e8896df93
3
+ metadata.gz: e1aff7042917b171b5d17ebf844a2d999aa6618e
4
+ data.tar.gz: 0b40b2253e90d2b396488e23760ba55ddbbe00d7
5
5
  SHA512:
6
- metadata.gz: 7250feadcc58c2e9672a5e5580674b2283cbb2c5109ee8e3c7b3ec330e83985d3494d39c332c8ea1825ebd211f82e7a1ddafae6c7468a2c43dc94cdfa3a84518
7
- data.tar.gz: a8e345e42bb720faa2d8001e17513d2b76ccc0c3135884aa0beff203f9681d04542f169b5101fbc7ff0a96925d855092f0f7f70c51cf9562713da17b6f6910ab
6
+ metadata.gz: 726743abc9b1a8e572e6919900d4caf7e1426e020b316ac6c2533032b7da7b8e335dbd79a9082ba3561358ff524beb6c0486fffa6f692512c2c98ab082717430
7
+ data.tar.gz: 95ceed7ebc6efbc6bb2a2ea6d37d991bf71145996d834521fbf7b62cbeed7d0ecebc5b53b21e4cd8aea0a72b0dfa73dbaec114698453bb39d2f0baec8e7badb3
@@ -9,7 +9,7 @@ module Specinfra
9
9
  def run_command(cmd, opts={})
10
10
  cmd = build_command(cmd)
11
11
  cmd = add_pre_command(cmd)
12
- stdout = run_with_no_ruby_environment do
12
+ stdout = with_env do
13
13
  `#{build_command(cmd)} 2>&1`
14
14
  end
15
15
  # In ruby 1.9, it is possible to use Open3.capture3, but not in 1.8
@@ -23,14 +23,26 @@ module Specinfra
23
23
  CommandResult.new :stdout => stdout, :exit_status => $?.exitstatus
24
24
  end
25
25
 
26
- def run_with_no_ruby_environment
26
+ def with_env
27
27
  keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE
28
28
  RUBYOPT GEM_HOME GEM_PATH GEM_CACHE]
29
29
 
30
30
  keys.each { |key| ENV["_SPECINFRA_#{key}"] = ENV[key] ; ENV.delete(key) }
31
+
32
+ env = Specinfra.configuration.env || {}
33
+ env['LANG'] ||= 'C'
34
+
35
+ env.each do |key, value|
36
+ ENV["_SPECINFRA_#{key}"] = ENV[key];
37
+ ENV[key] = value
38
+ end
39
+
31
40
  yield
32
41
  ensure
33
42
  keys.each { |key| ENV[key] = ENV.delete("_SPECINFRA_#{key}") }
43
+ env.each do |key, value|
44
+ ENV[key] = ENV.delete("_SPECINFRA_#{key}");
45
+ end
34
46
  end
35
47
 
36
48
  def build_command(cmd)
@@ -40,7 +52,7 @@ module Specinfra
40
52
 
41
53
  path = Specinfra.configuration.path
42
54
  if path
43
- cmd = "env PATH=#{path.shellescape}:\"$PATH\" #{cmd}"
55
+ cmd = %Q{env PATH="#{path}" #{cmd}}
44
56
  end
45
57
 
46
58
  cmd
@@ -11,7 +11,9 @@ module Specinfra
11
11
  def run_command(cmd, opt={})
12
12
  cmd = build_command(cmd)
13
13
  cmd = add_pre_command(cmd)
14
- ret = ssh_exec!(cmd)
14
+ ret = with_env do
15
+ ssh_exec!(cmd)
16
+ end
15
17
 
16
18
  ret[:stdout].gsub!(/\r\n/, "\n")
17
19
 
@@ -23,6 +25,26 @@ module Specinfra
23
25
  CommandResult.new ret
24
26
  end
25
27
 
28
+ def with_env
29
+ env = Specinfra.configuration.env || {}
30
+ env['LANG'] ||= 'C'
31
+
32
+ ssh_options = Specinfra.configuration.ssh_options || {}
33
+ ssh_options[:send_env] ||= []
34
+
35
+ env.each do |key, value|
36
+ ENV["_SPECINFRA_#{key}"] = ENV[key];
37
+ ENV[key] = value
38
+ ssh_options[:send_env] << key
39
+ end
40
+
41
+ yield
42
+ ensure
43
+ env.each do |key, value|
44
+ ENV[key] = ENV.delete("_SPECINFRA_#{key}");
45
+ end
46
+ end
47
+
26
48
  def build_command(cmd)
27
49
  cmd = super(cmd)
28
50
  user = Specinfra.configuration.ssh_options[:user]
@@ -4,6 +4,6 @@ class Specinfra::Command::Linux::Base::LxcContainer < Specinfra::Command::Base::
4
4
  end
5
5
 
6
6
  def check_is_running(container)
7
- "lxc-info -n #{escape(container)} -t RUNNING"
7
+ "lxc-info -n #{escape(container)} -s | grep -w RUNNING"
8
8
  end
9
9
  end
@@ -2,6 +2,7 @@ module Specinfra
2
2
  module Configuration
3
3
  class << self
4
4
  VALID_OPTIONS_KEYS = [
5
+ :env,
5
6
  :path,
6
7
  :shell,
7
8
  :pre_command,
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.0.0.beta9"
2
+ VERSION = "2.0.0.beta10"
3
3
  end
@@ -46,7 +46,7 @@ describe Specinfra::Backend::Exec do
46
46
 
47
47
  context 'with custom path' do
48
48
  before do
49
- RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin' }
49
+ RSpec.configure {|c| c.path = '/opt/bin:/opt/foo/bin:$PATH' }
50
50
  end
51
51
 
52
52
  after do
@@ -54,13 +54,13 @@ describe Specinfra::Backend::Exec do
54
54
  end
55
55
 
56
56
  it 'should use custom path' do
57
- expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH=/opt/bin:/opt/foo/bin:"$PATH" /bin/sh -c test\ -f\ /etc/passwd'
57
+ expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/foo/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd'
58
58
  end
59
59
  end
60
60
 
61
61
  context 'with custom path that needs escaping' do
62
62
  before do
63
- RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin' }
63
+ RSpec.configure {|c| c.path = '/opt/bin:/opt/test & spec/bin:$PATH' }
64
64
  end
65
65
 
66
66
  after do
@@ -68,7 +68,7 @@ describe Specinfra::Backend::Exec do
68
68
  end
69
69
 
70
70
  it 'should use custom path' do
71
- expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH=/opt/bin:/opt/test\ \&\ spec/bin:"$PATH" /bin/sh -c test\ -f\ /etc/passwd'
71
+ expect(backend.build_command('test -f /etc/passwd')).to eq 'env PATH="/opt/bin:/opt/test & spec/bin:$PATH" /bin/sh -c test\ -f\ /etc/passwd'
72
72
  end
73
73
  end
74
74
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe backend.run_command('echo $LANG').stdout.strip do
4
+ it { should eq 'C' }
5
+ end
6
+
7
+ describe do
8
+ before do
9
+ ENV['LANG'] = 'C'
10
+ set :env, 'LANG' => 'ja_JP.UTF-8'
11
+ end
12
+ let(:lang) { backend.run_command('echo $LANG').stdout.strip }
13
+ it { expect(lang).to eq 'ja_JP.UTF-8' }
14
+ it { expect(ENV['LANG']).to eq 'C' }
15
+ end
16
+
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'specinfra'
2
2
  require 'rspec/mocks/standalone'
3
+ require 'rspec/its'
3
4
 
4
5
  include Specinfra::Helper::Exec
5
6
 
data/specinfra.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake", "~> 10.1.1"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "rspec-its"
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta9
4
+ version: 2.0.0.beta10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Common layer for serverspec and configspec
70
84
  email:
71
85
  - gosukenator@gmail.com
@@ -293,6 +307,7 @@ files:
293
307
  - lib/specinfra/runner.rb
294
308
  - lib/specinfra/version.rb
295
309
  - spec/backend/exec/build_command_spec.rb
310
+ - spec/backend/exec/env_spec.rb
296
311
  - spec/backend/ssh/build_command_spec.rb
297
312
  - spec/command/base/file_spec.rb
298
313
  - spec/command/base_spec.rb
@@ -333,6 +348,7 @@ specification_version: 4
333
348
  summary: Common layer for serverspec and configspec
334
349
  test_files:
335
350
  - spec/backend/exec/build_command_spec.rb
351
+ - spec/backend/exec/env_spec.rb
336
352
  - spec/backend/ssh/build_command_spec.rb
337
353
  - spec/command/base/file_spec.rb
338
354
  - spec/command/base_spec.rb