<commit_before>require_relative 'spec_helper'
require 'minitest/mock'
require 'awesome_print'
require 'rails_riemann_middleware/duration'

describe RailsRiemannMiddleware::Duration do
  
  before do
    @start_time = Time.at(0)
    @env = {}
    @event = MiniTest::Mock.new
    @event.expect :app_prefix, "TEST APP"
  end

  it "should set the duration to 100 second" do
    d = RailsRiemannMiddleware::Duration.new(@event, @env, @start_time)
    Time.stub :new, Time.at(100) do
      d.message[:metric].must_equal 100
    end
  end

  it "should set the host to the value of HTTP_HOST" do
    @env["HTTP_HOST"] = "my.test.host"
    d = RailsRiemannMiddleware::Duration.new(@event, @env, @start_time)
    d.message[:host].must_equal "my.test.host"
  end

  it "should add the hash to the message array" do
    to_send = []
    def to_send.app_prefix
      "TEST APP"
    end
    d = RailsRiemannMiddleware::Duration.new(to_send, @env, @start_time)
    result = d.send
    result.size.must_equal 1
    result.first[:service].must_match /^TEST APP/
  end
  
end<commit_msg>Add spec for the state to default to info<commit_after>require_relative 'spec_helper'
require 'minitest/mock'
require 'awesome_print'
require 'rails_riemann_middleware/duration'

describe RailsRiemannMiddleware::Duration do
  
  before do
    @start_time = Time.at(0)
    @env = {}
    @event = MiniTest::Mock.new
    @event.expect :app_prefix, "TEST APP"
  end

  it "should set the duration to 100 second" do
    d = RailsRiemannMiddleware::Duration.new(@event, @env, @start_time)
    Time.stub :new, Time.at(100) do
      d.message[:metric].must_equal 100
    end
  end

  it "should set the host to the value of HTTP_HOST" do
    @env["HTTP_HOST"] = "my.test.host"
    d = RailsRiemannMiddleware::Duration.new(@event, @env, @start_time)
    d.message[:host].must_equal "my.test.host"
  end

  it "should add the hash to the message array" do
    to_send = []
    def to_send.app_prefix
      "TEST APP"
    end
    d = RailsRiemannMiddleware::Duration.new(to_send, @env, @start_time)
    result = d.send
    result.size.must_equal 1
    result.first[:service].must_match /^TEST APP/
  end

  it "should have a state of 'info'" do
    d = RailsRiemannMiddleware::Duration.new(@event, @env, @start_time)
    d.message[:state].must_equal "info"    
  end
  
end
{'fraction_non_alphanumeric': 0.11315902271753107, 'fraction_numerical': 0.009429918559794257, 'mean_word_length': 3.5320388349514564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4857481', 'n_tokens_mistral': 842, 'n_tokens_neox': 797, 'n_words': 208}