From 08a53784489e13a5037c7fb845210b37858cad1e Mon Sep 17 00:00:00 2001 From: nthanes Date: Sun, 15 Jan 2017 14:29:07 -0500 Subject: [PATCH] Add stdout_as_json to the Command resource --- lib/serverspec/type/command.rb | 6 ++++++ spec/type/base/command_spec.rb | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/serverspec/type/command.rb b/lib/serverspec/type/command.rb index 2a52e849..d343295f 100644 --- a/lib/serverspec/type/command.rb +++ b/lib/serverspec/type/command.rb @@ -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 diff --git a/spec/type/base/command_spec.rb b/spec/type/base/command_spec.rb index b2407bdd..39f805e8 100644 --- a/spec/type/base/command_spec.rb +++ b/spec/type/base/command_spec.rb @@ -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) { < 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