<commit_before>require 'spec_helper'

describe Keychain::Item do

  before do @item = Keychain::Item.new end

  describe 'attributes' do
    it 'is readable' do
      @item.should respond_to :attributes
    end
    it 'is writable' do
      @item.should respond_to :attributes=
    end
    it 'is initialized with a default class' do
      @item.attributes[KSecClass].should == KSecClassInternetPassword
    end
    it 'allows the default class to be overridden' do
      ret = Keychain::Item.new(KSecClass => 'zomg made up')
      ret.attributes[KSecClass].should == 'zomg made up'
    end
  end

  describe '#[]' do
    it 'should be equivalent to #attributes' do
      @item.attributes[:test] = 'test'
      @item[:test].should == 'test'
    end
    it 'should add a special case for argument KSecAttrPassword'
  end

  describe '#[]=' do
    it 'should be equivalent to #attributes=' do
      @item[:test1] = 'test'
      @item.attributes[:test1].should == 'test'
    end
    it 'should add a special case for argument KSecAttrPassword'
  end

  describe '#password' do
    before do
      @item[KSecAttrServer] = 'example.test.org'
    end
    it 'should return the stored password' do
      @item.password.should == 'password'
    end
    it 'should return an empty string for blank passwords' do
      @item[KSecAttrServer] = 'example2.test.org'
      @item.password.should be_empty
    end
    it 'should not cache the password' do
      @item.password
      @item.attributes.values.should_not include 'password'
    end
    it 'should raise an exception for an unexpected result code' do
      @item[KSecClass] = 'madeup!'
      expect { @item.password }.to raise_error Keychain::KeychainException
    end
    it 'should not mutate the stored attributes' do
      before_attributes = @item.attributes.dup
      @item.password
      @item.attributes.should == before_attributes
    end
  end

  describe '#password=' do
    before do
      @item[KSecAttrServer] = 'example3.test.org'
      @password = <PASSWORD>
    end
    it 'should return the stored password' do<commit_msg>Test caching in a more robust way<commit_after>require 'spec_helper'

describe Keychain::Item do

  before do @item = Keychain::Item.new end

  describe 'attributes' do
    it 'is readable' do
      @item.should respond_to :attributes
    end
    it 'is writable' do
      @item.should respond_to :attributes=
    end
    it 'is initialized with a default class' do
      @item.attributes[KSecClass].should == KSecClassInternetPassword
    end
    it 'allows the default class to be overridden' do
      ret = Keychain::Item.new(KSecClass => 'zomg made up')
      ret.attributes[KSecClass].should == 'zomg made up'
    end
  end

  describe '#[]' do
    it 'should be equivalent to #attributes' do
      @item.attributes[:test] = 'test'
      @item[:test].should == 'test'
    end
    it 'should add a special case for argument KSecAttrPassword'
  end

  describe '#[]=' do
    it 'should be equivalent to #attributes=' do
      @item[:test1] = 'test'
      @item.attributes[:test1].should == 'test'
    end
    it 'should add a special case for argument KSecAttrPassword'
  end

  describe '#password' do
    before do
      @item[KSecAttrServer] = 'example.test.org'
    end
    it 'should return the stored password' do
      @item.password.should == 'password'
    end
    it 'should return an empty string for blank passwords' do
      @item[KSecAttrServer] = 'example2.test.org'
      @item.password.should be_empty
    end
    it 'should not cache the password' do
      cached_password = @item.password
      @item.attributes.values.should_not include cached_password
    end
    it 'should raise an exception for an unexpected result code' do
      @item[KSecClass] = 'madeup!'
      expect { @item.password }.to raise_error Keychain::KeychainException
    end
    it 'should not mutate the stored attributes' do
      before_attributes = @item.attributes.dup
      @item.password
      @item.attributes.should == before_attributes
    end
  end

  describe '#password=' do
    before do
      @item[KSecAttrServer] = 'example3.test.org'
      @password = <PASSWORD>
    end
    it 'should return the stored password' do
{'fraction_non_alphanumeric': 0.09466192170818505, 'fraction_numerical': 0.0018979833926453143, 'mean_word_length': 2.9365079365079363, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5585811', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1234, 'n_words': 414}