Skip to content

Instantly share code, notes, and snippets.

@elizabrock
Created April 16, 2014 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elizabrock/10905532 to your computer and use it in GitHub Desktop.
Save elizabrock/10905532 to your computer and use it in GitHub Desktop.
# Build on the results of our in-class exploration to output, for example:
# Give me an... A
# Give me a... B
# Give me a... B
# Give me a... Y
# ABBY’s just GRAND!
# When given the input of “Abby”. Note: the “a” vs. “an”
name = gets.chomp
name.each_char do |char|
puts "Give me a.. #{char.upcase}"
end
require "minitest/autorun"
# These helpers are just some toys if you want to try them!
# I pulled them out of the NSS-futureperfect-CLI repo.
def strip_control_characters_and_excesses(string)
last = string.split("\033[2;0f").last#.gsub(/(\e\[\d+\w)|(\e\[\w)/,"")
if last.empty?
""
else
last.gsub(/(\e\[\d+\w)|(\e\[\w)/,"").gsub(" +","")
end
end
def assert_includes_in_order input, *items
input = strip_control_characters_and_excesses(input)
regexp_string = items.join(".*").gsub("?","\\?")
assert_match /#{regexp_string}/, input.delete("\n"), "Expected /#{regexp_string}/ to match:\n" + input
end
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rake/testtask'
Rake::TestTask.new() do |t|
t.pattern = "test/test_*.rb"
end
desc "Run tests"
task :default => :test
require_relative 'helper'
class TestCheersIntegration < MiniTest::Unit::TestCase
def test_a_name_with_no_vowels
shell_output = ""
IO.popen('ruby cheers.rb', 'r+') do |pipe|
pipe.puts "BRT"
pipe.close_write
shell_output = pipe.read
end
expected_output = <<EOS
Give me a.. B
Give me a.. R
Give me a.. T
EOS
assert_equal expected_output, shell_output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment