Skip to content

Commit

Permalink
Merge pull request #586 from nthanes/command-stdout-as-json
Browse files Browse the repository at this point in the history
[WIP] command stdout_as_json feature request
  • Loading branch information
mizzy authored Jan 16, 2017
2 parents 8ddea2b + 08a5378 commit 5e518e1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/serverspec/type/command.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require 'multi_json'

module Serverspec::Type
class Command < Base
def stdout
command_result.stdout
end

def stdout_as_json
MultiJson.load(command_result.stdout)
end

def stderr
command_result.stderr
end
Expand Down
39 changes: 39 additions & 0 deletions spec/type/base/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,42 @@
its(:stdout) { should contain('4260').before('home') }
its(:stdout) { should_not contain('4260').before('bin') }
end

describe command('curl http://localhost:8080/info') do
let(:stdout) { <<EOF
{
"sensu":{
"version":"0.26.5"
},
"transport":{
"keepalives":{
"messages":0,
"consumers":1
},
"results":{
"messages":0,
"consumers":1
},
"connected":true
},
"redis":{
"connected":true
},
"array":[
{
"title":"array 1"
},
{
"title":"array 2"
}
]
}
EOF
}

its(:stdout_as_json) { should include('sensu') }
its(:stdout_as_json) { should include('sensu' => include('version' => '0.26.5')) }
its(:stdout_as_json) { should include('transport' => include('keepalives' => include('consumers' => 1))) }
its(:stdout_as_json) { should include('transport' => include('connected' => true)) }
its(:stdout_as_json) { should include('array' => include('title' => 'array 2')) }
end

0 comments on commit 5e518e1

Please sign in to comment.