先日、JSON や YAML のファイルをテストする
- its(:content_as_json)
- its(:content_as_yaml)
のPR を送り、INI ファイルも同じようなものが欲しいと思ったので、
とりあえず、以下のような感じで spec_helper.rb に書いてみた。
require 'inifile'
class IniFile
attr_reader :ini
end
module Serverspec
module Type
class File < Base
def content_as_inifile
@content = content if @content.nil?
@content_as_inifile = IniFile.new(content: @content).ini if @content_as_inifile.nil?
@content_as_inifile
end
end
end
end
使い方は以下のような感じ。
describe file('/path/to/hoge') do
its(:content_as_inifile) { should include('section' => include('key' => 'value')) }
end