var expect = require('expect.js');
var assert = require('better-assert');
var sinon = require('sinon');

describe('console.table', function () {
  beforeEach(function () {
    // make sure the module is loaded without caching
    delete require.cache[require.resolve('../index')];
  });

  afterEach(function () {
    delete console.table;
  });

  it('fills missing method', function () {
    expect(console.table).to.be(undefined);
  });

  it('installs html method', function () {
    require('../index');
    expect(typeof console.table).to.be('function');
  });

  it('logs simple string', function () {
    require('../index');
    sinon.spy(console, 'log');
    console.table('foo');
    assert(console.log.firstCall.calledWith('foo'));
    console.log.restore();
  });

  it('logs several strings separately', function () {
    require('../index');
    sinon.spy(console, 'log');
    console.table('foo', 'bar');
    assert(console.log.firstCall.calledWith('foo'));
    assert(console.log.secondCall.calledWith('bar'));
    console.log.restore();
  });

  it('can print title', function () {
    require('../index');
    console.table('These are numbers', [1, 2, 3]);
  });

  it('objects with title', function () {
    var objects = [
      {
        name: 'foo',
        age: 10
      },
      {
        name: 'bar',
        age: 20
      },
      {
        name: 'baz',
        age: 30
      }
    ];
    require('../index');
    console.table('Several objects', objects);
  });
});

describe('console.table object', function () {
  beforeEach(function () {
    // make sure the module is loaded without caching
    delete require.cache[require.resolve('../index')];
    require('../index');
  });

  afterEach(function () {
    delete console.table;
  });

  it('prints an object', function () {
    console.table({ foo: 'foo', bar: 'bar' });
  });

  it('prints an object', function () {
    console.table('this is an object', { foo: 'foo', bar: 'bar' });
  });
});

@@ -1,12 +1,27 @@
+'use strict';%0A%0A
 var expect =
@@ -117,77 +117,88 @@
 );%0A%0A
-describe('console.table', function () %7B%0A  beforeEach(function 
+function loadMethod() %7B%0A  require('../index');%0A%7D%0A%0Afunction cleanLoadedCache
 () %7B%0A
-  
   //
@@ -237,34 +237,32 @@
 without caching%0A
-  
   delete require
@@ -302,43 +302,42 @@
 )%5D;%0A
-  %7D);%0A%0A  afterEach(function 
+%7D%0A%0Afunction deleteTableMethod
 () %7B%0A
-  
   de
@@ -348,35 +348,136 @@
  console.table;%0A
-  %7D
+%7D%0A%0Adescribe('console.table', function () %7B%0A  beforeEach(cleanLoadedCache);%0A  afterEach(deleteTableMethod
 );%0A%0A  it('fills 
@@ -605,34 +605,27 @@
 ) %7B%0A    
-require('../index'
+loadMethod(
 );%0A    e
@@ -723,34 +723,27 @@
 ) %7B%0A    
-require('../index'
+loadMethod(
 );%0A    s
@@ -939,34 +939,27 @@
 ) %7B%0A    
-require('../index'
+loadMethod(
 );%0A    s
@@ -1200,34 +1200,27 @@
 ) %7B%0A    
-require('../index'
+loadMethod(
 );%0A    c
@@ -1505,34 +1505,27 @@
  %5D;%0A    
-require('../index'
+loadMethod(
 );%0A    c
@@ -1659,200 +1659,82 @@
     
-// make sure the module is loaded without caching%0A    delete require.cache%5Brequire.resolve('../index')%5D;%0A    require('../index');%0A  %7D);%0A%0A  afterEach(function () %7B%0A    delete console.table;%0A  %7D
+cleanLoadedCache();%0A    loadMethod();%0A  %7D);%0A%0A  afterEach(deleteTableMethod
 );%0A%0A

test refactoring