<commit_before>
describe 'Express'
  before_each
    reset()
  end
  
  describe 'parseParams()'
    it 'should parse simple query string key / value pairs'
      parseParams('foo=bar').should.eql { foo: 'bar' }
      parseParams('foo=bar&baz=1').should.eql { foo: 'bar', baz: '1' }
    end
    
    it 'should parse named nested params'
      var user = { user: { name: 'tj', email: '<EMAIL>' }}
      parseParams('user[name]=tj&user[email]=<EMAIL>').should.eql user
    end
    
    it 'should parse several levels of nesting'
      var user = { user: { name: 'tj', email: { primary: '<EMAIL>' }}}
      parseParams('user[name]=tj&user[email][primary]=<EMAIL>').should.eql user
    end
  end
  
  describe 'toArray()'
    describe 'when given an array'
      it 'should return the array'
        toArray([1,2,3]).should.eql [1,2,3]
      end
    end
    
    describe 'when given an object with indexed values and length'
      it 'should return an array'
        var args = -{ return arguments }('foo', 'bar')
        toArray(args).should.eql ['foo', 'bar']
      end
    end
  end
  
  describe 'escape()'
    it 'should escape html'
      escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'
    end
  end
  
  describe 'extname()'
    it 'should return the a files extension'
      extname('image.png').should.eql 'png'
      extname('image.large.png').should.eql 'png'
      extname('/path/to/image.large.png').should.eql 'png'
    end
    
    it 'should return null when not found'
      extname('path').should.be_null
      extname('/just/a/path').should.be_null
    end
  end
  
  describe 'dirname()'
    it 'should return the directory path'
      dirname('/path/to/images/foo.bar.png').should.eql '/path/to/images'
    end
  end
  
  describe 'status()'
    it 'should set the response status'
      get('/user', function(){ status(500) })
      get('/user').status.should.eql 500
    end
  end
  
  describe 'header()'
    describe 'when given a field name and value'
      it 'should set the header'
        get('/user', function(){
          header('x-foo', 'bar')
        })
        get('/user').headers.should.have_property 'x-foo', 'bar'
      end  
    end
    
    describe 'when given a field name'
      it 'should return a request header value'
        get('/user', function(){
          return header('host')
        })
        get('/user').body.should.eql 'localhost'
      end
      
      it 'should be case-insensitive'
        get('/user', function(){
          return header('Host')
        })
        get('/user').body.should.eql 'localhost'
      end
    end
  end
  
  describe 'halt()'
    describe 'when given no arguments'
      it 'should respond with 404 Not Found'
        get('/user', function(){ halt() })
        get('/user').body.should.include('Not Found')
        get('/user').status.should.eql 404
      end
    end
    
    describe 'when given a status code'
      it 'should respond with that status and its associated default body'
        get('/user', function(){ halt(400) })
        get('/user').body.should.include('Bad Request')
        get('/user').status.should.eql 400        
      end
    end
    
    describe 'when given a status code and body'
      it 'should respond with the status and its body'
        get('/user', function(){ halt(400, 'Oh noes!') })
        get('/user').body.should.include('Oh noes!')
        get('/user').status.should.eql 400
      end
    end
    
    describe 'when given an invalid status code'
      it 'should throw an InvalidStatusCode exception'
        // TODO: throw_error(InvalidStatusCode, ...) when jspec is fixed
        get('/user', function(){ halt(123123) })<commit_msg>Re-ordering some specs<commit_after>
describe 'Express'
  before_each
    reset()
  end
  
  describe 'parseParams()'
    it 'should parse simple query string key / value pairs'
      parseParams('foo=bar').should.eql { foo: 'bar' }
      parseParams('foo=bar&baz=1').should.eql { foo: 'bar', baz: '1' }
    end
    
    it 'should parse named nested params'
      var user = { user: { name: 'tj', email: '<EMAIL>' }}
      parseParams('user[name]=tj&user[email]=<EMAIL>').should.eql user
    end
    
    it 'should parse several levels of nesting'
      var user = { user: { name: 'tj', email: { primary: '<EMAIL>' }}}
      parseParams('user[name]=tj&user[email][primary]=<EMAIL>').should.eql user
    end
  end
  
  describe 'toArray()'
    describe 'when given an array'
      it 'should return the array'
        toArray([1,2,3]).should.eql [1,2,3]
      end
    end
    
    describe 'when given an object with indexed values and length'
      it 'should return an array'
        var args = -{ return arguments }('foo', 'bar')
        toArray(args).should.eql ['foo', 'bar']
      end
    end
  end
  
  describe 'escape()'
    it 'should escape html'
      escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'
    end
  end
  
  describe 'extname()'
    it 'should return the a files extension'
      extname('image.png').should.eql 'png'
      extname('image.large.png').should.eql 'png'
      extname('/path/to/image.large.png').should.eql 'png'
    end
    
    it 'should return null when not found'
      extname('path').should.be_null
      extname('/just/a/path').should.be_null
    end
  end
  
  describe 'dirname()'
    it 'should return the directory path'
      dirname('/path/to/images/foo.bar.png').should.eql '/path/to/images'
    end
  end
  
  describe 'status()'
    it 'should set the response status'
      get('/user', function(){ status(500) })
      get('/user').status.should.eql 500
    end
  end
  
  describe 'header()'
    describe 'when given a field name and value'
      it 'should set the header'
        get('/user', function(){
          header('x-foo', 'bar')
        })
        get('/user').headers.should.have_property 'x-foo', 'bar'
      end  
    end
    
    describe 'when given a field name'
      it 'should return a request header value'
        get('/user', function(){
          return header('host')
        })
        get('/user').body.should.eql 'localhost'
      end
      
      it 'should be case-insensitive'
        get('/user', function(){
          return header('Host')
        })
        get('/user').body.should.eql 'localhost'
      end
    end
  end
  
  describe 'halt()'
    describe 'when given no arguments'
      it 'should respond with 404 Not Found'
        get('/user', function(){ halt() })
        get('/user').status.should.eql 404
        get('/user').body.should.include('Not Found')
      end
    end
    
    describe 'when given a status code'
      it 'should respond with that status and its associated default body'
        get('/user', function(){ halt(400) })
        get('/user').status.should.eql 400
        get('/user').body.should.include('Bad Request')
      end
    end
    
    describe 'when given a status code and body'
      it 'should respond with the status and its body'
        get('/user', function(){ halt(400, 'Oh noes!') })
        get('/user').status.should.eql 400
        get('/user').body.should.include('Oh noes!')
      end
    end
    
    describe 'when given an invalid status code'
      it 'should throw an InvalidStatusCode exception'
        // TODO: throw_error(InvalidStatusCode, ...) when jspec is fixed
        get('/user', function(){ halt(123123) })
{'fraction_non_alphanumeric': 0.14192761285075234, 'fraction_numerical': 0.010302290904161583, 'mean_word_length': 2.341485507246377, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3594520', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2265, 'n_words': 656}