Skip to content

Commit

Permalink
Add README test
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Jul 25, 2017
1 parent 82db2e9 commit 6488ed2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/readme_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require_relative "test_helper"

describe "readme" do
it "'bashcached --help' output is same" do
skip "this spec is not related to memcached" if TEST_MEMCACHED

readme = File.read("README.md")
.match(%r{(?<=^\$ \.\/bashcached --help\n).*?(?=^\$ )}m)
.to_s
help = `./bashcached --help`
readme.must_equal help
end

it "example can run" do
example = File.read("README.md")
.match(%r{(?<=^\$ telnet localhost 25252\n).*?(?=^```)}m)
.to_s
# TODO: .lines(chomp: true)
# ruby on ubuntu 17.10 is still 2.3.x...
.lines
.map(&:chomp)
with_bashcached_and_client do |client|
while example.empty?
case line = example.shift
when /\Aversion/
client << "#{line}\r\n"
client.gets.must_equal "#{example.shift}\r\n"
when /\Aset/
client << "#{line}\r\n"
client << "#{example.shift}\r\n"
client.gets.must_equal "#{example.shift}\r\n"
when /\Aget/
client << "#{line}\r\n"
client.gets.must_equal "#{example.shift}\r\n"
client.gets.must_equal "#{example.shift}\r\n"
when /\Aquit/
client << "#{line}\r\n"
client.gets.must_be_nil
end
end
end
end
end

0 comments on commit 6488ed2

Please sign in to comment.