celerity 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +15 -1
- data/Manifest.txt +174 -0
- data/README.txt +19 -10
- data/config/hoe.rb +68 -0
- data/config/requirements.rb +15 -0
- data/lib/celerity.rb +14 -11
- data/lib/celerity/collections.rb +37 -8
- data/lib/celerity/container.rb +100 -3
- data/lib/celerity/disabled_element.rb +4 -2
- data/lib/celerity/element.rb +21 -8
- data/lib/celerity/element_collections.rb +4 -7
- data/lib/celerity/element_locator.rb +1 -0
- data/lib/celerity/elements/button.rb +6 -2
- data/lib/celerity/elements/file_field.rb +1 -1
- data/lib/celerity/elements/form.rb +1 -2
- data/lib/celerity/elements/frame.rb +0 -3
- data/lib/celerity/elements/image.rb +1 -4
- data/lib/celerity/elements/label.rb +1 -0
- data/lib/celerity/elements/link.rb +2 -0
- data/lib/celerity/elements/option.rb +1 -0
- data/lib/celerity/elements/radio_check.rb +3 -5
- data/lib/celerity/elements/select_list.rb +3 -10
- data/lib/celerity/elements/table.rb +8 -22
- data/lib/celerity/elements/table_body.rb +5 -11
- data/lib/celerity/elements/table_cell.rb +1 -0
- data/lib/celerity/elements/table_footer.rb +30 -0
- data/lib/celerity/elements/table_header.rb +30 -0
- data/lib/celerity/elements/table_row.rb +5 -3
- data/lib/celerity/elements/text_field.rb +18 -13
- data/lib/celerity/exception.rb +8 -8
- data/lib/celerity/extra/method_generator.rb +5 -2
- data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
- data/lib/celerity/ie.rb +195 -141
- data/lib/celerity/non_control_elements.rb +30 -4
- data/lib/celerity/version.rb +1 -1
- data/lib/celerity/watir_compatibility.rb +62 -0
- data/setup.rb +0 -2
- data/spec/area_spec.rb +4 -1
- data/spec/areas_spec.rb +1 -1
- data/spec/button_spec.rb +35 -17
- data/spec/buttons_spec.rb +1 -1
- data/spec/checkbox_spec.rb +6 -4
- data/spec/checkboxes_spec.rb +1 -1
- data/spec/div_spec.rb +20 -19
- data/spec/divs_spec.rb +2 -2
- data/spec/element_spec.rb +13 -2
- data/spec/filefield_spec.rb +6 -3
- data/spec/filefields_spec.rb +1 -1
- data/spec/form_spec.rb +4 -1
- data/spec/forms_spec.rb +1 -1
- data/spec/frame_spec.rb +6 -2
- data/spec/hidden_spec.rb +8 -4
- data/spec/hiddens_spec.rb +1 -1
- data/spec/hn_spec.rb +86 -0
- data/spec/hns_spec.rb +41 -0
- data/spec/html/bug_duplicate_attributes.html +14 -0
- data/spec/html/bug_javascript_001.html +11 -0
- data/spec/html/forms_with_input_elements.html +11 -11
- data/spec/html/images.html +18 -15
- data/spec/html/latin1_text.html +16 -0
- data/spec/html/non_control_elements.html +28 -4
- data/spec/html/tables.html +3 -3
- data/spec/html/utf8_text.html +15 -0
- data/spec/htmlunit_spec.rb +27 -0
- data/spec/ie_spec.rb +47 -12
- data/spec/image_spec.rb +4 -7
- data/spec/images_spec.rb +3 -2
- data/spec/label_spec.rb +4 -3
- data/spec/labels_spec.rb +1 -1
- data/spec/li_spec.rb +11 -8
- data/spec/link_spec.rb +5 -1
- data/spec/links_spec.rb +2 -1
- data/spec/lis_spec.rb +3 -2
- data/spec/map_spec.rb +4 -1
- data/spec/maps_spec.rb +1 -1
- data/spec/meta_spec.rb +6 -0
- data/spec/ol_spec.rb +73 -0
- data/spec/ols_spec.rb +41 -0
- data/spec/option_spec.rb +129 -0
- data/spec/p_spec.rb +4 -1
- data/spec/pre_spec.rb +4 -1
- data/spec/pres_spec.rb +1 -1
- data/spec/ps_spec.rb +2 -1
- data/spec/radio_spec.rb +7 -19
- data/spec/radios_spec.rb +1 -1
- data/spec/select_list_spec.rb +19 -57
- data/spec/select_lists_spec.rb +3 -2
- data/spec/span_spec.rb +8 -5
- data/spec/spans_spec.rb +2 -1
- data/spec/spec_helper.rb +8 -43
- data/spec/table_bodies_spec.rb +17 -4
- data/spec/table_body_spec.rb +47 -16
- data/spec/table_cell_spec.rb +5 -3
- data/spec/table_cells_spec.rb +1 -1
- data/spec/table_footer_spec.rb +94 -0
- data/spec/table_footers_spec.rb +53 -0
- data/spec/table_header_spec.rb +94 -0
- data/spec/table_headers_spec.rb +53 -0
- data/spec/table_row_spec.rb +25 -4
- data/spec/table_rows_spec.rb +1 -1
- data/spec/table_spec.rb +22 -2
- data/spec/tables_spec.rb +2 -1
- data/spec/text_field_spec.rb +52 -20
- data/spec/text_fields_spec.rb +1 -1
- data/spec/ul_spec.rb +73 -0
- data/spec/uls_spec.rb +41 -0
- data/spec/watir_compatability_spec.rb +253 -0
- data/support/celerity_viewer/rubycocoa/CelerityViewer.icns +0 -0
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/classes.nib +37 -0
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/info.nib +19 -0
- data/support/celerity_viewer/rubycocoa/English.lproj/Main.nib/keyedobjects.nib +0 -0
- data/support/celerity_viewer/rubycocoa/Info.plist.erb +28 -0
- data/support/celerity_viewer/rubycocoa/MainController.rb +23 -0
- data/support/celerity_viewer/rubycocoa/README +94 -0
- data/support/celerity_viewer/rubycocoa/Rakefile +100 -0
- data/support/celerity_viewer/rubycocoa/distributed_viewer.rb +86 -0
- data/support/celerity_viewer/rubycocoa/main.m +7 -0
- data/support/celerity_viewer/rubycocoa/main.rb +27 -0
- data/support/spec_server.rb +64 -0
- data/tasks/benchmark.rake +1 -0
- data/tasks/rdoc.rake +4 -0
- data/tasks/rspec.rake +10 -3
- data/tasks/simple_ci.rake +94 -0
- data/tasks/specserver.rake +21 -0
- metadata +160 -114
- data/spec/table_bodies.rb +0 -40
- data/tasks/testserver.rake +0 -32
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'osx/cocoa'
|
2
|
+
require "distributed_viewer"
|
3
|
+
include OSX
|
4
|
+
require_framework 'WebKit'
|
5
|
+
|
6
|
+
class MainController < NSObject
|
7
|
+
ib_outlets :web_view, :text_field
|
8
|
+
|
9
|
+
def awakeFromNib
|
10
|
+
@web_view.preferences.setShouldPrintBackgrounds(true)
|
11
|
+
NSUserDefaults.standardUserDefaults.setObject_forKey('YES', 'WebKitDeveloperExtras')
|
12
|
+
DRb.start_service("druby://127.0.0.1:1337", DistributedViewer.new(@web_view, @text_field))
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_url(sender)
|
16
|
+
str = sender.stringValue
|
17
|
+
url = NSURL.URLWithString(str.to_ruby =~ /^https?/ ? str : "http://#{str}" )
|
18
|
+
@web_view.mainFrame.loadRequest(OSX::NSURLRequest.requestWithURL(url))
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'osx/cocoa' # dummy
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'erb'
|
7
|
+
require 'pathname'
|
8
|
+
|
9
|
+
# Application own Settings
|
10
|
+
APPNAME = "Celerity_viewer"
|
11
|
+
TARGET = "#{APPNAME}.app"
|
12
|
+
VERSION = "rev#{`svn info`[/Revision: (\d+)/, 1]}"
|
13
|
+
RESOURCES = ['*.rb', '*.lproj', 'Credits.*', '*.icns']
|
14
|
+
PKGINC = [TARGET, 'README', 'html', 'client']
|
15
|
+
LOCALENIB = [] #['Japanese.lproj/Main.nib']
|
16
|
+
PUBLISH = 'yourname@yourhost:path'
|
17
|
+
|
18
|
+
BUNDLEID = "rubyapp.#{APPNAME}"
|
19
|
+
|
20
|
+
CLEAN.include ['**/.*.sw?', '*.dmg', TARGET, 'image', 'a.out']
|
21
|
+
|
22
|
+
# Tasks
|
23
|
+
task :default => [:test]
|
24
|
+
|
25
|
+
desc 'Create Application Budle and Run it.'
|
26
|
+
task :test => [TARGET] do
|
27
|
+
sh %{open '#{TARGET}'}
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Create .dmg file for Publish'
|
31
|
+
task :package => [:clean, 'pkg', TARGET] do
|
32
|
+
name = "#{APPNAME}.#{VERSION}"
|
33
|
+
sh %{
|
34
|
+
mkdir image
|
35
|
+
cp -r #{PKGINC.join(' ')} image
|
36
|
+
ln -s html/index.html image/index.html
|
37
|
+
}
|
38
|
+
puts 'Creating Image...'
|
39
|
+
sh %{
|
40
|
+
hdiutil create -volname #{name} -srcfolder image #{name}.dmg
|
41
|
+
rm -rf image
|
42
|
+
mv #{name}.dmg pkg
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'Publish .dmg file to specific server.'
|
47
|
+
task :publish => [:package] do
|
48
|
+
sh %{
|
49
|
+
svn log > CHANGES
|
50
|
+
}
|
51
|
+
_, host, path = */^([^\s]+):(.+)$/.match(PUBLISH)
|
52
|
+
path = Pathname.new path
|
53
|
+
puts "Publish: Host: %s, Path: %s" % [host, path]
|
54
|
+
sh %{
|
55
|
+
scp pkg/IIrcv.#{VERSION}.dmg #{PUBLISH}/pkg
|
56
|
+
scp CHANGES #{PUBLISH}/pkg
|
57
|
+
scp -r html/* #{PUBLISH}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Make Localized nib from English.lproj and Lang.lproj/nib.strings'
|
62
|
+
rule(/.nib$/ => [proc {|tn| File.dirname(tn) + '/nib.strings' }]) do |t|
|
63
|
+
p t.name
|
64
|
+
lproj = File.dirname(t.name)
|
65
|
+
target = File.basename(t.name)
|
66
|
+
sh %{
|
67
|
+
rm -rf #{t.name}
|
68
|
+
nibtool -d #{lproj}/nib.strings -w #{t.name} English.lproj/#{target}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
# File tasks
|
73
|
+
desc 'Make executable Application Bundle'
|
74
|
+
file TARGET => [:clean, APPNAME] + LOCALENIB do
|
75
|
+
sh %{
|
76
|
+
mkdir -p "#{APPNAME}.app/Contents/MacOS"
|
77
|
+
mkdir "#{APPNAME}.app/Contents/Resources"
|
78
|
+
cp -rp #{RESOURCES.join(' ')} "#{APPNAME}.app/Contents/Resources"
|
79
|
+
cp '#{APPNAME}' "#{APPNAME}.app/Contents/MacOS"
|
80
|
+
echo -n "APPL????" > "#{APPNAME}.app/Contents/PkgInfo"
|
81
|
+
echo -n #{VERSION} > "#{APPNAME}.app/Contents/Resources/VERSION"
|
82
|
+
}
|
83
|
+
File.open("#{APPNAME}.app/Contents/Info.plist", "w") do |f|
|
84
|
+
f.puts ERB.new(File.read("Info.plist.erb")).result
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
file APPNAME => ['main.m'] do
|
89
|
+
# Universal Binary
|
90
|
+
sh %{gcc -arch ppc -arch i386 -Wall -lobjc -framework RubyCocoa main.m -o '#{APPNAME}'}
|
91
|
+
end
|
92
|
+
|
93
|
+
directory 'pkg'
|
94
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'osx/cocoa' # dummy
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'erb'
|
7
|
+
require 'pathname'
|
8
|
+
|
9
|
+
# Application own Settings
|
10
|
+
APPNAME = "CelerityViewer"
|
11
|
+
TARGET = "#{APPNAME}.app"
|
12
|
+
v = "rev#{`svn info`[/Revision: (\d+)/, 1]}"
|
13
|
+
APP_VERSION = (v == 'rev' ? "rev#{`git-svn info`[/Revision: (\d+)/, 1]}" : v)
|
14
|
+
RESOURCES = ['*.rb', '*.lproj', 'Credits.*', '*.icns']
|
15
|
+
PKGINC = [TARGET, 'README', 'html', 'client']
|
16
|
+
LOCALENIB = [] #['Japanese.lproj/Main.nib']
|
17
|
+
COPYRIGHT = "Copyright © 2008 FinnTech AS"
|
18
|
+
#PUBLISH = 'yourname@yourhost:path'
|
19
|
+
BUNDLEID = "no.finntech.#{APPNAME.downcase}"
|
20
|
+
|
21
|
+
|
22
|
+
CLEAN.include ['**/.*.sw?', '*.dmg', TARGET, 'image', 'a.out']
|
23
|
+
|
24
|
+
# Tasks
|
25
|
+
task :default => [:test]
|
26
|
+
|
27
|
+
desc 'Create Application Budle and Run it.'
|
28
|
+
task :test => [TARGET] do
|
29
|
+
sh %{open '#{TARGET}'}
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Create .dmg file for Publish'
|
33
|
+
task :package => [:clean, 'pkg', TARGET] do
|
34
|
+
name = "#{APPNAME}.#{APP_VERSION}"
|
35
|
+
sh %{
|
36
|
+
mkdir image
|
37
|
+
cp -r #{PKGINC.join(' ')} image
|
38
|
+
ln -s html/index.html image/index.html
|
39
|
+
}
|
40
|
+
puts 'Creating Image...'
|
41
|
+
sh %{
|
42
|
+
hdiutil create -volname #{name} -srcfolder image #{name}.dmg
|
43
|
+
rm -rf image
|
44
|
+
mv #{name}.dmg pkg
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Publish .dmg file to specific server.'
|
49
|
+
task :publish => [:package] do
|
50
|
+
sh %{
|
51
|
+
svn log > CHANGES
|
52
|
+
}
|
53
|
+
_, host, path = */^([^\s]+):(.+)$/.match(PUBLISH)
|
54
|
+
path = Pathname.new path
|
55
|
+
puts "Publish: Host: %s, Path: %s" % [host, path]
|
56
|
+
sh %{
|
57
|
+
scp pkg/IIrcv.#{APP_VERSION}.dmg #{PUBLISH}/pkg
|
58
|
+
scp CHANGES #{PUBLISH}/pkg
|
59
|
+
scp -r html/* #{PUBLISH}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'Make Localized nib from English.lproj and Lang.lproj/nib.strings'
|
64
|
+
rule(/.nib$/ => [proc {|tn| File.dirname(tn) + '/nib.strings' }]) do |t|
|
65
|
+
p t.name
|
66
|
+
lproj = File.dirname(t.name)
|
67
|
+
target = File.basename(t.name)
|
68
|
+
sh %{
|
69
|
+
rm -rf #{t.name}
|
70
|
+
nibtool -d #{lproj}/nib.strings -w #{t.name} English.lproj/#{target}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
# File tasks
|
75
|
+
desc 'Make executable Application Bundle'
|
76
|
+
file TARGET => [:clean, APPNAME] + LOCALENIB do
|
77
|
+
sh %{
|
78
|
+
mkdir -p "#{APPNAME}.app/Contents/MacOS"
|
79
|
+
mkdir "#{APPNAME}.app/Contents/Resources"
|
80
|
+
cp -rp #{RESOURCES.join(' ')} "#{APPNAME}.app/Contents/Resources"
|
81
|
+
cp '#{APPNAME}' "#{APPNAME}.app/Contents/MacOS"
|
82
|
+
echo -n "APPL????" > "#{APPNAME}.app/Contents/PkgInfo"
|
83
|
+
echo #{APP_VERSION} > "#{APPNAME}.app/Contents/Resources/VERSION"
|
84
|
+
}
|
85
|
+
File.open("#{APPNAME}.app/Contents/Info.plist", "w") do |f|
|
86
|
+
f.puts ERB.new(File.read("Info.plist.erb")).result
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
file APPNAME => ['main.m'] do
|
91
|
+
# Universal Binary
|
92
|
+
sh %{gcc -arch ppc -arch i386 -Wall -lobjc -framework RubyCocoa main.m -o '#{APPNAME}'}
|
93
|
+
end
|
94
|
+
|
95
|
+
desc 'Install the application bundle in /Applications'
|
96
|
+
task :install => [TARGET] do
|
97
|
+
sh "cp -R #{APPNAME}.app /Applications", :verbose => true
|
98
|
+
end
|
99
|
+
directory 'pkg'
|
100
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "drb"
|
2
|
+
require "drb/acl"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
DRb.install_acl(ACL.new(%w{deny all allow 127.0.0.1}))
|
6
|
+
|
7
|
+
class DistributedViewer
|
8
|
+
attr_reader :web_view
|
9
|
+
|
10
|
+
def initialize(web_view, url_field)
|
11
|
+
@web_view = web_view
|
12
|
+
@url_field = url_field
|
13
|
+
end
|
14
|
+
|
15
|
+
def render_html(html, url = nil)
|
16
|
+
begin
|
17
|
+
if url
|
18
|
+
uri = URI.parse(url)
|
19
|
+
base_url = "#{uri.scheme}://#{uri.host}"
|
20
|
+
@url_field.setStringValue(url)
|
21
|
+
url = NSURL.URLWithString(base_url)
|
22
|
+
end
|
23
|
+
@web_view.mainFrame.loadHTMLString_baseURL(html, url)
|
24
|
+
rescue => e
|
25
|
+
log(e)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def print(path = nil)
|
30
|
+
if path
|
31
|
+
# TODO: fix printing
|
32
|
+
|
33
|
+
# =========
|
34
|
+
# = Alt I =
|
35
|
+
# =========
|
36
|
+
# rect = @web_view.mainFrame.frameView.documentView.bounds
|
37
|
+
# view = @web_view.mainFrame.frameView.documentView
|
38
|
+
# print_operation = NSPrintOperation.PDFOperationWithView_insideRect_toPath_printInfo(view,
|
39
|
+
# rect,
|
40
|
+
# path,
|
41
|
+
# NSPrintInfo.sharedPrintInfo)
|
42
|
+
# print_operation.runOperation
|
43
|
+
|
44
|
+
# ======================================================================
|
45
|
+
# = Alt II : http://www.cocoadev.com/index.pl?GettingViewContentAsImage =
|
46
|
+
# ======================================================================
|
47
|
+
print_info = NSPrintInfo.sharedPrintInfo
|
48
|
+
print_info.setJobDisposition(NSPrintSaveJob)
|
49
|
+
print_info.dictionary.setObject_forKey(path, NSPrintSavePath)
|
50
|
+
print_info.dictionary.setObject_forKey(1, NSPrintFirstPage)
|
51
|
+
print_info.dictionary.setObject_forKey(1, NSPrintLastPage)
|
52
|
+
print_info.dictionary.setObject_forKey("Letter", NSPrintPaperName)
|
53
|
+
print_info.setBottomMargin(0.0)
|
54
|
+
print_info.setTopMargin(0.0)
|
55
|
+
print_info.setLeftMargin(0.0)
|
56
|
+
print_info.setRightMargin(0.0)
|
57
|
+
|
58
|
+
operation = NSPrintOperation.printOperationWithView_printInfo(@web_view.mainFrame.frameView.documentView, print_info)
|
59
|
+
operation.setShowPanels(false)
|
60
|
+
operation.runOperation
|
61
|
+
|
62
|
+
# ===============================================================
|
63
|
+
# = Alt III : /Developer/Examples/RubyCocoa/Scripts/darkroom.rb =
|
64
|
+
# ===============================================================
|
65
|
+
# viewport = @web_view.mainFrame.frameView.documentView
|
66
|
+
# log(1)
|
67
|
+
# # viewport.window.orderFront(nil)
|
68
|
+
# viewport.window.display
|
69
|
+
# log(2)
|
70
|
+
# # viewport.window.setContentSize(viewport.bounds)
|
71
|
+
# viewport.setFrame(viewport.bounds)
|
72
|
+
# log(3)
|
73
|
+
# viewport.lockFocus
|
74
|
+
# log(4)
|
75
|
+
# bitmap = NSBitmapImageRep.alloc.initWithFocusedViewRect(viewport.bounds)
|
76
|
+
# viewport.unLockFocus
|
77
|
+
# log(5)
|
78
|
+
# log(bitmap)
|
79
|
+
# bitmap.representationUsingType_properties(NSPNGFileType, nil).writeToFile_atomically(path, true)
|
80
|
+
# log(6)
|
81
|
+
else
|
82
|
+
@web_view.print(nil)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require 'rubygems'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
require 'osx/cocoa'
|
7
|
+
require 'pathname'
|
8
|
+
|
9
|
+
def log(*args)
|
10
|
+
args.each do |m|
|
11
|
+
OSX.NSLog m.inspect
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def _(key)
|
16
|
+
NSLocalizedString(key, '').to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
path = Pathname.new OSX::NSBundle.mainBundle.resourcePath.fileSystemRepresentation
|
20
|
+
Pathname.glob(path + '*.rb') do |file|
|
21
|
+
next if file.to_s == __FILE__
|
22
|
+
require(file)
|
23
|
+
end
|
24
|
+
OSX::NSApplication.sharedApplication
|
25
|
+
OSX.NSApplicationMain(0, nil)
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'webrick/https'
|
3
|
+
|
4
|
+
module Celerity
|
5
|
+
|
6
|
+
class PostHandler < WEBrick::HTTPServlet::AbstractServlet
|
7
|
+
def do_POST(req, resp)
|
8
|
+
resp['content-type'] = 'text/html'
|
9
|
+
resp.body << "You posted the following content:\n"
|
10
|
+
resp.body << req.body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class PlainTextHandler < WEBrick::HTTPServlet::AbstractServlet
|
15
|
+
def do_GET(req, resp)
|
16
|
+
resp['content-type'] = 'text/plain'
|
17
|
+
resp.body << "This is text/plain"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class SpecServer
|
22
|
+
attr_reader :host, :thread, :log_file
|
23
|
+
|
24
|
+
def initialize(opts = {})
|
25
|
+
@ssl = opts[:ssl] || false
|
26
|
+
@doc_root = opts[:doc_root] || File.join(File.dirname(__FILE__),"..", "spec", "html")
|
27
|
+
@log_file = opts[:log_file] || File.join(File.dirname(__FILE__), "..", "log", "webrick_log.txt")
|
28
|
+
@port = opts[:port] || 2000
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
unless File.exist?(@log_file)
|
33
|
+
FileUtils.mkdir_p(File.dirname(@log_file))
|
34
|
+
FileUtils.touch(@log_file)
|
35
|
+
end
|
36
|
+
|
37
|
+
server_options = {
|
38
|
+
:Port => @port,
|
39
|
+
:DocumentRoot => @doc_root,
|
40
|
+
:Logger => WEBrick::Log.new(@log_file, WEBrick::BasicLog::WARN),
|
41
|
+
:AccessLog => [],
|
42
|
+
}
|
43
|
+
|
44
|
+
if @ssl
|
45
|
+
# java complains about this certifcate, need to create our own (when running under MRI)
|
46
|
+
server_options.merge!(
|
47
|
+
:SSLEnable => true,
|
48
|
+
:SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
|
49
|
+
:SSLCertName => [["CN", "Celerity"]]
|
50
|
+
)
|
51
|
+
@host = "https://localhost:#{@port}"
|
52
|
+
else
|
53
|
+
@host = "http://localhost:#{@port}"
|
54
|
+
end
|
55
|
+
|
56
|
+
server = WEBrick::HTTPServer.new(server_options)
|
57
|
+
server.mount("/", WEBrick::HTTPServlet::FileHandler, @doc_root, {:FancyIndexing=>true})
|
58
|
+
server.mount("/post_to_me", PostHandler)
|
59
|
+
server.mount("/plain_text", PlainTextHandler)
|
60
|
+
|
61
|
+
@thread = Thread.new { server.start }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/tasks/benchmark.rake
CHANGED
data/tasks/rdoc.rake
ADDED
data/tasks/rspec.rake
CHANGED
@@ -4,6 +4,7 @@ rescue LoadError
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'spec'
|
6
6
|
end
|
7
|
+
|
7
8
|
begin
|
8
9
|
require 'spec/rake/spectask'
|
9
10
|
rescue LoadError
|
@@ -14,10 +15,16 @@ EOS
|
|
14
15
|
exit(0)
|
15
16
|
end
|
16
17
|
|
17
|
-
desc "Run the specs under spec/
|
18
|
+
desc "Run the specs under spec/"
|
18
19
|
Spec::Rake::SpecTask.new do |t|
|
19
20
|
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
21
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
|
22
|
-
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'rcov'
|
25
|
+
t.rcov = true
|
26
|
+
t.rcov_opts = ['--exclude', 'spec,fcntl,path_helper', '--no-rcovrt']
|
27
|
+
rescue LoadError
|
28
|
+
end
|
29
|
+
|
23
30
|
end
|