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 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 |s,o,e|
46
- o.should =~ /localhost/
45
+ system_run('cat /etc/resolv.conf') do |r|
46
+ r[:stdout].should =~ /localhost/
47
47
  end
48
48
  end
49
49
  end
@@ -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 |s, o, e|
23
- # s.exitstatus.should == 0
24
- # o.should =~ /localhost/
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 |s, o, e|
62
- # s.exitstatus == 0
63
- # o.should =~ /3.1/
64
- # e.should == ''
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 [status, stdout, stderr] yields status, stdout and stderr when
94
- # called as a block.
95
- # @yieldparam status [Process::Status] the status of the executed command
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
- status, stdout, stderr = result = ns.run(options)
119
+ result = ns.run(options)
124
120
  log.info("system_run results:\n" +
125
121
  "-----------------------\n" +
126
- "Exit Status: #{status.exitstatus}\n" +
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(*result)
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
- result = ""
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
- result = systemu cmd
48
- log.debug("[Vagrant#run] Finished running command: #{cmd}. Result is #{result}.")
47
+ r = systemu cmd
48
+ log.debug("[Vagrant#run] Finished running command: #{cmd}.")
49
49
  end
50
- result
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.
@@ -61,7 +61,7 @@ RSpec.configure do |c|
61
61
  end
62
62
 
63
63
  # Default the system_tmp dir to something random
64
- c.system_tmp = Dir.tmpdir
64
+ c.system_tmp = Dir.mktmpdir
65
65
 
66
66
  c.before :suite do
67
67
  start_nodes
data/rspec-system.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # Metadata
4
4
  s.name = "rspec-system"
5
- s.version = "0.2.0"
5
+ s.version = "0.3.0"
6
6
  s.authors = ["Ken Barber"]
7
7
  s.email = ["ken@bob.sh"]
8
8
  s.homepage = "https://github.com/kbarber/rspec-system"
@@ -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 |s, o, e|
6
- s.exitstatus.should == 0
7
- o.should =~ /localhost/
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
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: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: