wsoc 0.1.0

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.
Files changed (45) hide show
  1. data.tar.gz.sig +4 -0
  2. data/COPYING.txt +339 -0
  3. data/History.rdoc +16 -0
  4. data/Manifest.txt +42 -0
  5. data/README.rdoc +58 -0
  6. data/Rakefile +27 -0
  7. data/bin/wsoc_server +12 -0
  8. data/config.ru +9 -0
  9. data/lib/wsoc.rb +21 -0
  10. data/lib/wsoc/app.rb +147 -0
  11. data/lib/wsoc/config.rb +46 -0
  12. data/lib/wsoc/course.rb +69 -0
  13. data/lib/wsoc/course_specs.rb +124 -0
  14. data/lib/wsoc/helpers.rb +34 -0
  15. data/lib/wsoc/helpers/course.rb +148 -0
  16. data/lib/wsoc/helpers/rendering.rb +111 -0
  17. data/lib/wsoc/runner.rb +123 -0
  18. data/lib/wsoc/specs.rb +62 -0
  19. data/lib/wsoc/version.rb +24 -0
  20. data/public/css/layout.css +44 -0
  21. data/public/css/specs.css +11 -0
  22. data/public/js/jquery-1.3.2.min.js +19 -0
  23. data/tasks/yard.rb +12 -0
  24. data/views/course_absolute_start.erb +19 -0
  25. data/views/course_cookies_get.erb +13 -0
  26. data/views/course_cookies_start.erb +13 -0
  27. data/views/course_empty_start.erb +23 -0
  28. data/views/course_fail.erb +11 -0
  29. data/views/course_frames_frame.erb +15 -0
  30. data/views/course_frames_iframe.erb +15 -0
  31. data/views/course_frames_start.erb +15 -0
  32. data/views/course_javascript_start.erb +19 -0
  33. data/views/course_loop_next.erb +13 -0
  34. data/views/course_loop_start.erb +19 -0
  35. data/views/course_pass.erb +9 -0
  36. data/views/course_redirects_start.erb +17 -0
  37. data/views/course_relative_start.erb +27 -0
  38. data/views/course_remote_next.erb +9 -0
  39. data/views/course_remote_start.erb +31 -0
  40. data/views/course_start.erb +22 -0
  41. data/views/layout.erb +24 -0
  42. data/views/specs.erb +48 -0
  43. data/views/welcome.erb +38 -0
  44. metadata +161 -0
  45. metadata.gz.sig +0 -0
