<commit_before>require 'spec_helper'

describe SecretStore, "initializing" do
  let(:tmpfile) { Tempfile.new("secret_store") }

  it "takes a password and file path" do
    subject = SecretStore.new("pass", tmpfile.path)
    subject.file_path.should == tmpfile.path
  end
end

describe SecretStore, "storing a secret" do
  let(:tmpfile) { Tempfile.new("secret_store") }
  subject { SecretStore.new("the_pass", tmpfile.path) }

  context "when the key is not already stored" do
    it "stores the value for the key in a yaml data file" do
      subject.store("foobar", "fizzbuzz")
      data = YAML.load_file(tmpfile.path)
      data["foobar"].should_not be_empty
    end

    it "stores in an encrypted fashion" do
      subject.store("foobar", "fizzbuzz")
      data = YAML.load_file(tmpfile.path)
      data["foobar"].should_not == "fizzbuzz"
    end

    it "leaves other data in the store file intact" do
      tmpfile.puts YAML.dump("already" => "here")
      tmpfile.flush
      subject.store("foobar", "fizzbuzz")
      data = YAML.load_file(tmpfile.path)
      data["already"].should == "here"
    end
  end

  context "when the key is already stored" do
    it "raises if not forced" do
      subject.store("foobar", "fizzbuzz")
      lambda {
        subject.store("foobar", "fizzbuzz")
      }.should raise_error
    end

    it "stores if forced" do
      subject.store("foobar", "fizzbuzz")
      lambda {
        subject.store("foobar", "fizzbuzz", :force)
      }.should_not raise_error
    end
  end
end

describe SecretStore, "getting a secret" do
  let(:tmpfile) { Tempfile.new("secret_store") }
  subject { SecretStore.new("the_pass", tmpfile.path) }

  it "returns the decrypted secret" do
    subject.store("foobar", "fizzbuzz")
    subject.get("foobar").should == "fizzbuzz"
  end

  it "raises IndexError if the key is not found" do
    lambda{<commit_msg>Make code in :forced spec more explicit<commit_after>require 'spec_helper'

describe SecretStore, "initializing" do
  let(:tmpfile) { Tempfile.new("secret_store") }

  it "takes a password and file path" do
    subject = SecretStore.new("pass", tmpfile.path)
    subject.file_path.should == tmpfile.path
  end
end

describe SecretStore, "storing a secret" do
  let(:tmpfile) { Tempfile.new("secret_store") }
  subject { SecretStore.new("the_pass", tmpfile.path) }

  context "when the key is not already stored" do
    it "stores the value for the key in a yaml data file" do
      subject.store("foobar", "fizzbuzz")
      data = YAML.load_file(tmpfile.path)
      data["foobar"].should_not be_empty
    end

    it "stores in an encrypted fashion" do
      subject.store("foobar", "fizzbuzz")
      data = YAML.load_file(tmpfile.path)
      data["foobar"].should_not == "fizzbuzz"
    end

    it "leaves other data in the store file intact" do
      tmpfile.puts YAML.dump("already" => "here")
      tmpfile.flush
      subject.store("foobar", "fizzbuzz")
      data = YAML.load_file(tmpfile.path)
      data["already"].should == "here"
    end
  end

  context "when the key is already stored" do
    it "raises if not forced" do
      subject.store("foobar", "fizzbuzz")
      lambda {
        subject.store("foobar", "fizzbuzz")
      }.should raise_error
    end

    it "stores if forced" do
      subject.store("foobar", "fizzbuzz")
      subject.store("foobar", "buzzfizz", :force)
      subject.get("foobar").should == "buzzfizz"
    end
  end
end

describe SecretStore, "getting a secret" do
  let(:tmpfile) { Tempfile.new("secret_store") }
  subject { SecretStore.new("the_pass", tmpfile.path) }

  it "returns the decrypted secret" do
    subject.store("foobar", "fizzbuzz")
    subject.get("foobar").should == "fizzbuzz"
  end

  it "raises IndexError if the key is not found" do
    lambda{
{'fraction_non_alphanumeric': 0.12206076618229855, 'fraction_numerical': 0.0, 'mean_word_length': 3.2779661016949153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5254516', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1241, 'n_words': 344}