<commit_before>require 'test/spec'
require 'stringio'

require 'rack/commonlogger'
require 'rack/lobster'
require 'rack/testrequest'

context "Rack::CommonLogger" do
  specify "should log to rack.errors by default" do
    log = StringIO.new
    _,_, b = Rack::CommonLogger.new(lambda { |env|
                                      [200,
                                       {"Content-Type" => "text/html"},
                                       ["foo"]]
                                    }).
      call(TestRequest.env({'rack.errors' => log}))
    b.each { }

    log.string.should =~ /GET /
    log.string.should =~ / 200 / # status
    log.string.should =~ / 3 / # length
  end

  specify "should log to anything with <<" do
    log = ""
    _,_, b = Rack::CommonLogger.new(lambda { |env|
                                      [200,
                                       {"Content-Type" => "text/html"},
                                       ["foo"]]
                                    },
                                    log).call(TestRequest.env({}))
    b.each { }

    log.should =~ /GET /
    log.should =~ / 200 / # status
    log.should =~ / 3 / # length
  end
end<commit_msg>Make spec_rack_commonlogger.rb use mocks<commit_after>require 'test/spec'
require 'stringio'

require 'rack/commonlogger'
require 'rack/lobster'
require 'rack/mock'

context "Rack::CommonLogger" do
  App = lambda { |env|
    [200,
     {"Content-Type" => "text/html"},
     ["foo"]]}

  specify "should log to rack.errors by default" do
    log = StringIO.new
    res = Rack::MockRequest.new(Rack::CommonLogger.new(App)).get("/")

    res.errors.should.not.be.empty
    res.errors.should =~ /GET /
    res.errors.should =~ / 200 / # status
    res.errors.should =~ / 3 /   # length
  end

  specify "should log to anything with <<" do
    log = ""
    res = Rack::MockRequest.new(Rack::CommonLogger.new(App, log)).get("/")

    log.should =~ /GET /
    log.should =~ / 200 / # status
    log.should =~ / 3 / # length
  end
end
{'fraction_non_alphanumeric': 0.14448292924294903, 'fraction_numerical': 0.012370113805047007, 'mean_word_length': 1.6328125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6487830', 'n_tokens_mistral': 658, 'n_tokens_neox': 614, 'n_words': 134}