diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-09 22:08:05 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-09 22:08:05 +0900 |
commit | fbc724881092a1391576d020b13ba3ed75b419de (patch) | |
tree | 3ec77adfc47091dad3d6821b56e5c24bba830e67 | |
parent | 1722044a27839f349da3e33ec6355ae67dc88fd8 (diff) | |
download | plum-fbc724881092a1391576d020b13ba3ed75b419de.tar.gz |
test: add util methods
-rw-r--r-- | test/utils/assertions.rb | 6 | ||||
-rw-r--r-- | test/utils/server.rb | 18 |
2 files changed, 24 insertions, 0 deletions
diff --git a/test/utils/assertions.rb b/test/utils/assertions.rb index e11a194..71928ed 100644 --- a/test/utils/assertions.rb +++ b/test/utils/assertions.rb @@ -18,6 +18,12 @@ module CustomAssertions assert_nil(Plum::ConnectionError.last, "No connection error expected but raised: #{Plum::ConnectionError.last}") end + def assert_frame(frame, **args) + args.each do |name, value| + assert_equal(value, frame.__send__(name)) + end + end + private def assert_http_error(klass, type, &blk) klass.reset diff --git a/test/utils/server.rb b/test/utils/server.rb index cc17fd5..e3b8386 100644 --- a/test/utils/server.rb +++ b/test/utils/server.rb @@ -38,6 +38,24 @@ module ServerUtils end frames end + + def capture_frames(con = nil, &blk) + io = (con || @_con).io + pos = io.string.bytesize + blk.call + resp = io.string.byteslice(pos, io.string.bytesize - pos) + frames = [] + while f = Frame.parse!(resp) + frames << f + end + frames + end + + def capture_frame(con = nil, &blk) + frames = capture_frames(con, &blk) + assert_equal(1, frames.size, "Supplied block sent no frames or more than 1 frame") + frames.first + end end class Minitest::Test |