Sha256: a07e04825bf6c0cbc35265a61e9cdddd6c2fe0ea0bb6410d62437f0d5f314585

Contents?: true

Size: 1.85 KB

Versions: 19

Compression:

Stored size: 1.85 KB

Contents

module CodeClimate
  module TestReporter
    class WebMockMessage
      def library_name
        "WebMock"
      end

      def instructions
        <<-STR
  WebMock.disable_net_connect!(:allow => "codeclimate.com")
        STR
      end
    end

    class VCRMessage
      def library_name
        "VCR"
      end

      def instructions
        <<-STR
  VCR.configure do |config|
    # your existing configuration
    config.ignore_hosts 'codeclimate.com'
  end
        STR
      end
    end

    class ExceptionMessage
      HTTP_STUBBING_MESSAGES = {
        "VCR::Errors::UnhandledHTTPRequestError".freeze => VCRMessage,
        "WebMock::NetConnectNotAllowedError".freeze => WebMockMessage,
      }.freeze

      def initialize(exception)
        @exception = exception
      end

      def message
        parts = []
        parts << "Code Climate encountered an exception: #{exception_class}"
        if http_stubbing_exception
          message = http_stubbing_exception.new
          parts << "======"
          parts << "Hey! Looks like you are using #{message.library_name}, which will prevent the codeclimate-test-reporter from reporting results to codeclimate.com.
Add the following to your spec or test helper to ensure codeclimate-test-reporter can post coverage results:"
          parts << "\n" + message.instructions + "\n"
          parts << "======"
          parts << "If this doesn't work, please consult https://codeclimate.com/docs#test-coverage-troubleshooting"
          parts << "======"
        else
          parts << @exception.message
          @exception.backtrace.each do |line|
            parts << line
          end
        end
        parts.join("\n")
      end

      private

      def exception_class
        @exception.class.to_s
      end

      def http_stubbing_exception
        HTTP_STUBBING_MESSAGES[exception_class]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
codeclimate-test-reporter-1.0.9 lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.8 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.7 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.6 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.5 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.4 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.3 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.2 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.1 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.0 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.0.pre.rc2 lib/code_climate/test_reporter/exception_message.rb
codeclimate-test-reporter-1.0.0.pre.rc1 lib/code_climate/test_reporter/exception_message.rb