var renderDocsFactory = require('../../processors/render-docs');

var mockLog, mockTemplateFinder, mockTemplateEngine;

beforeEach(function() {
  mockLog = jasmine.createSpyObj('mockLog', ['silly', 'debug', 'info', 'warn', 'error']);
  // Uncomment this line if you are debugging and want to see the log messages
  //mockLog.debug.and.callFake(console.log);

  mockTemplateFinder = jasmine.createSpy('templateFinder').and.returnValue('SOME TEMPLATE');
  mockTemplateEngine = jasmine.createSpyObj('templateEngine', ['render']);
});

describe("render-docs", function() {

  it("should call the templateFinder for each doc", function() {
    var doc1 = {}, doc2 = {}, docs = [ doc1, doc2 ];
    var processor = renderDocsFactory(mockLog, mockTemplateFinder, mockTemplateEngine);
    processor.$process(docs);
    expect(mockTemplateFinder.calls.count()).toEqual(2);
    expect(mockTemplateFinder.calls.argsFor(0)).toEqual([doc1]);
    expect(mockTemplateFinder.calls.argsFor(1)).toEqual([doc2]);
  });

  it("should call the templateEngine.render with the template and data", function() {
    var doc1 = { id: 1 }, doc2 = { id: 2 }, docs = [ doc1, doc2 ];
    var someProp = {}, someMethod = function() {};
    var processor = renderDocsFactory(mockLog, mockTemplateFinder, mockTemplateEngine);

    processor.extraData.someProp = someProp;
    processor.helpers.someMethod = someMethod;

    processor.$process(docs);

    expect(mockTemplateEngine.render.calls.count()).toEqual(2);
    expect(mockTemplateEngine.render.calls.argsFor(0)).toEqual(['SOME TEMPLATE',
      { doc: doc1, docs: docs, someProp: someProp, someMethod: someMethod }]);
    expect(mockTemplateEngine.render.calls.argsFor(1)).toEqual(['SOME TEMPLATE',
      { doc: doc2, docs: docs, someProp: someProp, someMethod: someMethod }]);
  });

  it("should place the result of calling templateEngine.render into doc.renderedContent", function() {
    var doc1 = { id: 1 }, doc2 = { id: 2 }, docs = [ doc1, doc2 ];

    mockTemplateEngine.render.and.returnValue('RENDERED CONTENT');

    var processor = renderDocsFactory(mockLog, mockTemplateFinder, mockTemplateEngine);

    processor.$process(docs);
    expect(doc1.renderedContent).toEqual('RENDERED CONTENT');
    expect(doc2.renderedContent).toEqual('RENDERED CONTENT');
  });

});

@@ -116,247 +116,90 @@
 ne;%0A
-%0AbeforeEach(function() %7B%0A  mockLog = jasmine.createSpyObj('mockLog', %5B'silly', 'debug', 'info', 'warn', 'error'%5D);%0A  // Uncomment this line if you are debugging and want to see the log messages%0A  //mockLog.debug.and.callFake(console.log);%0A
+var mockLog = require('dgeni/lib/mocks/log')(/* true */);%0A%0AbeforeEach(function() %7B
 %0A  m

use mockLog from dgeni