webspeak 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +42 -0
- data/README.txt +1 -0
- data/Rakefile +4 -0
- data/bin/webspeak +64 -0
- data/bin/webspeak_listener +46 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/examples/google_cookies.rb +3 -0
- data/examples/web_search.rb +9 -0
- data/lib/webspeak.rb +6 -0
- data/lib/webspeak/console_app.rb +3 -0
- data/lib/webspeak/http_dialect.rb +71 -0
- data/lib/webspeak/http_listener.rb +100 -0
- data/lib/webspeak/request.rb +81 -0
- data/lib/webspeak/response_accessor.rb +39 -0
- data/lib/webspeak/session.rb +10 -0
- data/lib/webspeak/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/http_dialect_spec.rb +93 -0
- data/spec/http_listener_spec.rb +46 -0
- data/spec/parse_request_servlet_spec.rb +76 -0
- data/spec/request_spec.rb +127 -0
- data/spec/response_accessor_spec.rb +40 -0
- data/spec/session_spec.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/webspeak_spec.rb +9 -0
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +154 -0
- data/website/index.txt +90 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +93 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe WebSpeak::HTTP::Dialect do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@interpreter = WebSpeak::HTTP::Base.new
|
7
|
+
@request = mock(:request)
|
8
|
+
WebSpeak::Request.should_receive(:new).any_number_of_times.and_return(@request)
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_common_parameter_based_spec_with_hash_passed(function_name)
|
12
|
+
check_common_parameter_based_spec(function_name, " => ")
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_common_parameter_based_spec_with_list_passed(function_name)
|
16
|
+
check_common_parameter_based_spec(function_name, ", ")
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_common_parameter_based_spec(function_name, param_join)
|
20
|
+
hash = {}
|
21
|
+
@request.should_receive("#{function_name.to_s}s").and_return(hash)
|
22
|
+
@interpreter.instance_eval("#{function_name} 'param_name'#{param_join}'param_value'")
|
23
|
+
hash['param_name'].should eql("param_value")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set header values with hash style call" do
|
27
|
+
check_common_parameter_based_spec_with_hash_passed(:header)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set header values with list style call" do
|
31
|
+
check_common_parameter_based_spec_with_list_passed(:header)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set query params with hash style call" do
|
35
|
+
check_common_parameter_based_spec_with_hash_passed(:query_param)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set query params with list style call" do
|
39
|
+
check_common_parameter_based_spec_with_list_passed(:query_param)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set params with hash style call" do
|
43
|
+
check_common_parameter_based_spec_with_hash_passed(:param)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set params with list style call" do
|
47
|
+
check_common_parameter_based_spec_with_list_passed(:param)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set cookies with hash style call" do
|
51
|
+
check_common_parameter_based_spec_with_hash_passed(:cookie)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should set cookies with list style call" do
|
55
|
+
check_common_parameter_based_spec_with_list_passed(:cookie)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set host in request" do
|
59
|
+
@request.should_receive(:host=).with("test.com")
|
60
|
+
@interpreter.host "test.com"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set port in request" do
|
64
|
+
@request.should_receive(:port=).with(83)
|
65
|
+
@interpreter.port 83
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set path in request" do
|
69
|
+
@request.should_receive(:path=).with("/test/path")
|
70
|
+
@interpreter.path "/test/path"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should report an error with invalid call" do
|
74
|
+
lambda {@interpreter.header "foo"}.should raise_error()
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should do a POST with post" do
|
78
|
+
@request.should_receive(:post).once.with(no_args)
|
79
|
+
@interpreter.post
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should do a GET with a get" do
|
83
|
+
@request.should_receive(:get).once.with(no_args)
|
84
|
+
@interpreter.get
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return a ResponseAccessor with response" do
|
88
|
+
@request.should_receive(:response).once.with(no_args).and_return(nil)
|
89
|
+
ra = @interpreter.response
|
90
|
+
ra.should be_instance_of(WebSpeak::ResponseAccessor)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
describe WebSpeak::HTTPListener do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@server = mock(:server)
|
9
|
+
@server.should_receive(:start)
|
10
|
+
@real_stdout = $stdout
|
11
|
+
$stdout = StringIO.new
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
$stdout = @real_stdout
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should listen on correct default port" do
|
19
|
+
WEBrick::HTTPServer.should_receive(:new) do |opts|
|
20
|
+
opts[:Port].should eql(8080)
|
21
|
+
@server
|
22
|
+
end
|
23
|
+
@server.should_receive(:mount)
|
24
|
+
listener = WebSpeak::HTTPListener.new
|
25
|
+
listener.listen
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should listen on configurable port" do
|
29
|
+
WEBrick::HTTPServer.should_receive(:new) do |opts|
|
30
|
+
opts[:Port].should eql(80)
|
31
|
+
@server
|
32
|
+
end
|
33
|
+
@server.should_receive(:mount)
|
34
|
+
listener = WebSpeak::HTTPListener.new(80)
|
35
|
+
listener.listen
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should listen on '/' with a ParseRequestServlet" do
|
39
|
+
WEBrick::HTTPServer.should_receive(:new).and_return(@server)
|
40
|
+
@server.should_receive(:mount).with('/', WebSpeak::ParseRequestServlet)
|
41
|
+
listener = WebSpeak::HTTPListener.new
|
42
|
+
listener.listen
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
def setup_generic_request_response_mocks
|
6
|
+
@request = mock(:request)
|
7
|
+
@request.should_receive(:path).and_return('/')
|
8
|
+
@request.should_receive(:request_uri).at_least(:once).and_return(URI::parse("http://foo.com/?query_param=query_param_value"))
|
9
|
+
@request.should_receive(:header).and_return({
|
10
|
+
'header' => 'value', 'repeated_header' => ['value_1', 'value_2']})
|
11
|
+
@request.should_receive(:query).and_return({'param_name' => 'param_value'})
|
12
|
+
@request.should_receive(:cookies).and_return([mock_cookie('cookie_name', 'cookie_value')])
|
13
|
+
|
14
|
+
@response = mock(:response)
|
15
|
+
@response.should_receive(:body=) {|body| @body = body}
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "WebSpeak::ParseRequestServlet POSTing a standard request" do
|
19
|
+
|
20
|
+
before do
|
21
|
+
setup_generic_request_response_mocks
|
22
|
+
@server = mock(:server, :null_object => true)
|
23
|
+
@servlet = WebSpeak::ParseRequestServlet.new(@server)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should parse query params" do
|
27
|
+
@servlet.do_POST(@request, @response)
|
28
|
+
@body.should include("query_param 'query_param' => 'query_param_value'")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should parse headers" do
|
32
|
+
@servlet.do_POST(@request, @response)
|
33
|
+
@body.should include("header 'header' => 'value'")
|
34
|
+
@body.should include("header 'repeated_header' => 'value_1'")
|
35
|
+
@body.should include("header 'repeated_header' => 'value_2'")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should parse params" do
|
39
|
+
@servlet.do_POST(@request, @response)
|
40
|
+
@body.should include("param 'param_name' => 'param_value'")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should parse cookies" do
|
44
|
+
@servlet.do_POST(@request, @response)
|
45
|
+
@body.should include("cookie 'cookie_name' => 'cookie_value'")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should post the request" do
|
49
|
+
@servlet.do_POST(@request, @response)
|
50
|
+
@body.should include("post\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe WebSpeak::ParseRequestServlet do
|
56
|
+
# firefox likes to ask for the favicon.ico, so...
|
57
|
+
it "should ignore requests for favicon.ico" do
|
58
|
+
@request = mock(:request)
|
59
|
+
@request.should_receive(:path).and_return('/favicon.ico')
|
60
|
+
@response = mock(:response)
|
61
|
+
@server = mock(:server, :null_object => true)
|
62
|
+
@servlet = WebSpeak::ParseRequestServlet.new(@server)
|
63
|
+
@servlet.do_POST(@request, @response)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should ignore requests for favicon.ico" do
|
67
|
+
setup_generic_request_response_mocks
|
68
|
+
@server = mock(:server)
|
69
|
+
@server.should_receive(:shutdown)
|
70
|
+
null_mock = mock(:null_mock, :null => true)
|
71
|
+
@server.should_receive(:[]).and_return(null_mock)
|
72
|
+
@servlet = WebSpeak::ParseRequestServlet.new(@server)
|
73
|
+
@servlet.do_POST(@request, @response)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
# Time to add your specs!
|
4
|
+
# http://rspec.rubyforge.org/
|
5
|
+
describe "Initial creation of ", WebSpeak::Request do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@request = WebSpeak::Request.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not have any cookies" do
|
12
|
+
@request.cookies.should be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not have any headers" do
|
16
|
+
@request.headers.should be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not have any params" do
|
20
|
+
@request.params.should be_empty
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not have any query_params" do
|
24
|
+
@request.query_params.should be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have appropriate default connection values" do
|
28
|
+
@request.host.should eql("localhost")
|
29
|
+
@request.port.should eql(80)
|
30
|
+
@request.path.should eql("/")
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Posting a ", WebSpeak::Request do
|
36
|
+
|
37
|
+
before :each do
|
38
|
+
@request = WebSpeak::Request.new
|
39
|
+
@mock_http = mock(:http)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should post properly" do
|
43
|
+
@mock_http.should_receive(:post).with('/', '', {}).and_return(:response)
|
44
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
45
|
+
@request.post
|
46
|
+
@request.response.should eql(:response)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should post to different host information" do
|
50
|
+
@request.host = 'foo.bar'
|
51
|
+
@request.port = 1234
|
52
|
+
@request.path = '/other/path'
|
53
|
+
@mock_http.should_receive(:post).with('/other/path', '', {}).and_return(:response)
|
54
|
+
Net::HTTP.should_receive(:start).with('foo.bar', 1234).and_yield(@mock_http)
|
55
|
+
@request.post
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should contain headers when provided" do
|
59
|
+
@request.headers['header_name'] = 'header_value'
|
60
|
+
@mock_http.should_receive(:post).with('/', '', {'header_name' => 'header_value'}).and_return(:response)
|
61
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
62
|
+
@request.post
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should contain cookies when provided" do
|
66
|
+
@request.cookies['cookie_name'] = 'cookie_value'
|
67
|
+
@mock_http.should_receive(:post).with('/', '', {'Cookie' => 'cookie_name=cookie_value; '}).and_return(:response)
|
68
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
69
|
+
@request.post
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should contain query_params in the url when provided" do
|
73
|
+
@request.query_params['param_name'] = 'param_value'
|
74
|
+
@mock_http.should_receive(:post).with('/?param_name=param_value', '', {}).and_return(:response)
|
75
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
76
|
+
@request.post
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should contain params in the body when provided" do
|
80
|
+
@request.params['param_name'] = 'param_value'
|
81
|
+
@mock_http.should_receive(:post).with('/', 'param_name=param_value', {}).and_return(:response)
|
82
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
83
|
+
@request.post
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
describe "GETing a ", WebSpeak::Request do
|
90
|
+
before :each do
|
91
|
+
@request = WebSpeak::Request.new
|
92
|
+
@mock_http = mock(:http)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should get a simple URL" do
|
96
|
+
@request.host = 'foo.bar'
|
97
|
+
@request.port = 1234
|
98
|
+
@request.path = '/get/path'
|
99
|
+
@mock_http.should_receive(:get).with('/get/path', {}).and_return(:response)
|
100
|
+
Net::HTTP.should_receive(:start).with('foo.bar', 1234).and_yield(@mock_http)
|
101
|
+
@request.get
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should add headers and cookies" do
|
105
|
+
@request.headers['header_name'] = 'header_value'
|
106
|
+
@request.cookies['cookie_name'] = 'cookie_value'
|
107
|
+
@mock_http.should_receive(:get).with('/',
|
108
|
+
{'header_name' => 'header_value', 'Cookie' => 'cookie_name=cookie_value; '}).and_return(:response)
|
109
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
110
|
+
@request.get
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should add params and query_params to the path" do
|
114
|
+
@request.params['param_name'] = 'param_value'
|
115
|
+
@request.query_params['query_param_name'] = 'query_param_value'
|
116
|
+
@mock_http.should_receive(:get) do |path, hdrs|
|
117
|
+
path.should match(/^\/\?/)
|
118
|
+
path.should include("query_param_name=query_param_value")
|
119
|
+
path.should include("param_name=param_value")
|
120
|
+
hdrs.should be_empty
|
121
|
+
:response
|
122
|
+
end
|
123
|
+
Net::HTTP.should_receive(:start).with('localhost', 80).and_yield(@mock_http)
|
124
|
+
@request.get
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe WebSpeak::ResponseAccessor, "when the response is nil" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@response = mock(:response)
|
7
|
+
@ra = WebSpeak::ResponseAccessor.new(@response)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return the response with http_response" do
|
11
|
+
@ra.http_response.should be(@response)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the headers" do
|
15
|
+
@response.should_receive(:each_header).and_yield('content-type', ['text/html'])
|
16
|
+
headers = @ra.headers
|
17
|
+
headers.should eql("content-type => text/html\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not include cookies in headers" do
|
21
|
+
@response.should_receive(:each_header).and_yield('set-cookie', ['Foo=Bar; ', 'Jack=Frost; '])
|
22
|
+
headers = @ra.headers
|
23
|
+
headers.should eql("")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return cookies" do
|
27
|
+
@response.should_receive(:get_fields).with('set-cookie').and_return(
|
28
|
+
['Foo=Bar; expires=someday; domain=.foo.com', 'Jack=Frost; domain=.com'])
|
29
|
+
cookies = @ra.cookies
|
30
|
+
cookies.should eql("Foo => Bar\n expires: someday\n domain: .foo.com\nJack => Frost\n domain: .com\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the body" do
|
34
|
+
@response.should_receive(:body).and_return("the body")
|
35
|
+
body = @ra.body
|
36
|
+
body.should eql("the body")
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + "/../lib/webspeak"
|
10
|
+
require 'stringio'
|
11
|
+
require 'pp'
|
12
|
+
require 'ostruct'
|
13
|
+
|
14
|
+
def mock_cookie(name, value)
|
15
|
+
OpenStruct.new({'name' => name, 'value' => value})
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|