test/test_from_readme.rb in jellyfish-1.0.2 vs test/test_from_readme.rb in jellyfish-1.1.0

- old
+ new

@@ -18,29 +18,40 @@ codes.each.with_index do |(title, code, test), index| next if title =~ /NewRelic/i would "pass from README.md #%02d #{title}" % index do - method_path, expect = test.strip.split("\n", 2) - method, path = method_path.split(' ') - uri = URI.parse(path) - pinfo, query = uri.path, uri.query + app = Rack::Builder.app{ eval(code) } - sock = nil - status, headers, body = File.open(File::NULL) do |input| - Rack::Builder.app{ eval(code) }.call( - 'REQUEST_METHOD' => method, 'PATH_INFO' => pinfo, - 'QUERY_STRING' => query , 'SCRIPT_NAME'=> '' , - 'rack.input' => input , - 'rack.hijack' => lambda{ - sock = StringIO.new - # or TypeError: no implicit conversion of StringIO into IO - mock(IO).select([sock]){ [[sock], [], []] } - sock - }) - end + test.split("\n\n").each do |t| + method_path, expect = t.strip.split("\n", 2) + method, path = method_path.split(' ') + uri = URI.parse(path) + pinfo, query = uri.path, uri.query - body.extend(Enumerable) - [status, headers, body.to_a].should.eq eval(expect, binding, __FILE__) + sock = nil + status, headers, body = File.open(File::NULL) do |input| + app.call( + 'HTTP_VERSION' => 'HTTP/1.1', + 'REQUEST_METHOD' => method, 'PATH_INFO' => pinfo, + 'QUERY_STRING' => query , 'SCRIPT_NAME'=> '' , + 'rack.input' => input , + 'rack.hijack' => lambda{ + sock = StringIO.new + # or TypeError: no implicit conversion of StringIO into IO + mock(IO).select([sock]){ [[sock], [], []] } + sock + }) + end + + if hijack = headers.delete('rack.hijack') + sock = StringIO.new + hijack.call(sock) + body = sock.string.each_line("\n\n") + end + + body.extend(Enumerable) + [status, headers, body.to_a].should.eq eval(expect, binding, __FILE__) + end end end end