<commit_before>require 'stringio'
require 'timeout'
require_relative '../../lib/passman'
require_relative 'mock_standard_in'

module CommandHelper
  attr_reader :stdout, :stderr

  def invoke(*argv)
    if @app
      @app.join
      @app = nil
    end

    @stdin = MockStandardIn.new
    @app = Thread.new do
      previous_stdin, $stdin = $stdin, @stdin

      @stdout, @stderr = capture_output do
        Passman::App.run argv.flatten
      end

      $stdin = previous_stdin
    end
  end

  def simple_invoke(*argv)
    @stdout, @stderr = capture_output do
      Passman::App.run argv.flatten
    end
  end

  def enter(text)
    @stdin.enter text
  end

  def capture_output
    $previous_stdout, $stdout = $stdout, StringIO.new
    $previous_stderr, $stderr = $stderr, StringIO.new

    yield

    [$stdout.string, $stderr.string]
  ensure
    $stdout = $previous_stdout
    $stderr = $previous_stderr
  end

  def dump_output
    puts "STDOUT:\n#{stdout}"
    puts "STDERR:\n#{stderr}"
  end

  def delay_until
    Timeout.timeout(2.5) do
      while true
        sleep 0.01
        begin
          return yield
        rescue RSpec::Expectations::ExpectationNotMetError
        end
      end
    end
  end
end<commit_msg>Use one second timeout in cukes<commit_after>require 'stringio'
require 'timeout'
require_relative '../../lib/passman'
require_relative 'mock_standard_in'

module CommandHelper
  attr_reader :stdout, :stderr

  def invoke(*argv)
    if @app
      @app.join
      @app = nil
    end

    @stdin = MockStandardIn.new
    @app = Thread.new do
      previous_stdin, $stdin = $stdin, @stdin

      @stdout, @stderr = capture_output do
        Passman::App.run argv.flatten
      end

      $stdin = previous_stdin
    end
  end

  def simple_invoke(*argv)
    @stdout, @stderr = capture_output do
      Passman::App.run argv.flatten
    end
  end

  def enter(text)
    @stdin.enter text
  end

  def capture_output
    $previous_stdout, $stdout = $stdout, StringIO.new
    $previous_stderr, $stderr = $stderr, StringIO.new

    yield

    [$stdout.string, $stderr.string]
  ensure
    $stdout = $previous_stdout
    $stderr = $previous_stderr
  end

  def dump_output
    puts "STDOUT:\n#{stdout}"
    puts "STDERR:\n#{stderr}"
  end

  def delay_until
    Timeout.timeout(1) do
      while true
        sleep 0.01
        begin
          return yield
        rescue RSpec::Expectations::ExpectationNotMetError
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09329563812600969, 'fraction_numerical': 0.0036348949919224557, 'mean_word_length': 2.5134751773049646, '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': '227998', 'n_tokens_mistral': 822, 'n_tokens_neox': 798, 'n_words': 204}