Skip to content

Instantly share code, notes, and snippets.

@FluffyCode
Forked from koriroys/even_better.rb
Created July 1, 2014 17:54
Show Gist options
  • Save FluffyCode/e4c68161b2dd28ff4073 to your computer and use it in GitHub Desktop.
Save FluffyCode/e4c68161b2dd28ff4073 to your computer and use it in GitHub Desktop.
# Original method
#def process(input)
# if input == 'q'
# puts 'Goodbye'
# elsif input == 'tweet'
# puts 'tweeting'
# elsif input == 'dm'
# puts 'direct messaging'
# elsif input == 'help'
# puts 'helping'
# end
#end
RESPONSES = {
'tweet' => 'tweeting',
'dm' => 'direct messaging',
'help' => 'helping',
'q' => 'Goodbye'
}
def process(input)
puts RESPONSES.fetch(input) { return nil }
end
describe 'process' do
it 'prints "Goodbye" when called with input of "q"' do
STDOUT.should_receive(:puts).with('Goodbye')
process('q')
end
it 'prints "tweeting" when called with input of "tweet"' do
STDOUT.should_receive(:puts).with('tweeting')
process('tweet')
end
it 'prints "direct messaging" when called with input of "dm"' do
STDOUT.should_receive(:puts).with('direct messaging')
process('dm')
end
it 'prints "helping" when called with input of "help"' do
STDOUT.should_receive(:puts).with('helping')
process('help')
end
it 'returns nil when called with any other input ' do
STDOUT.should_not_receive(:puts)
expect(process('bad input')).to eq(nil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment