<commit_before>require 'nokogiri'

class Rack::MockResponse

  def alerts
    markup = Nokogiri::HTML(body)
    markup.css('div.alert')
  end

end

<commit_msg>added json helpers to rack test mock response<commit_after>require 'nokogiri'

class Rack::MockResponse

  def mime
    content_type.split(';')[0]
  end

  def charset
    content_type.split(';')[1].
      split('=')[1]
  end

  def alerts
    markup = Nokogiri::HTML(body)
    markup.css('div.alert')
  end

  def json
    mime == 'application/json' ? JSON.parse(body) :
      (raise Exception, 'response is not json')
  end

end


{'fraction_non_alphanumeric': 0.1266891891891892, 'fraction_numerical': 0.005067567567567568, 'mean_word_length': 3.360294117647059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '784797', 'n_tokens_mistral': 224, 'n_tokens_neox': 213, 'n_words': 50}