spec/keychain_spec.rb in ruby-keychain-0.3.2 vs spec/keychain_spec.rb in ruby-keychain-0.4.0

- old
+ new

@@ -15,11 +15,11 @@ end end describe 'default' do it "should return the login keychain" do - expect(Keychain.default.path).to eq(File.expand_path(File.join(ENV['HOME'], 'Library','Keychains', 'login.keychain'))) + expect(Keychain.default.path).to eq(File.expand_path(File.join(ENV['HOME'], 'Library','Keychains', 'login.keychain-db'))) end end describe 'open' do it 'should create a keychain reference to a path' do @@ -43,17 +43,24 @@ end end context 'no password supplied' do #we have to stub this out as it would trigger a dialog box prompting for a password + let(:result) do + instance_double(Keychain::Keychain) + end + it 'should create a keychain by prompting the user' do #we can't just use a kind_of matcher becaue FFI::Pointer#== raises an exception #when compared to non pointer values - mock_pointer = double(FFI::MemoryPointer, :read_pointer => 0) + mock_pointer = double(FFI::MemoryPointer, :read_pointer => 123456) allow(FFI::MemoryPointer).to receive(:new).with(:pointer).and_return(mock_pointer) expect(Sec).to receive('SecKeychainCreate').with('akeychain', 0, nil, 1, nil,mock_pointer).and_return(0) - Keychain.create('akeychain') + + expect(Keychain::Keychain).to receive(:new).with(mock_pointer.read_pointer).and_return(result) + expect(result).to receive(:release_on_gc).and_return(result) + expect(Keychain.create('akeychain')).to eq(result) end end end describe 'import' do \ No newline at end of file