<commit_before>require 'helper'

class TestGibbon < Test::Unit::TestCase

  context "build api url" do

    setup do
      @gibbon = Gibbon::API.new
    end

    should "handle empty api key" do
      expect_post("https://api.mailchimp.com/1.3/?method=sayHello", {"apikey" => nil})

      @gibbon.say_hello
    end

    should "handle timeout" do
      expect_post("https://api.mailchimp.com/1.3/?method=sayHello", {"apikey" => nil}, 120)
      @gibbon.timeout=120
      @gibbon.say_hello
    end

    should "handle api key with dc" do
      @gibbon.apikey="TESTKEY-us1"
      expect_post("https://us1.api.mailchimp.com/1.3/?method=sayHello", {"apikey" => "TESTKEY-us1"})

      @gibbon.say_hello
    end
  end

  context "build api body" do
    setup do
      @key = "TESTKEY-us1"
      @gibbon = Gibbon::API.new(@key)
      @url = "https://us1.api.mailchimp.com/1.3/?method=sayHello"
    end

    should "escape string parameters" do
      expect_post(@url, {"apikey" => @key, "message" => "simon+says"})
      @gibbon.say_hello(:message => "simon says")
    end

    should "escape string parameters in an array" do
      expect_post(@url, {"apikey" => @key, "messages" => ["simon+says", "do+this"]})
      @gibbon.say_hello(:messages => ["simon says", "do this"])
    end

    should "escape string parameters in a hash" do
      expect_post(@url, {"apikey" => @key, "messages" => {"simon+says" => "do+this"}})
      @gibbon.say_hello(:messages => {"simon says" => "do this"})
    end

    should "escape nested string parameters" do
      expect_post(@url, {"apikey" => @key, "messages" => {"simon+says" => ["do+this", "and+this"]}})
      @gibbon.say_hello(:messages => {"simon says" => ["do this", "and this"]})
    end

    should "pass through non string parameters" do
      expect_post(@url, {"apikey" => @key, "fee" => 99})
      @gibbon.say_hello(:fee => 99)
    end

  end

  private

  def expect_post(expected_url, expected_body, expected_timeout=nil)
    Gibbon::API.expects(:post).with do |url, opts|
      url == expected_url &&
      JSON.parse(URI::decode(opts[:body])) == expected_body &&
      opts[:timeout] == expected_timeout
    end.returns(Struct.new(:body).new("") )
  end
end<commit_msg>Fix tests in Gibbon so they pass out of the box.<commit_after>require 'helper'

class TestGibbon < Test::Unit::TestCase

  context "build api url" do

    setup do
      @gibbon = Gibbon.new
    end

    should "handle empty api key" do
      expect_post("https://api.mailchimp.com/1.3/?method=sayHello", {"apikey" => nil})
      @gibbon.say_hello
    end

    should "handle timeout" do
      expect_post("https://api.mailchimp.com/1.3/?method=sayHello", {"apikey" => nil}, 120)
      @gibbon.timeout=120
      @gibbon.say_hello
    end

    should "handle api key with dc" do
      @gibbon.api_key="TESTKEY-us1"
      expect_post("https://us1.api.mailchimp.com/1.3/?method=sayHello", {"apikey" => "TESTKEY-us1"})
      @gibbon.say_hello
    end
  end

  context "build api body" do
    setup do
      @key = "TESTKEY-us1"
      @gibbon = Gibbon.new(@key)
      @url = "https://us1.api.mailchimp.com/1.3/?method=sayHello"
    end

    should "escape string parameters" do
      expect_post(@url, {"apikey" => @key, "message" => "simon+says"})
      @gibbon.say_hello(:message => "simon says")
    end

    should "escape string parameters in an array" do
      expect_post(@url, {"apikey" => @key, "messages" => ["simon+says", "do+this"]})
      @gibbon.say_hello(:messages => ["simon says", "do this"])
    end

    should "escape string parameters in a hash" do
      expect_post(@url, {"apikey" => @key, "messages" => {"simon+says" => "do+this"}})
      @gibbon.say_hello(:messages => {"simon says" => "do this"})
    end

    should "escape nested string parameters" do
      expect_post(@url, {"apikey" => @key, "messages" => {"simon+says" => ["do+this", "and+this"]}})
      @gibbon.say_hello(:messages => {"simon says" => ["do this", "and this"]})
    end

    should "pass through non string parameters" do
      expect_post(@url, {"apikey" => @key, "fee" => 99})
      @gibbon.say_hello(:fee => 99)
    end

  end

  private

  def expect_post(expected_url, expected_body, expected_timeout=nil)
    Gibbon.expects(:post).with do |url, opts|
      url == expected_url &&
      JSON.parse(URI::decode(opts[:body])) == expected_body &&
      opts[:timeout] == expected_timeout
    end.returns(Struct.new(:body).new("") )
  end
end
{'fraction_non_alphanumeric': 0.16902356902356902, 'fraction_numerical': 0.010325476992143659, 'mean_word_length': 3.1958568738229753, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 8, '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': '2839485', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1530, 'n_words': 357}