<commit_before>RSpec.describe 'console' do
  pending
end

# TODO: how to test a long running process that expect a tty
# RSpec.describe 'console' do
#   around do |example|
#     # start console
#     cmd = 'cd spec/dummy && nibtest console web'
#     `setsid sh -c 'exec "#{cmd}" <> /dev/tty2 >&0 2>&1'`

#     sleep 5

#     example.run

#     puts `docker ps`
#     # TODO: stop console
#   end

#   context command("docker-compose exec web /bin/bash 'ps x; exit'") do
#     its(:stdout) { should match(/pry/) }
#   end
# end<commit_msg>Implement spec for console command<commit_after>require 'pty'

RSpec.describe 'console' do
  def tty
    PTY.spawn('cd spec/dummy && nibtest console web') do |stdout, stdin, pid|
      stdout.eof?

      yield(stdout, stdin)

      stdin.puts 'exit'

      Process.waitpid(pid, 0)

      stdin.close
      stdout.close
    end
  end

  it 'starts a pry session and accepts input' do
    tty do |stdout, stdin|
      # ideally we do not have to write a message at all, we simply want to
      # check for a prompt. however if we do not perform a #puts here then
      # stdout.gets hangs indefinitely.
      stdin.puts 'puts "foo"'

      expect(stdout.gets).to match(/puts \"foo\"/)
      expect(stdout.gets).to match(/pry\(main\)>/)
    end
  end
end
{'fraction_non_alphanumeric': 0.1185127807900852, 'fraction_numerical': 0.004647560030983733, 'mean_word_length': 2.5789473684210527, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '5754140', 'n_tokens_mistral': 458, 'n_tokens_neox': 433, 'n_words': 149}