Implement `ask' recipe keyword

This commit is contained in:
Thibault Jouan
2013-12-22 23:54:19 +00:00
parent 70109615c8
commit 7e062e06a1
7 changed files with 114 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ require 'spec_helper'
module Producer::Core
describe Task::DSL do
let(:block) { proc {} }
let(:env) { double 'env' }
let(:env) { Env.new }
subject(:dsl) { Task::DSL.new(env, &block) }
%w[echo sh file_write].each do |action|
@@ -82,5 +82,25 @@ module Producer::Core
end
end
end
describe '#ask' do
let(:question) { 'Which letter?' }
let(:choices) { %w[A B] }
let(:prompter_class) { double('prompter class').as_null_object }
subject(:ask) { dsl.ask question, choices,
prompter: prompter_class }
it 'builds a prompter' do
expect(prompter_class).to receive(:new).with(env.input, env.output)
ask
end
it 'prompts and returns the choice' do
prompter = double 'prompter'
allow(prompter_class).to receive(:new) { prompter }
allow(prompter).to receive(:prompt) { :choice }
expect(ask).to eq :choice
end
end
end
end