rspec-system 1.2.0 → 1.2.1
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.
- data/lib/rspec-system.rb +1 -0
- data/lib/rspec-system/node_set/vagrant.rb +3 -2
- data/lib/rspec-system/util.rb +26 -0
- data/rspec-system.gemspec +1 -1
- data/spec/system/system_run_spec.rb +29 -4
- data/spec/unit/utils_spec.rb +15 -0
- metadata +5 -2
data/lib/rspec-system.rb
CHANGED
@@ -6,6 +6,7 @@ module RSpecSystem
|
|
6
6
|
# A NodeSet implementation for Vagrant.
|
7
7
|
class NodeSet::Vagrant < RSpecSystem::NodeSet::Base
|
8
8
|
include RSpecSystem::Log
|
9
|
+
include RSpecSystem::Util
|
9
10
|
|
10
11
|
ENV_TYPE = 'vagrant'
|
11
12
|
|
@@ -68,7 +69,7 @@ module RSpecSystem
|
|
68
69
|
ssh_channels = RSpec.configuration.ssh_channels
|
69
70
|
puts "-----------------"
|
70
71
|
puts "#{dest}$ #{cmd}"
|
71
|
-
result = ssh_exec!(ssh_channels[dest], "cd /tmp && sudo sh -c
|
72
|
+
result = ssh_exec!(ssh_channels[dest], "cd /tmp && sudo sh -c #{shellescape(cmd)}")
|
72
73
|
puts "-----------------"
|
73
74
|
result
|
74
75
|
end
|
@@ -122,7 +123,7 @@ module RSpecSystem
|
|
122
123
|
log.info "[Vagrant#create_vagrantfile] Creating vagrant file here: #{@vagrant_path}"
|
123
124
|
FileUtils.mkdir_p(@vagrant_path)
|
124
125
|
File.open(File.expand_path(File.join(@vagrant_path, "Vagrantfile")), 'w') do |f|
|
125
|
-
f.write(
|
126
|
+
f.write("Vagrant::Config.run do |c|\n")
|
126
127
|
nodes.each do |k,v|
|
127
128
|
log.debug "Filling in content for #{k}"
|
128
129
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# A set of utilities that can be used as a mixin.
|
2
|
+
module RSpecSystem::Util
|
3
|
+
# This is the shellescape method from shellwords from ruby-2.0.0
|
4
|
+
#
|
5
|
+
# @param str [String] string to escape
|
6
|
+
# @return [String] returns escaped string
|
7
|
+
def shellescape(str)
|
8
|
+
str = str.to_s
|
9
|
+
|
10
|
+
# An empty argument will be skipped, so return empty quotes.
|
11
|
+
return "''" if str.empty?
|
12
|
+
|
13
|
+
str = str.dup
|
14
|
+
|
15
|
+
# Treat multibyte characters as is. It is caller's responsibility
|
16
|
+
# to encode the string in the right encoding for the shell
|
17
|
+
# environment.
|
18
|
+
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
|
19
|
+
|
20
|
+
# A LF cannot be escaped with a backslash because a backslash + LF
|
21
|
+
# combo is regarded as line continuation and simply ignored.
|
22
|
+
str.gsub!(/\n/, "'\n'")
|
23
|
+
|
24
|
+
return str
|
25
|
+
end
|
26
|
+
end
|
data/rspec-system.gemspec
CHANGED
@@ -17,13 +17,13 @@ describe "system_run:" do
|
|
17
17
|
|
18
18
|
it 'piping should be preserved' do
|
19
19
|
system_run('rm -f /tmp/foo')
|
20
|
-
system_run('echo "foo" > /tmp/foo') do |r|
|
20
|
+
system_run('echo "foo bar baz" > /tmp/foo') do |r|
|
21
21
|
r.stderr.should == ''
|
22
22
|
r.exit_code.should == 0
|
23
23
|
end
|
24
24
|
|
25
25
|
system_run('cat /tmp/foo') do |r|
|
26
|
-
r.stdout.should =~ /foo/
|
26
|
+
r.stdout.should =~ /foo bar baz/
|
27
27
|
r.exit_code.should == 0
|
28
28
|
end
|
29
29
|
system_run('rm -f /tmp/foo')
|
@@ -31,15 +31,40 @@ describe "system_run:" do
|
|
31
31
|
|
32
32
|
it 'escape single quotes properly' do
|
33
33
|
system_run('rm -f /tmp/foo')
|
34
|
-
system_run("echo 'foo' > /tmp/foo") do |r|
|
34
|
+
system_run("echo 'foo bar baz' > /tmp/foo") do |r|
|
35
35
|
r.stderr.should == ''
|
36
36
|
r.exit_code.should == 0
|
37
37
|
end
|
38
38
|
|
39
39
|
system_run('cat /tmp/foo') do |r|
|
40
|
-
r.stdout.should =~ /foo/
|
40
|
+
r.stdout.should =~ /foo bar baz/
|
41
41
|
r.exit_code.should == 0
|
42
42
|
end
|
43
43
|
system_run('rm -f /tmp/foo')
|
44
44
|
end
|
45
|
+
|
46
|
+
it 'escape all quotes properly' do
|
47
|
+
system_run('rm -f ~vagrant/foo')
|
48
|
+
system_run("su - vagrant -c 'echo \"foo bar baz\" > ~/foo'") do |r|
|
49
|
+
r.stderr.should == ''
|
50
|
+
r.exit_code.should == 0
|
51
|
+
end
|
52
|
+
|
53
|
+
system_run('cat ~vagrant/foo') do |r|
|
54
|
+
r.stdout.should =~ /foo bar baz/
|
55
|
+
r.exit_code.should == 0
|
56
|
+
end
|
57
|
+
system_run('rm -f ~vagrant/foo')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'a string of commands should succeed' do
|
61
|
+
r = system_run(<<-EOS.gsub(/^ {6}/, ''))
|
62
|
+
rm /tmp/foo
|
63
|
+
echo 'foo bar baz' > /tmp/foo
|
64
|
+
cat /tmp/foo
|
65
|
+
rm /tmp/foo
|
66
|
+
EOS
|
67
|
+
r.stdout.should =~ /foo bar baz/
|
68
|
+
r.exit_code.should == 0
|
69
|
+
end
|
45
70
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec-system/util'
|
3
|
+
|
4
|
+
describe RSpecSystem::Util do
|
5
|
+
let(:cls) do
|
6
|
+
cls = Object.new
|
7
|
+
cls.extend(RSpecSystem::Util)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#shellescape' do
|
11
|
+
it 'should escape strings' do
|
12
|
+
cls.shellescape('echo "foo" > /tmp/baz').should == 'echo\ \\"foo\\"\ \>\ /tmp/baz'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/rspec-system/rake_task.rb
|
145
145
|
- lib/rspec-system/result.rb
|
146
146
|
- lib/rspec-system/spec_helper.rb
|
147
|
+
- lib/rspec-system/util.rb
|
147
148
|
- resources/kwalify-schemas/nodeset_schema.yml
|
148
149
|
- resources/kwalify-schemas/prefabs_schema.yml
|
149
150
|
- resources/prefabs.yml
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- spec/unit/kwalify-schemas/nodeset_schema_spec.rb
|
159
160
|
- spec/unit/kwalify-schemas/prefabs_schema_spec.rb
|
160
161
|
- spec/unit/result_spec.rb
|
162
|
+
- spec/unit/utils_spec.rb
|
161
163
|
homepage: https://github.com/puppetlabs/rspec-system
|
162
164
|
licenses: []
|
163
165
|
post_install_message:
|
@@ -189,3 +191,4 @@ test_files:
|
|
189
191
|
- spec/unit/kwalify-schemas/nodeset_schema_spec.rb
|
190
192
|
- spec/unit/kwalify-schemas/prefabs_schema_spec.rb
|
191
193
|
- spec/unit/result_spec.rb
|
194
|
+
- spec/unit/utils_spec.rb
|