ハッシュテーブルの各キーに対して、リソースタイプインスタンスに属性を割り当てます。キーが存在しない場合は、適切なメッセージで失敗したいと思います。
rspecのコードを掘り下げた後、モジュールをミックスインすると、テストが失敗したことを報告する必要があるRSpec::Expectations
呼び出しができることがわかりました。fail_with()
ただし、「スタックレベルが深すぎます」SystemStackError
という呼び出し行から取得しています。fail_with()
私はそれを間違っていると思います。意味のあるメッセージでテストを失敗させる方法はありますか?
require 'yaml'
module Serverspec
module Type
class YAMLFile < Base
include RSpec::Expectations
def initialize(path)
yaml = YAML.load_file(path)
return unless yaml
yaml.each { |key, value| self.send('#{key}=', value) }
end
def method_missing(m, *args, &block)
# fail here with message
self.fail_with('The key does not exist in the YAML file')
end
end
def yaml_file(path)
YAMLFile.new(path)
end
end
end
include Serverspec::Type