JackDanger / jack

Javascript Rack Adapter

This URL has Read+Write access

JackDanger (author)
Sat Mar 21 11:28:07 -0700 2009
commit  647a501a8bcedad9c0b2758ac0ad4e1bde60a735
tree    138db1df10e727022293e1f6ed88744c98235134
parent  e57297bd42980f2fd4814a9e82fe9ba4220044a5
jack / test / test_jack.rb
100644 49 lines (41 sloc) 1.306 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'rubygems'
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/jack'
require 'open-uri'
require 'ostruct'
 
class TestJack < Test::Unit::TestCase
  TEST_OPTS = OpenStruct.new(:log => File.dirname(__FILE__) + '/test.log',
                             :host => 'localhost', :port => 1338)
 
  def setup
    @app_thread = Thread.new do
      Jack.run(File.dirname(__FILE__) + '/app.js', TEST_OPTS)
    end
    sleep 1.0
  end
 
  def teardown
    @app_thread.kill
  end
 
  def test_hello_world
    assert_equal( "<h1>O hai</h1>" , open('http://localhost:1338/o-hai').read )
    assert_raises(OpenURI::HTTPError) { open('http://localhost:1338/pow').read }
    assert_raises(OpenURI::HTTPError) { open('http://localhost:1338/404').read }
  end
 
  def test_custom_content_type
    open('http://localhost:1338/source/app.js') do |response|
      assert_equal 'text/plain', response.content_type
    end
  end
  
  def test_views
    assert_equal( "<DIV class='message'>Hello from jquery</DIV>" , open('http://localhost:1338/jquery').read )
  end
 
  if ENV['FULL_TEST']
    def test_requests_dont_each_add_to_the_stack
      n = 0
      2_000.times do |n|
        open('http://localhost:1338/o-hai').read
      end
    rescue => e
      assert false, "Blew up after #{n} requests"
    end
  end
end