Sha256: 56467ad209eb52fd82bbabc1b1bc358dfee824451d9fcd05fcde3175c201f4d1

Contents?: true

Size: 1.17 KB

Versions: 35

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require File.expand_path("../../test_helper", File.dirname(__FILE__))
require "coverband/integrations/report_middleware"

class ReportMiddlewareTest < Minitest::Test
  def setup
    super
    Coverband.configure do |config|
      config.background_reporting_enabled = false
    end
  end

  test "reports coverage" do
    request = Rack::MockRequest.env_for("/anything.json")
    Coverband::Collectors::Coverage.instance.expects(:report_coverage)
    middleware = Coverband::ReportMiddleware.new(fake_app)
    middleware.call(request)
  end

  test "reports coverage when an error is raised" do
    request = Rack::MockRequest.env_for("/anything.json")
    Coverband::Collectors::Coverage.instance.reset_instance
    Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
    middleware = Coverband::ReportMiddleware.new(fake_app_raise_error)
    begin
      middleware.call(request)
    rescue
      nil
    end
  end

  private

  def fake_app
    @fake_app ||= lambda do |env|
      [200, {"Content-Type" => "text/plain"}, env["PATH_INFO"]]
    end
  end

  def fake_app_raise_error
    @fake_app_raise_error ||= -> { raise "hell" }
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
coverband-5.2.6.rc.6 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.3.2 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.6.rc.5 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.3.1 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.6.rc.4 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.6.rc.3 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.6.rc.2 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.6.rc.1 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.5 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.5.rc.3 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.5.rc.2 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.5.rc.1 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.4 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.3 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.2 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.1 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.1.rc.1 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.0 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.0.rc.2 test/coverband/integrations/report_middleware_test.rb
coverband-5.2.0.rc.1 test/coverband/integrations/report_middleware_test.rb