<commit_before>
var express = require('../')
  , request = require('./support/http');

describe('res', function(){
  describe('.render(name)', function(){
    it('should expose app.locals', function(done){
      var app = express();
  
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };

      app.use(function(req, res){
        res.render('user.jade');
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
  
    it('should support index.<engine>', function(done){
      var app = express();
  
      app.set('views', __dirname + '/fixtures');
      app.set('view engine', 'jade');

      app.use(function(req, res){
        res.render('blog/post');
      });
      
      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<h1>blog post</h1>');
        done();
      });
    })
  
    describe('when an error occurs', function(){
      it('should next(err)', function(done){
        var app = express();
  
        app.set('views', __dirname + '/fixtures');

        app.use(function(req, res){
          res.render('user.jade');
        });
        
        app.use(function(err, req, res, next){
          res.end(err.message);
        });

        request(app)
        .get('/')
        .end(function(res){
          res.body.should.match(/user is not defined/);
          done();
        });
      })
    })
  
    describe('when "view engine" is given', function(){
      it('should render the template', function(done){
        var app = express();
  
        app.set('view engine', 'jade');
        app.set('views', __dirname + '/fixtures');

        app.use(function(req, res){
          res.render('email');
        });

        request(app)
        .get('/')
        .end(function(res){
          res.body.should.equal('<p>This is an email</p>');
          done();
        });
      })
    })
  })

  describe('.render(name, option)', function(){
    it('should render the template', function(done){
      var app = express();
  
      app.set('views', __dirname + '/fixtures');
  
      var user = { name: 'tobi' };

      app.use(function(req, res){
        res.render('user.jade', { user: user });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
  
    it('should expose app.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };

      app.use(function(req, res){
        res.render('user.jade', {});
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
    
    it('should expose res.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');

      app.use(function(req, res){
        res.locals.user = { name: 'tobi' };
        res.render('user.jade', {});
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
    
    it('should give precedence to res.locals over app.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };

      app.use(function(req, res){
        res.locals.user = { name: 'jane' };
        res.render('user.jade', {});
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>jane</p>');
        done();
      });
    })

    it('should give precedence to res.render() locals over res.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      var jane = { name: 'jane' };
    
      app.use(function(req, res){
        res.locals.user = { name: 'tobi' };
        res.render('user.jade', { user: jane });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>jane</p>');
        done();
      });
    })
    
    it('should give precedence to res.render() locals over app.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };
      var jane = { name: 'jane' };
    
      app.use(function(req, res){
        res.render('user.jade', { user: jane });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>jane</p>');
        done();
      });
    })
  })

  describe('.render(name, fn)', function(){
    it('should not respond', function(done){
      var app = express();

      app.set('views', __dirname + '/fixtures');

      app.use(function(req, res){
        res.locals.user = { name: 'tobi' };
        res.render('user.jade', function(err, html){
          html = html.replace('tobi', 'loki');
          res.end(html);
        });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>loki</p>');
        done();
      });
    })

    describe('when an error occurs', function(){
      it('should pass it to the callback', function(done){
        var app = express();

        app.set('views', __dirname + '/fixtures');

        app.use(function(req, res){
          res.render('user.jade', function(err){<commit_msg>Added res.render() callback with locals test<commit_after>
var express = require('../')
  , request = require('./support/http');

describe('res', function(){
  describe('.render(name)', function(){
    it('should expose app.locals', function(done){
      var app = express();
  
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };

      app.use(function(req, res){
        res.render('user.jade');
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
  
    it('should support index.<engine>', function(done){
      var app = express();
  
      app.set('views', __dirname + '/fixtures');
      app.set('view engine', 'jade');

      app.use(function(req, res){
        res.render('blog/post');
      });
      
      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<h1>blog post</h1>');
        done();
      });
    })
  
    describe('when an error occurs', function(){
      it('should next(err)', function(done){
        var app = express();
  
        app.set('views', __dirname + '/fixtures');

        app.use(function(req, res){
          res.render('user.jade');
        });
        
        app.use(function(err, req, res, next){
          res.end(err.message);
        });

        request(app)
        .get('/')
        .end(function(res){
          res.body.should.match(/user is not defined/);
          done();
        });
      })
    })
  
    describe('when "view engine" is given', function(){
      it('should render the template', function(done){
        var app = express();
  
        app.set('view engine', 'jade');
        app.set('views', __dirname + '/fixtures');

        app.use(function(req, res){
          res.render('email');
        });

        request(app)
        .get('/')
        .end(function(res){
          res.body.should.equal('<p>This is an email</p>');
          done();
        });
      })
    })
  })

  describe('.render(name, option)', function(){
    it('should render the template', function(done){
      var app = express();
  
      app.set('views', __dirname + '/fixtures');
  
      var user = { name: 'tobi' };

      app.use(function(req, res){
        res.render('user.jade', { user: user });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
  
    it('should expose app.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };

      app.use(function(req, res){
        res.render('user.jade', {});
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
    
    it('should expose res.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');

      app.use(function(req, res){
        res.locals.user = { name: 'tobi' };
        res.render('user.jade', {});
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>tobi</p>');
        done();
      });
    })
    
    it('should give precedence to res.locals over app.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };

      app.use(function(req, res){
        res.locals.user = { name: 'jane' };
        res.render('user.jade', {});
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>jane</p>');
        done();
      });
    })

    it('should give precedence to res.render() locals over res.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      var jane = { name: 'jane' };
    
      app.use(function(req, res){
        res.locals.user = { name: 'tobi' };
        res.render('user.jade', { user: jane });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>jane</p>');
        done();
      });
    })
    
    it('should give precedence to res.render() locals over app.locals', function(done){
      var app = express();
    
      app.set('views', __dirname + '/fixtures');
      app.locals.user = { name: 'tobi' };
      var jane = { name: 'jane' };
    
      app.use(function(req, res){
        res.render('user.jade', { user: jane });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>jane</p>');
        done();
      });
    })
  })

  describe('.render(name, options, fn)', function(){
    it('should pass the resulting string', function(done){
      var app = express();

      app.set('views', __dirname + '/fixtures');

      app.use(function(req, res){
        var tobi = { name: 'tobi' };
        res.render('user.jade', { user: tobi }, function(err, html){
          html = html.replace('tobi', 'loki');
          res.end(html);
        });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>loki</p>');
        done();
      });
    })
  })

  describe('.render(name, fn)', function(){
    it('should pass the resulting string', function(done){
      var app = express();

      app.set('views', __dirname + '/fixtures');

      app.use(function(req, res){
        res.locals.user = { name: 'tobi' };
        res.render('user.jade', function(err, html){
          html = html.replace('tobi', 'loki');
          res.end(html);
        });
      });

      request(app)
      .get('/')
      .end(function(res){
        res.body.should.equal('<p>loki</p>');
        done();
      });
    })

    describe('when an error occurs', function(){
      it('should pass it to the callback', function(done){
        var app = express();

        app.set('views', __dirname + '/fixtures');

        app.use(function(req, res){
          res.render('user.jade', function(err){
{'fraction_non_alphanumeric': 0.19903912148249828, 'fraction_numerical': 0.00034317089910775565, 'mean_word_length': 1.9399747793190416, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '3173998', 'n_tokens_mistral': 3765, 'n_tokens_neox': 3702, 'n_words': 698}