@@ -0,0 +1,34 @@
1
+ #
2
+ # WSOC - The Web Spider Obstacle Course
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'wsoc/helpers/course'
22
+ require 'wsoc/helpers/rendering'
23
+
24
+ require 'rack'
25
+
26
+ module WSOC
27
+ module Helpers
28
+ include Rack::Utils
29
+ alias :h :escape_html
30
+
31
+ include Rendering
32
+ include Course
33
+ end
34
+ end
@@ -0,0 +1,148 @@
1
+ #
2
+ # WSOC - The Web Spider Obstacle Course
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'wsoc/config'
22
+ require 'wsoc/course_specs'
23
+
24
+ module WSOC
25
+ module Helpers
26
+ module Course
27
+ #
28
+ # Renders a course page.
29
+ #
30
+ # @param [Symbol] name
31
+ # The name of the course page.
32
+ #
33
+ # @return [String]
34
+ # The rendered page.
35
+ #
36
+ # @example
37
+ # course_page :course_start
38
+ #
39
+ # @since 0.1.0
40
+ #
41
+ def course_page(name)
42
+ erb name, :layout => false
43
+ end
44
+
45
+ #
46
+ # Renders a title string.
47
+ #
48
+ # @param [Array] names
49
+ # The names to put into the title.
50
+ #
51
+ # @return [String]
52
+ # The title.
53
+ #
54
+ # @example
55
+ # title_for 'HTTP Redirects'
56
+ # # => "Web Spider Obstacle Course :: HTTP Redirects"
57
+ #
58
+ # @since 0.1.0
59
+ #
60
+ def title_for(*names)
61
+ (['Web Spider Obstacle Course'] + names).join(' :: ')
62
+ end
63
+
64
+ #
65
+ # Generates a remote URL containing a given path.
66
+ #
67
+ # @param [String] path
68
+ # The path to include within the URL.
69
+ #
70
+ # @return [String]
71
+ # The remote URL.
72
+ #
73
+ # @example
74
+ # remote_url '/course/redirects/start.html'
75
+ # # => "http://localhost:8080/course/redirects/start.html"
76
+ #
77
+ # @since 0.1.0
78
+ #
79
+ def remote_url(path)
80
+ s = "#{request.scheme}://#{request.host}"
81
+ s << ":#{request.port}" if request.port != 80
82
+ s << path
83
+
84
+ return s
85
+ end
86
+
87
+ #
88
+ # The course directory.
89
+ #
90
+ # @return [String]
91
+ # The course directory.
92
+ #
93
+ # @example
94
+ # course_dir
95
+ # # => "/course/"
96
+ #
97
+ # @since 0.1.0
98
+ #
99
+ def course_dir
100
+ "#{Config::COURSE_DIR}/"
101
+ end
102
+
103
+ #
104
+ # The full course starting URL.
105
+ #
106
+ # @return [String]
107
+ # The remote course starting URL.
108
+ #
109
+ # @example
110
+ # course_start
111
+ # # => "http://localhost:8080/course/start.html"
112
+ #
113
+ # @since 0.1.0
114
+ #
115
+ def course_start
116
+ remote_url Config::COURSE_START_PATH
117
+ end
118
+
119
+ #
120
+ # The full course failure URL.
121
+ #
122
+ # @return [String]
123
+ # The remote course failure URL.
124
+ #
125
+ # @example
126
+ # course_fail
127
+ # # => "http://localhost:8080/course/fail"
128
+ #
129
+ # @since 0.1.0
130
+ #
131
+ def course_fail
132
+ remote_url Config::COURSE_FAIL_PATH
133
+ end
134
+
135
+ #
136
+ # The specs for the course.
137
+ #
138
+ # @return [Array<Hash>]
139
+ # The Array of specs for each URL within the course.
140
+ #
141
+ # @since 0.1.0
142
+ #
143
+ def specs
144
+ CourseSpecs.specs_for(request.host,request.port)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,111 @@
1
+ #
2
+ # WSOC - The Web Spider Obstacle Course
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'json'
22
+ require 'yaml'
23
+
24
+ module WSOC
25
+ module Helpers
26
+ module Rendering
27
+ #
28
+ # Renders a partial template.
29
+ #
30
+ # @param [Symbol] page
31
+ # The name of the partial template.
32
+ #
33
+ # @param [Hash] options
34
+ # Additional options.
35
+ #
36
+ # @return [String]
37
+ # The rendered partial.
38
+ #
39
+ # @example
40
+ # partial :course_include
41
+ #
42
+ # @since 0.1.0
43
+ #
44
+ def partial(page,options={})
45
+ erb "_#{page}".to_sym, options.merge(:layout => false)
46
+ end
47
+
48
+ #
49
+ # Renders a page.
50
+ #
51
+ # @param [Symbol] page
52
+ # Name of the page to render.
53
+ #
54
+ # @param [Hash] options
55
+ # Additional options.
56
+ #
57
+ # @return [String]
58
+ # The rendered page.
59
+ #
60
+ # @example
61
+ # show :course_fail
62
+ #
63
+ # @since 0.1.0
64
+ #
65
+ def show(page,options={})
66
+ erb(page,options)
67
+ end
68
+
69
+ #
70
+ # Renders a JSON blob and sets the content-type accordingly.
71
+ #
72
+ # @param [Object] obj
73
+ # The object to encode.
74
+ #
75
+ # @return [String]
76
+ # The JSON encoded object.
77
+ #
78
+ # @example
79
+ # json @specs
80
+ #
81
+ # @since 0.1.0
82
+ #
83
+ def json(obj)
84
+ content_type :json
85
+
86
+ obj = obj.to_s unless obj.respond_to?(:to_json)
87
+ return obj.to_json
88
+ end
89
+
90
+ #
91
+ # Renders a YAML blob and sets the content-type accordingly.
92
+ #
93
+ # @param [Object] obj
94
+ # The object to encode.
95
+ #
96
+ # @return [String]
97
+ # The YAML encoded object.
98
+ #
99
+ # @example
100
+ # yaml @specs
101
+ #
102
+ # @since 0.1.0
103
+ #
104
+ def yaml(obj)
105
+ content_type :yaml
106
+
107
+ return YAML.dump(obj)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,123 @@
1
+ #
2
+ # WSOC - The Web Spider Obstacle Course
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'wsoc/config'
22
+ require 'wsoc/app'
23
+
24
+ require 'optparse'
25
+
26
+ module WSOC
27
+ class Runner
28
+
29
+ # Host to run the WSOC server on
30
+ attr_reader :host
31
+
32
+ # Port to run the WSOC server on
33
+ attr_reader :port
34
+
35
+ #
36
+ # Creates a new runner.
37
+ #
38
+ # @since 0.1.0
39
+ #
40
+ def initialize
41
+ @host = Config::DEFAULT_HOST
42
+ @port = Config::DEFAULT_PORT
43
+ @handler = nil
44
+ end
45
+
46
+ #
47
+ # Starts the runner.
48
+ #
49
+ # @param [Array<String>] argvs (ARGV)
50
+ # The arguments to run the runner with.
51
+ #
52
+ # @since 0.1.0
53
+ #
54
+ def Runner.start(args=ARGV)
55
+ runner = self.new()
56
+ runner.run(*args)
57
+ end
58
+
59
+ #
60
+ # Runs the runner.
61
+ #
62
+ # @param [Array<String>] args
63
+ # The arguments to run the runner with.
64
+ #
65
+ # @since 0.1.0
66
+ #
67
+ def run(*args)
68
+ optparse(*args)
69
+
70
+ options = {
71
+ :env => :production,
72
+ :host => @host,
73
+ :port => @port
74
+ }
75
+
76
+ options.merge!(:server => @handler) if @handler
77
+
78
+ App.run!(options)
79
+ end
80
+
81
+ protected
82
+
83
+ #
84
+ # Parses the given arguments.
85
+ #
86
+ # @param [Array<String>] args
87
+ # The arguments to parse.
88
+ #
89
+ # @since 0.1.0
90
+ #
91
+ def optparse(*args)
92
+ opts = OptionParser.new
93
+
94
+ opts.banner = "usage: #{$0} [options]"
95
+
96
+ opts.on('-H','--host HOST',"The host to run the server on","Default: #{@host}") do |host|
97
+ @host = host
98
+ end
99
+
100
+ opts.on('-p','--port PORT',"The port to run the server on","Default: #{@port}") do |port|
101
+ @port = port.to_i
102
+ end
103
+
104
+ opts.on('--s','--server NAME','Rack handler to run the server under') do |handler|
105
+ @handler = handler
106
+ end
107
+
108
+ opts.on('-h','--help','Display the help output') do
109
+ puts opts
110
+ exit
111
+ end
112
+
113
+ begin
114
+ opts.parse!(args)
115
+ rescue OptionParser::InvalidOption => e
116
+ STDERR.puts e.message
117
+ STDERR.puts opts
118
+ exit -1
119
+ end
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # WSOC - The Web Spider Obstacle Course
3
+ #
4
+ # Copyright (c) 2009-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ module WSOC
22
+ module Specs
23
+ def self.included(base)
24
+ base.module_eval do
25
+ def self.specs
26
+ @@specs ||= []
27
+ end
28
+
29
+ def self.should(behavior,options)
30
+ self.specs << {:behavior => behavior}.merge(options)
31
+ end
32
+
33
+ def self.specs_for(host,port=nil)
34
+ prefix = "http://#{host}"
35
+ prefix << ":#{port}" if (port && port != 80)
36
+
37
+ self.specs.map do |spec|
38
+ unless spec[:url] =~ /^[a-zA-Z0-9]+:/
39
+ spec.merge(:url => prefix + spec[:url])
40
+ else
41
+ spec
42
+ end
43
+ end
44
+ end
45
+
46
+ protected
47
+
48
+ def self.should_visit(url,message=nil)
49
+ self.should(:visit,:url => url, :message => message)
50
+ end
51
+
52
+ def self.should_ignore(url,message=nil)
53
+ self.should(:ignore,:url => url, :message => message)
54
+ end
55
+
56
+ def self.should_fail(url,message=nil)
57
+ self.should(:fail,:url => url, :message => message)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end