Verified Commit db7db3fa authored by Kamil Trzciński's avatar Kamil Trzciński Committed by GitLab
Browse files

Merge branch 'sh-clear-labkit-context' into 'master'

feat: add Labkit::Context.clear for resetting context between tests

See merge request !253

Merged-by: default avatarKamil Trzciński <ayufan@ayufan.eu>
Approved-by: default avatarKamil Trzciński <ayufan@ayufan.eu>
Reviewed-by: default avatarGitLab Duo <gitlab-duo@gitlab.com>
Co-authored-by: default avatarStan Hu <stanhu@gmail.com>
parents 37ea74e2 4445e242
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -66,6 +66,10 @@ module Labkit
        contexts.last
      end

      def clear
        Thread.current[:labkit_contexts] = nil
      end

      def log_key(key)
        key = key.to_s
        return key if RAW_KEYS.include?(key)
+16 −0
Original line number Diff line number Diff line
@@ -93,6 +93,22 @@ describe Labkit::Context do
    end
  end

  describe ".clear" do
    it "removes all contexts from the stack" do
      described_class.push
      described_class.push

      described_class.clear

      expect(Thread.current[:labkit_contexts]).to be_nil
      expect(described_class.current).to be_nil
    end

    it "does nothing when the stack is already empty" do
      expect { described_class.clear }.not_to raise_error
    end
  end

  describe ".current" do
    let!(:root_context) { described_class.push }