Sha256: 2402e888b51214905766bc26f89e789a05e95eedbfa6db3b58e63c14219f763d

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require 'test_helper'

class CaliperTest < ActionDispatch::IntegrationTest

  setup do
    Caliper::Tracer.finish_called = false
  end

  test 'creating a caliper tracer when calling an action' do
    get "/posts"
    assert_response :success

    assert_not_nil request.env['caliper.tracer'], "should have a caliper tracer in rack env"
  end

  # TODO: Only passes when running individually
  test 'saving the samples of a default controller request to the trace' do
    get '/posts'
    assert_response :success

    assert_equal 3, request.env['caliper.tracer'].samples.size
  end

  # TODO: Only passes when running individually
  test "saving active record samples to the tracer" do
    3.times {|n| Post.create(title: "post #{n}") }
    get "/posts_with_query"
    assert_response :success

    assert_equal 4, request.env['caliper.tracer'].samples.size
    sql_samples = request.env['caliper.tracer'].samples.select { |s| s.name[/active_record/] }
    assert_equal 1, sql_samples.size
  end

  test 'calling finished after a page request' do
    get "/posts"
    assert_equal true, request.env['caliper.tracer'].finish_called
  end

  test 'disabling caliper tracer when config has enabled as false' do
    Caliper.config[:enabled] = false
    get "/posts"
    assert_nil request.env['caliper.tracer']
    Caliper.config[:enabled] = true # set it back to enabled for other tests
  end

  test "calling finish and holding exception information in samples" do
    Caliper::AppError.expects(:create)

    # TODO: Add more tests to ensure sample information is correct

    assert_raise StandardError do
      get "/posts_with_error"
    end
  end

  test "capturing no route errors" do
    Caliper::AppError.expects(:create)

    assert_raise ActionController::RoutingError do
      get "/something_that_does_not_exist"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caliper-0.0.1 spec/dummy/test/integration/caliper_test.rb