rspec-system 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/rspec-system/helpers.rb +13 -19
- data/lib/rspec-system/node_set/vagrant.rb +9 -4
- data/lib/rspec-system/spec_helper.rb +1 -1
- data/rspec-system.gemspec +1 -1
- data/spec/system/basic_spec.rb +3 -3
- metadata +1 -1
data/README.md
CHANGED
@@ -42,8 +42,8 @@ Create the directory `spec/system` in your project, make sure your unit tests go
|
|
42
42
|
|
43
43
|
describe 'basics' do
|
44
44
|
it 'should cat /etc/resolv.conf' do
|
45
|
-
system_run('cat /etc/resolv.conf') do |
|
46
|
-
|
45
|
+
system_run('cat /etc/resolv.conf') do |r|
|
46
|
+
r[:stdout].should =~ /localhost/
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/rspec-system/helpers.rb
CHANGED
@@ -19,9 +19,9 @@
|
|
19
19
|
# @example Using run within your tests
|
20
20
|
# describe 'test running' do
|
21
21
|
# it 'run cat' do
|
22
|
-
# system_run 'cat /etc/resolv.conf' do |
|
23
|
-
#
|
24
|
-
#
|
22
|
+
# system_run 'cat /etc/resolv.conf' do |r|
|
23
|
+
# r[:exit_code].should == 0
|
24
|
+
# r[:stdout].should =~ /localhost/
|
25
25
|
# end
|
26
26
|
# end
|
27
27
|
# end
|
@@ -58,10 +58,10 @@
|
|
58
58
|
#
|
59
59
|
# it 'test installing latest puppet' do
|
60
60
|
# install_puppet
|
61
|
-
# system_run('puppet apply --version') do |
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
61
|
+
# system_run('puppet apply --version') do |r|
|
62
|
+
# r[:exit_code] == 0
|
63
|
+
# r[:stdout].should =~ /3.1/
|
64
|
+
# r[:stderr].should == ''
|
65
65
|
# end
|
66
66
|
# end
|
67
67
|
# end
|
@@ -90,13 +90,9 @@ module RSpecSystem::Helpers
|
|
90
90
|
# default in your YAML file, otherwise if there is only one node it uses
|
91
91
|
# that) specifies node to execute command on.
|
92
92
|
# @option options [RSpecSystem::Node] :n alias for :node
|
93
|
-
# @yield [
|
94
|
-
#
|
95
|
-
# @
|
96
|
-
# @yieldparam stdout [String] the standard out of the command result
|
97
|
-
# @yieldparam stderr [String] the standard error of the command result
|
98
|
-
# @return [Array<Process::Status,String,String>] returns status, stdout and
|
99
|
-
# stderr when called as a simple method.
|
93
|
+
# @yield [result] yields result when called as a block
|
94
|
+
# @yieldparam result [Hash] a hash containing :exit_code, :stdout and :stderr
|
95
|
+
# @return [Hash] a hash containing :exit_code, :stdout and :stderr
|
100
96
|
def system_run(options)
|
101
97
|
ns = rspec_system_node_set
|
102
98
|
dn = ns.default_node
|
@@ -120,16 +116,14 @@ module RSpecSystem::Helpers
|
|
120
116
|
end
|
121
117
|
|
122
118
|
log.info("system_run #{options[:c]} on #{options[:n].name} executed")
|
123
|
-
|
119
|
+
result = ns.run(options)
|
124
120
|
log.info("system_run results:\n" +
|
125
121
|
"-----------------------\n" +
|
126
|
-
|
127
|
-
"<stdout>#{stdout}</stdout>\n" +
|
128
|
-
"<stderr>#{stderr}</stderr>\n" +
|
122
|
+
result.pretty_inspect +
|
129
123
|
"-----------------------\n")
|
130
124
|
|
131
125
|
if block_given?
|
132
|
-
yield(
|
126
|
+
yield(result)
|
133
127
|
else
|
134
128
|
result
|
135
129
|
end
|
@@ -40,14 +40,19 @@ module RSpecSystem
|
|
40
40
|
dest = opts[:n].name
|
41
41
|
cmd = opts[:c]
|
42
42
|
|
43
|
-
|
43
|
+
r = nil
|
44
44
|
Dir.chdir(@vagrant_path) do
|
45
45
|
cmd = "vagrant ssh #{dest} --command \"cd /tmp && sudo #{cmd}\""
|
46
46
|
log.debug("[vagrant#run] Running command: #{cmd}")
|
47
|
-
|
48
|
-
log.debug("[Vagrant#run] Finished running command: #{cmd}.
|
47
|
+
r = systemu cmd
|
48
|
+
log.debug("[Vagrant#run] Finished running command: #{cmd}.")
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
|
+
{
|
52
|
+
:exit_code => r[0].exitstatus,
|
53
|
+
:stdout => r[1],
|
54
|
+
:stderr => r[2]
|
55
|
+
}
|
51
56
|
end
|
52
57
|
|
53
58
|
# Transfer files to a host in the NodeSet.
|
data/rspec-system.gemspec
CHANGED
data/spec/system/basic_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper_system'
|
|
2
2
|
|
3
3
|
describe "basic tests:" do
|
4
4
|
it "check system_run works" do
|
5
|
-
system_run("cat /etc/hosts") do |
|
6
|
-
|
7
|
-
|
5
|
+
system_run("cat /etc/hosts") do |r|
|
6
|
+
r[:exit_code].should == 0
|
7
|
+
r[:stdout].should =~ /localhost/
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|