Sha256: 5cdc8c8070f5f23b4af3b94c39659bb9f581635474081d1906c501637fb0b6b4

Contents?: true

Size: 1.56 KB

Versions: 64

Compression:

Stored size: 1.56 KB

Contents

RSpec::Support.require_rspec_core('formatters/profile_formatter')

module KnapsackPro
  module Formatters
    module RSpecQueueProfileFormatterExtension
      def self.print_summary
        return unless KnapsackPro::Config::Env.modify_default_rspec_formatters?
        RSpec::Core::Formatters::ProfileFormatter.print_profile_summary
      end

      def initialize(output)
        @output = output
        self.class.registered_output = output
      end

      def dump_profile(profile)
        self.class.most_recent_profile = profile
      end
    end
  end
end

if KnapsackPro::Config::Env.modify_default_rspec_formatters?
  class RSpec::Core::Formatters::ProfileFormatter
    prepend KnapsackPro::Formatters::RSpecQueueProfileFormatterExtension

    def self.registered_output=(output)
      @registered_output = {
        ENV['KNAPSACK_PRO_QUEUE_ID'] => output
      }
    end

    def self.registered_output
      @registered_output ||= {}
      @registered_output[ENV['KNAPSACK_PRO_QUEUE_ID']]
    end

    def self.most_recent_profile=(profile)
      @most_recent_profile = {
        ENV['KNAPSACK_PRO_QUEUE_ID'] => profile
      }
    end

    def self.most_recent_profile
      @most_recent_profile ||= {}
      @most_recent_profile[ENV['KNAPSACK_PRO_QUEUE_ID']] || []
    end

    def self.print_profile_summary
      return unless registered_output
      profile_formatter = new(registered_output)
      profile_formatter.send(:dump_profile_slowest_examples,  most_recent_profile)
      profile_formatter.send(:dump_profile_slowest_example_groups, most_recent_profile)
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
knapsack_pro-2.1.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-2.0.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.22.3 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.22.2 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.22.1 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.22.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.21.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.20.2 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.20.1 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.20.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.19.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.18.2 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.18.1 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.18.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.17.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.16.1 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.16.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.15.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.14.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb
knapsack_pro-1.13.0 lib/knapsack_pro/formatters/rspec_queue_profile_formatter_extension.rb