Module: Spout::Tests::DomainFormat

Included in:
Spout::Tests
Defined in:
lib/spout/tests/domain_format.rb

Instance Method Summary collapse

Instance Method Details

#assert_domain_format(item, msg = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/spout/tests/domain_format.rb', line 5

def assert_domain_format(item, msg = nil)
  result = begin
    json = JSON.parse(File.read(item))
    if json.kind_of?(Array)
      json.empty? or json.select{|o| not o.kind_of?(Hash)}.size == 0
    else
      false
    end
  rescue JSON::ParserError
    false
  end

  full_message = build_message(msg, "Must be an array of choice hashes. Ex:\n[\n  {\n    \"value\":        \"1\",\n    \"display_name\": \"Option 1\",\n    \"description\":  \"...\"\n  },\n  { ... },\n  ...\n]")
  assert_block(full_message) do
    result
  end
end