spec/request_delegate_spec.rb in nyara-0.0.1.pre.2 vs spec/request_delegate_spec.rb in nyara-0.0.1.pre.3

- old
+ new

@@ -4,14 +4,12 @@ describe [Controller, Request] do class DelegateController < Controller end before :each do - @client, @server = Socket.pair :UNIX, :STREAM - Ext.set_nonblock @server.fileno - @request = Ext.handle_request @server.fileno - Ext.set_request_attrs @request, { + @request = Ext.request_new + Ext.request_set_attrs @request, { method_num: HTTP_METHODS['GET'], path: '/search', query: ParamHash.new.tap{|h| h['q'] = 'nyara' }, fiber: Fiber.new{}, scope: '/scope', @@ -38,22 +36,49 @@ it "request header" do assert_equal 'en-US', @c.header['accept'] end - it "set response header and send" do - pending - @c.set_header - @c.add_header_line - @c.send_header - @client - end + context "Simulate IO" do + before :each do + @client, @server = Socket.pair :UNIX, :STREAM + Ext.set_nonblock @server.fileno + Ext.request_set_fd @request, @server.fileno + end - it "set / delete / clear cookie" do - pending - end + def receive_header + @c.send_header + @server.close_write + @client.read + end - it "#session" do - pending + it "set response header and send" do + @c.set_header 'X-Test', true + @c.add_header_line "X-Test: also-true\r\n" + res = receive_header.lines + assert_includes res, "X-Test: true\r\n" + assert_includes res, "X-Test: also-true\r\n" + end + + it "set cookie" do + @c.set_cookie 'set', 'set' + cookie = receive_header.lines.grep(/Set-Cookie:/).last + assert_includes cookie, "set=set; HttpOnly" + end + + it "delete cookie" do + @c.delete_cookie 'del' + cookie = receive_header.lines.grep(/Set-Cookie:/).last + assert_includes cookie, "Expires" + end + + it "clear cookie" do + @c.clear_cookie + pending 'incomplete implementation' + end + + it "#session" do + pending + end end end end