<commit_before>require 'spec_helper'
require 'fakefs/safe'

describe Bucket::CLI do
  subject { Bucket::CLI.new }

  # Use a fake filesystem and clear it after each test
  before do
   FakeFS.activate!

   # Create a fake user's home (in reality this folder will exist)
   FileUtils.mkdir_p(Dir.home)
  end
  after do
   FakeFS.deactivate!
   FakeFS::FileSystem.clear
  end

  it "saves the user and password to the configuration file" do
    mock_credentials

    # The setup is run when initializing the CLI
    out = capture_io { subject }

    config = YAML.load_file("#{Dir.home}/.bucket")
    config.must_equal({ "username" => "user", "password" => "password" })
  end

  it "replaces the user and password when calling setup" do
    mock_credentials

    # Run the setup when initializing
    capture_io { subject }

    # Run the setup again with other credentials
    mock_credentials("other_user", "other_password")
    capture_io { subject.setup }

    config = YAML.load_file("#{Dir.home}/.bucket")
    config.must_equal({ "username" => "other_user", "password" => "<PASSWORD>" })
  end<commit_msg>Added more specs<commit_after>require 'spec_helper'
require 'fakefs/safe'

describe Bucket::CLI do
  subject { Bucket::CLI.new }

  # Use a fake filesystem and clear it after each test
  before do
    mock_credentials
    FakeFS.activate!

    # Create a fake user's home (in reality this folder will exist)
    FileUtils.mkdir_p(Dir.home)
  end
  after do
    FakeFS.deactivate!
    FakeFS::FileSystem.clear
  end

  it "saves the user and password to the configuration file" do
    # The setup is run when initializing the CLI
    out = capture_io { subject }

    config = YAML.load_file("#{Dir.home}/.bucket")
    config.must_equal({ "username" => "user", "password" => "password" })
  end

  it "replaces the user and password when calling setup" do
    # Run the setup when initializing (and ignore output)
    capture_io { subject }

    # Run the setup again with other credentials
    mock_credentials("other_user", "<PASSWORD>")
    capture_io { subject.setup }

    config = YAML.load_file("#{Dir.home}/.bucket")
    config.must_equal({ "username" => "other_user", "password" => "<PASSWORD>" })
  end

  it "displays a list of the user's repositories" do
    any_instance_of(Bucket::Client) do |client|
      mock(client).repos_list do
        [
          { owner: "user", slug: "repository" },
          { owner: "other_user", slug: "other_repository" }
        ]
      end
    end

    out = capture_io { subject.repos }.join('')
    out.must_match(/user\/repository/)
    out.must_match(/other_user\/other_repository/)
  end
{'fraction_non_alphanumeric': 0.1095166163141994, 'fraction_numerical': 0.0, 'mean_word_length': 3.2864077669902914, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '4857467', 'n_tokens_mistral': 852, 'n_tokens_neox': 803, 'n_words': 250}