Sha256: 543552c81ae1dcdcb005d4215af715369826bee3a0c007d15dc11bee974404a5

Contents?: true

Size: 1.88 KB

Versions: 53

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

describe S3Website::Keyboard do
  describe '.keep_or_delete' do
    let(:s3_object_keys) { ['a', 'b', 'c'] }
    let(:standard_input) { stub('std_in') }

    it 'can delete only the first item' do
      standard_input.stub(:gets).and_return("d", "K")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq(['a'])
    end

    it 'can delete only the second item' do
      standard_input.stub(:gets).and_return("k", "d", "k")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq(['b'])
    end

    it 'can delete all but the first item' do
      standard_input.stub(:gets).and_return("k", "D")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq(['b', 'c'])
    end

    it 'can delete all s3 objects' do
      standard_input.stub(:gets).and_return("D")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq(['a', 'b', 'c'])
    end

    it 'can keep one s3 object' do
      standard_input.stub(:gets).and_return("k", "d", "d")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq(['b', 'c'])
    end

    it 'can keep all s3 objects' do
      standard_input.stub(:gets).and_return("k", "k", "k")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq([])
    end

    it 'can keep all s3 objects' do
      standard_input.stub(:gets).and_return("K")
      deleted_keys = call_keyboard(s3_object_keys, standard_input)
      deleted_keys.should eq([])
    end

    def call_keyboard(s3_object_keys, standard_input)
      deleted_keys = []
      S3Website::Keyboard.if_user_confirms_delete(
        s3_object_keys,
        config = {},
        standard_input
      ) { |key|
        deleted_keys << key
      }
      deleted_keys
    end
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
s3_website-1.4.4 spec/lib/keyboard_spec.rb
s3_website-1.4.3 spec/lib/keyboard_spec.rb
s3_website-1.4.2 spec/lib/keyboard_spec.rb
s3_website-1.4.1 spec/lib/keyboard_spec.rb
s3_website-1.4.0 spec/lib/keyboard_spec.rb
s3_website-1.3.2 spec/lib/keyboard_spec.rb
s3_website-1.3.1 spec/lib/keyboard_spec.rb
s3_website-1.3.0 spec/lib/keyboard_spec.rb
s3_website-1.2.1 spec/lib/keyboard_spec.rb
s3_website-1.2.0 spec/lib/keyboard_spec.rb
s3_website-1.1.2 spec/lib/keyboard_spec.rb
s3_website-1.1.1 spec/lib/keyboard_spec.rb
s3_website-1.1.0 spec/lib/keyboard_spec.rb