spec/hayabusa_spec.rb in hayabusa-0.0.15 vs spec/hayabusa_spec.rb in hayabusa-0.0.16
- old
+ new
@@ -1,16 +1,27 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Hayabusa" do
it "should be able to start a sample-server" do
require "rubygems"
- require "hayabusa"
- require "/home/kaspernj/Dev/Ruby/Gems/knjrbfw/lib/knjrbfw.rb"
require "sqlite3" if RUBY_ENGINE != "jruby"
require "json"
- Knj.gem_require(:Http2, "http2")
+ begin
+ require "#{File.realpath(File.dirname(__FILE__))}/../../knjrbfw/lib/knjrbfw.rb"
+ rescue LoadError
+ require "knjrbfw"
+ end
+
+ require "#{File.realpath(File.dirname(__FILE__))}/../lib/hayabusa.rb"
+
+ begin
+ require "#{File.realpath(File.dirname(__FILE__))}/../../http2/lib/http2.rb"
+ rescue LoadError
+ require "http2"
+ end
+
db_path = "#{Knj::Os.tmpdir}/hayabusa_rspec.sqlite3"
File.unlink(db_path) if File.exists?(db_path)
db = Knj::Db.new(
:type => "sqlite3",
@@ -50,11 +61,11 @@
$appserver.define_magic_var(:_testvar2, "Johansen")
$appserver.start
raise "Expected thread-pool-priority to be '-3' but it wasnt: '#{$appserver.threadpool.args[:priority]}'." if $appserver.threadpool.args[:priority] != -3
- http = Http2.new(:host => "localhost", :port => 80)
+ http = Http2.new(:host => "localhost", :port => 80, :encoding_gzip => false, :debug => false)
$testmodes = [{
:name => :standalone,
:path_pre => "",
:http => Http2.new(:host => "localhost", :port => 1515)
@@ -74,10 +85,40 @@
# res = tdata[:http].get("#{tdata[:path_pre]}Kasper")
# raise "Expected data to be 'Test' in mode '#{tdata[:name]}' but it wasnt: '#{res.body}'." if res.body != "Test"
# end
#end
+ it "should be able to upload files" do
+ $testmodes.each do |tdata|
+ fpath = "#{File.realpath(File.dirname(__FILE__))}/../pages/spec_thread_joins.rhtml"
+
+ res = tdata[:http].post_multipart(:url => "#{tdata[:path_pre]}spec_vars_post_fileupload.rhtml", :post => {
+ "testfile" => {
+ :filename => "spec_thread_joins.rhtml",
+ :fpath => fpath
+ }
+ })
+
+ data = JSON.parse(res.body)
+
+ if data["testfile"] != File.read(fpath)
+ File.open("/tmp/hayabusa_spec_testfile1", "w") do |fp|
+ fp.puts("Class: #{data["testfile"].class.name}")
+ fp.write(data["testfile"])
+ end
+
+ File.open("/tmp/hayabusa_spec_testfile2", "w") do |fp|
+ fp.write(File.read(fpath))
+ end
+
+ raise "Expected uploaded data for mode '#{tdata[:name]}' to be the same but it wasnt:\n\"#{data["testfile"]}\"\n\n\"#{File.read(fpath)}\""
+ end
+ end
+ end
+
+ if false
+
it "should be able to handle a GET-request." do
$testmodes.each do |tdata|
res = tdata[:http].get("#{tdata[:path_pre]}spec.rhtml")
raise "Unexpected HTML: '#{res.body}'." if res.body.to_s != "Test"
@@ -298,9 +339,11 @@
es.each do |e|
raise e
end
end
+ end
+
end
it "should be able to stop." do
$appserver.stop
end