<commit_before>require 'trice/errors'

module Trice
  module SpecHelper
    def self.extract_time(runtime, static_time, block)
      block ? runtime.instance_eval(&block) : static_time
    end

    def set_reference_time(static_time = nil, &block)
      around(:each) do |ex|
        time = SpecHelper.extract_time(self, static_time, block)

        Trice.with_reference_time(time) { ex.run }
      end
    end

    def set_now_as_reference_time
      set_reference_time(Time.now)
    end

    def stub_requested_at(static_time = nil, &block)
      before(:each) do |ex|
        time = SpecHelper.extract_time(self, static_time, block)

        case ex.metadata[:type]
        when :controller
          request.headers['X-Requested-At'] = time.iso8601
        when :feature
          set_header 'X-Requested-At', time.iso8601
        else
          raise Trice::TestStubbingNotSupported, "Test stubbing for type: #{ex.metadata[:type]} is not supported"
        end
      end
    end
  end
end<commit_msg>Update capybara header customize method<commit_after>require 'trice/errors'

module Trice
  module SpecHelper
    def self.extract_time(runtime, static_time, block)
      block ? runtime.instance_eval(&block) : static_time
    end

    def set_reference_time(static_time = nil, &block)
      around(:each) do |ex|
        time = SpecHelper.extract_time(self, static_time, block)

        Trice.with_reference_time(time) { ex.run }
      end
    end

    def set_now_as_reference_time
      set_reference_time(Time.now)
    end

    def stub_requested_at(static_time = nil, &block)
      before(:each) do |ex|
        time = SpecHelper.extract_time(self, static_time, block)

        case ex.metadata[:type]
        when :controller
          request.headers['X-Requested-At'] = time.iso8601
        when :feature
          page.driver.header 'X-Requested-At', time.iso8601
        else
          raise Trice::TestStubbingNotSupported, "Test stubbing for type: #{ex.metadata[:type]} is not supported"
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09099804305283757, 'fraction_numerical': 0.007827788649706457, 'mean_word_length': 2.766114180478821, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4519556', 'n_tokens_mistral': 648, 'n_tokens_neox': 630, 'n_words': 145}