spec/unit/configuration/asker_spec.rb in imap-backup-1.0.9 vs spec/unit/configuration/asker_spec.rb in imap-backup-1.0.10
- old
+ new
@@ -1,23 +1,60 @@
# encoding: utf-8
require 'spec_helper'
-module Imap::Backup::Configuration
- describe Asker do
+module Imap::Backup
+ describe Configuration::Asker do
let(:highline) { double }
+ let(:query) do
+ double(
+ 'Query',
+ :default= => nil,
+ :readline= => nil,
+ :validate= => nil,
+ :responses => {},
+ :echo= => nil
+ )
+ end
+ let(:answer) { 'foo' }
- subject { Asker.new(highline) }
+ before do
+ allow(Configuration::Setup).to receive(:highline).and_return(highline)
+ allow(highline).to receive(:ask) do |&b|
+ b.call query
+ answer
+ end
+ end
+ subject { described_class.new(highline) }
+
+ [
+ [:email, [], 'email address'],
+ [:password, [], 'password'],
+ [:backup_path, ['x', 'y'], 'backup directory'],
+ ].each do |method, params, prompt|
+ context ".#{method}" do
+ it 'asks for input' do
+ described_class.send(method, *params)
+
+ expect(highline).to have_received(:ask).with("#{prompt}: ")
+ end
+
+ it 'returns the answer' do
+ expect(described_class.send(method, *params)).to eq(answer)
+ end
+ end
+ end
+
context '#initialize' do
its(:highline) { should eq(highline) }
end
context '#email' do
let(:email) { 'email@example.com' }
+ let(:answer) { email }
before do
- allow(highline).to receive(:ask).and_return(email)
@result = subject.email
end
it 'asks for an email' do
expect(highline).to have_received(:ask).with(/email/)
@@ -68,12 +105,16 @@
end
end
context '#backup_path' do
let(:path) { '/path' }
+ let(:answer) { path }
before do
- allow(highline).to receive(:ask).and_return(path)
+ allow(highline).to receive(:ask) do |&b|
+ b.call query
+ path
+ end
@result = subject.backup_path('', //)
end
it 'asks for a directory' do
expect(highline).to have_received(:ask).with(/directory/)