Created
April 16, 2014 16:47
-
-
Save elizabrock/10905532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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