require 'useragent_stream_specs'
require 'json'
gem "minitest"
require 'minitest/autorun'
require 'minitest/spec'

include UseragentStreamSpecs

class UseragentStreamSpecsTest < Minitest::Spec
  def test_all_agents_have_a_device
    puts "The USER_AGENTS contains streaming specifications for these platforms: #{USER_AGENTS.keys}."
    USER_AGENTS.keys.each do |platform|
      assert USER_AGENTS[platform][:device].class == String
      assert USER_AGENTS[platform][:device] != ""
    end
  end

  def test_output_ua_as_json
    outfile = File.open("lib/useragent_stream_specs.json", "w")
    USER_AGENTS.keys.each
    outfile.write("# NOTE: THIS FILE IS AUTOMATICALLY GENERATED.\n")
    outfile.write("#       TO CHANGE THE SPECIFICATION - DO IT IN THE RUBY HASH\n")
    outfile.write("#       THEN RUN 'rake' AND COMMIT.\n\n\n")
    
    outfile.write(%{"useragents": #{JSON.pretty_generate USER_AGENTS}})
  end
end
