You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: command_handler_helpers.rb
    path of file: ./repos/sequent/lib/sequent/test
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'thread_safe'
require 'sequent/core/event_store'

module Sequent
  module Test
    ##
    # Use in tests
    #
    # This provides a nice DSL for event based testing of your CommandHandler like
    #
    # given_events In
    
      def then_events(*expected_events)
        expected_classes = expected_events.flatten(1).map { |event| event.instance_of?(Class) ? event : event.class }
        expect(Sequent.configuration.event_store.stored_events.map(&:class)).to eq(expected_classes)

        Sequent
          .configuration
          .event_store
          .stored_events
          .zip(expected_events.flatten(1))
          .each_with_index do |(actual, expected), index|
            next if expected.instance_of?(Class)

            actual_hash = Sequent::Core::Oj.strict_load(Sequent::Core::Oj.dump(actual.payload))
            expected_hash = Sequent::Core::Oj.strict_load(Sequent::Core::Oj.dump(expected.payload))
            next unless expected

            # rubocop:disable Layout/LineLength
            expect(actual_hash)
              .to eq(expected_hash),
                  "#{index + 1}th Event of type #{actual.class} not equal\nexpected: #{expected_hash.inspect}\n     got: #{actual_hash.inspect}"
            # rubocop:enable Layout/LineLength
          end
      end