<commit_before>/**
 * Created by mattjohansen on 11/18/13.
 */
var geoip = require('../scripts/geolocate-ip.coffee');

describe('geolocation', function() {

  it('should be a function', function(){
    expect(typeof(geoip)).toBe('function');
  });

  it('should call respond when called', function() {
    var robot = {
      respond: function(){}
    };

    spyOn(robot, 'respond');
    geoip(robot);
    expect(robot.respond).toHaveBeenCalled();
  });

  //TODO: Need a way to call robot. Not sure how to do this without access to hubot itself.

});<commit_msg>passing tests for geolocation IP url<commit_after>/**
 * Created by mattjohansen on 11/18/13.
 */
var geoip = require('../scripts/geolocate-ip.coffee');
var HttpClient = require('scoped-http-client');

describe('geolocation', function() {
  var robot, msg = null;

  beforeEach(function(){
    robot = {
      respond: function(regex, callback){},
      http: function(url){
        //HttpClient.create(url);
      }
    }
    spyOn(robot, 'respond').andCallThrough();
    spyOn(robot, 'http').andCallFake(function(){
      var url = robot.http.mostRecentCall.args[0];
      var client = HttpClient.create(url);
      spyOn(client, 'get').andReturn(function(){});
      return client
    });
    geoip(robot);
    msg = {
      match: 'geolocate 1.2.3.4'.match(robot.respond.mostRecentCall.args[0]),
      send: function() {}
    }
  });

  it('should be a function', function(){
    expect(typeof(geoip)).toBe('function');
  });

  it('should generate the correct URL', function() {
    expect(robot.respond).toHaveBeenCalled();
    console.log(robot.respond.mostRecentCall.args[1]);
    robot.respond.mostRecentCall.args[1](msg);
    expect(robot.http).toHaveBeenCalled();
    expect(robot.http.mostRecentCall.args[0]).toBeDefined();
    expect(robot.http.mostRecentCall.args[0]).toBe('http://api.hostip.info/get_json.php?ip=1.2.3.4')
  });

});
{'fraction_non_alphanumeric': 0.17582417582417584, 'fraction_numerical': 0.013605442176870748, 'mean_word_length': 3.5632458233890216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1438788', 'n_tokens_mistral': 660, 'n_tokens_neox': 635, 'n_words': 119}