Module: Spout::Tests::FormExistenceValidation

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

Instance Method Summary collapse

Instance Method Details

#assert_form_existence(item) ⇒ Object



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

def assert_form_existence(item)
  form_names = Dir.glob("forms/**/*.json").collect{|file| file.split("/").last.to_s.downcase.split(".json").first}

  result = begin
    (form_names | JSON.parse(File.read(item, encoding: "utf-8"))["forms"]).size == form_names.size
  rescue JSON::ParserError
    false
  end

  message = "One or more forms referenced by #{item} does not exist."

  assert result, message
end