Skip to content

Instantly share code, notes, and snippets.

@purplexa
Created April 21, 2016 00:59
Show Gist options
  • Save purplexa/5bd44dab9c9bf4386fbe180f335559fd to your computer and use it in GitHub Desktop.
Save purplexa/5bd44dab9c9bf4386fbe180f335559fd to your computer and use it in GitHub Desktop.
rspec-puppet JSON attribute value comparison
require 'spec_helper'
require 'json'
fixture_dir = File.expand_path(File.join(__FILE__, '..', '..', 'fixtures', 'data'))
describe 'jmxtrans::query' do
def check_json_string(expected)
return Proc.new do |actual|
begin
expected_obj = JSON.parse(expected)
actual_obj = JSON.parse(actual)
expected_obj == actual_obj
rescue JSON.ParserError
false
end
end
end
context 'jmxtrans::query minimal' do
let(:title) { 'puppetserver' }
let(:params) {{
:host => 'w2',
:port => 1099,
:queries => []
}}
output = File.read(File.join(fixture_dir, 'minimal.json'))
it do
is_expected.to contain_file('/var/lib/jmxtrans/puppetserver.json').with({
:ensure => 'file',
:owner => 'jmxtrans',
:mode => '0640',
:content => check_json_string(output)
})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment