woah 1.2.2 → 1.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb45f60031e5467ff757e5095e822a7bef583a6225840bfc917b2795afd40bc3
4
- data.tar.gz: 63afa8fe95815849bdd0f2362336cc21d50ebb902e3b8c424d6891c586f3a3da
3
+ metadata.gz: ddb6b67913b808a98ad7c48a4382979b17b21b8ef0b1850b9a35095a60c492a4
4
+ data.tar.gz: d62145c5797169caf6168b9e731aa398988ea52a65820e5e6f1d98482f86dc87
5
5
  SHA512:
6
- metadata.gz: 29cb1e9b4287a3ee58d25c1db92138d7eb1572e6665bcefcfc4679908639d8af4a5d0d3b7a1e01b906fcbc2d3ae8584fc1530737e66d8e098f4472d4c85acb45
7
- data.tar.gz: 39c4fa1fa939c57a4ccc44eeb27e5c46689995a4394691d7f51c0300aade6d0772ae881bc11ec25c55ce0251ccaf2d86259bcc2ba90770897b2ea536c43fdd5a
6
+ metadata.gz: c8d3e98403cd86bdad62c2bfdda6ca74f02b6af31c1dd5da0e20874deb70be12805bf1f881222807b0139fb4dc1a39f3f0250b443b5678af42c15067a369b670
7
+ data.tar.gz: f60a750ca74dde1147300f4e3fff67936ade336d82a8f89556e7831cdd5f255897f1c141be38722b6b3a88355768f2a0a58af3f55d13522196948bfabf10ad8e
data/lib/woah/base.rb CHANGED
@@ -1,175 +1,177 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Woah
4
- # Base for apps
5
- class Base
6
- @@before = nil
7
- @@after = nil
8
- @@routes = []
9
-
10
- def initialize
11
- @@override = {}
12
- @@match = nil
13
- @@request = nil
14
- @@response = nil
15
- end
16
-
17
- # Answer the phone.
18
- # Finds a relevant route for the parameters in env,
19
- # and builds a response.
20
- def call(env)
21
- initialize
22
-
23
- @@request = Rack::Request.new env
24
-
25
- @@before&.call
26
-
27
- @@response = resolve_route env['REQUEST_URI'], env['REQUEST_METHOD']
28
-
29
- @@after&.call
30
-
31
- override_values
32
-
33
- # make sure we do not give nil bodies to the server
34
- @@response[:body] ||= ''
35
- @@response[:body] = [@@response[:body]]
36
-
37
- @@response.values
38
- end
39
-
40
- # Applies user overrides
41
- def override_values
42
- %i[status headers body].each do |r|
43
- @@response[r] = @@override[r] unless @@override[r].nil?
44
- end
45
- end
46
-
47
- # Resolves and executes a round
48
- # @param path [String, Regexp] the path to respond to
49
- # @param method [String] the HTTP method to use
50
- # @return [Hash] the route's response
51
- def resolve_route(path, method)
52
- route = @@routes.select { |r| r.matches?(method, path) }[0]
53
-
54
- if route.nil?
55
- return {
56
- status: 404,
57
- headers: { 'Content-Type' => 'text/html; charset=utf-8' },
58
- body: 'not found L:'
59
- }
60
- end
61
-
62
- @@match = route.match if route.match
63
-
64
- route.execute
65
- end
66
-
67
- class << self
68
- # Forwards to a new instance's #call method
69
- def call(env)
70
- new.call env
71
- end
72
-
73
- # Get this show on the road.
74
- # @param host [String] the host to use
75
- # @param port [Integer] the port to use
76
- def run!(host = '0.0.0.0', port = 4422)
77
- Rack::Handler.pick(%w[thin puma]).run new, Host: host, Port: port
78
- end
79
-
80
- # Register new routes. The optional method argument can be used to specify a method
81
- # @param path [String, Regexp] the path to respond to
82
- # @param method [String] the HTTP method to use
83
- # @raise [ArgumentError] if `method` is not a valid HTTP method
84
- def on(path, method = 'GET', &action)
85
- unless %w[DELETE GET HEAD OPTIONS PATCH POST PUT].include? method
86
- raise ArgumentError, 'Unknown method'
87
- end
88
-
89
- @@routes.push Route.new(path, method, &action)
90
- end
91
-
92
- # Takes a block that will be executed after every route
93
- def before(&action)
94
- @@before = action
95
- end
96
-
97
- # Takes a block that will be executed after every route
98
- def after(&action)
99
- @@after = action
100
- end
101
-
102
- # Redirect to another route.
103
- # @param path [String, Regexp] the path to redirect to
104
- # @param method [String] the HTTP method to use
105
- # @return [String] the redirect's body
106
- def redirect_to(path, method = 'GET')
107
- result = new.resolve_route path, method
108
-
109
- %i[status headers].each do |r|
110
- set r, result[r]
111
- end
112
-
113
- result[:body]
114
- end
115
-
116
- # Override an item in the response.
117
- # @param item [:status, :headers, :body] the item to be overriden
118
- # @param content the content to override the item with
119
- # @raise [ArgumentError] if item is outside the range of accepted values
120
- def set(item, content)
121
- unless %i[status headers body].include? item
122
- raise ArgumentError, "Unknown item #{item}, cannot override"
123
- end
124
-
125
- @@override[item] = content
126
- end
127
-
128
- # Set or read cookies
129
- # Depending on the type of `value`, respectively reads, deletes, or sets a cookie
130
- # @param key [String] the name of the cookie
131
- # @param value [nil, :delete, String]
132
- def cookie(key, value = nil)
133
- if value.nil?
134
- read_cookie key
135
- elsif value == :delete
136
- del_cookie key
137
- elsif value.is_a? String
138
- set_cookie key, value
139
- else
140
- raise ArgumentError, 'Value should be either nil, :delete, or a string'
141
- end
142
- end
143
-
144
- # Returns the value of class attribute match
145
- def match
146
- @@match
147
- end
148
-
149
- # Returns the value of class attribute request
150
- def request
151
- @@request
152
- end
153
-
154
- private
155
-
156
- def read_cookie(key)
157
- @@request.env['HTTP_COOKIE']&.split('; ')&.each do |c|
158
- s = c.split('=')
159
- return s[1] if s[0] == key
160
- end
161
- nil # if not found
162
- end
163
-
164
- def del_cookie(key)
165
- @@override[:headers] ||= {}
166
- Rack::Utils.delete_cookie_header! @@override[:headers], key
167
- end
168
-
169
- def set_cookie(key, value)
170
- @@override[:headers] ||= {}
171
- Rack::Utils.set_cookie_header! @@override[:headers], key, value
172
- end
173
- end
174
- end
4
+ # Base for apps.
5
+ class Base
6
+ @@before = nil
7
+ @@after = nil
8
+ @@routes = []
9
+
10
+ def initialize
11
+ @@override = {}
12
+ @@match = nil
13
+ @@request = nil
14
+ @@response = nil
15
+ end
16
+
17
+ # Answer the phone.
18
+ # Finds a relevant route for the parameters in env,
19
+ # and builds a response.
20
+ def call(env)
21
+ initialize
22
+
23
+ @@request = Rack::Request.new env
24
+
25
+ @@before&.call
26
+
27
+ @@response = resolve_route env['REQUEST_URI'], env['REQUEST_METHOD']
28
+
29
+ @@after&.call
30
+
31
+ override_values
32
+
33
+ # make sure we do not give nil bodies to the server
34
+ @@response[:body] ||= ''
35
+ @@response[:body] = [@@response[:body]]
36
+
37
+ @@response.values
38
+ end
39
+
40
+ # Applies user overrides.
41
+ def override_values
42
+ %i[status headers body].each do |r|
43
+ @@response[r] = @@override[r] unless @@override[r].nil?
44
+ end
45
+ end
46
+
47
+ # Resolves and executes a round.
48
+ # @param path [String, Regexp] the path to respond to
49
+ # @param method [String] the HTTP method to use
50
+ # @return [Hash] the route's response
51
+ def resolve_route(path, method)
52
+ route = @@routes.select { |r| r.matches?(method, path) }[0]
53
+
54
+ if route.nil?
55
+ return {
56
+ status: 404,
57
+ headers: { 'Content-Type' => 'text/html; charset=utf-8' },
58
+ body: 'not found L:'
59
+ }
60
+ end
61
+
62
+ @@match = route.match if route.match
63
+
64
+ route.execute
65
+ end
66
+
67
+ class << self
68
+ # Forwards to a new instance's #call method.
69
+ def call(env)
70
+ new.call env
71
+ end
72
+
73
+ # Get this show on the road.
74
+ # @param host [String] the host to use
75
+ # @param port [Integer] the port to use
76
+ def run!(host = '0.0.0.0', port = 4422)
77
+ Rack::Handler.pick(%w[thin puma]).run new, Host: host, Port: port
78
+ end
79
+
80
+ # Register new routes. The optional method argument can be used to specify
81
+ # a method.
82
+ # @param path [String, Regexp] the path to respond to
83
+ # @param method [String] the HTTP method to use
84
+ # @raise [ArgumentError] if `method` is not a valid HTTP method
85
+ def on(path, method = 'GET', &action)
86
+ unless %w[DELETE GET HEAD OPTIONS PATCH POST PUT].include? method
87
+ raise ArgumentError, 'Unknown method'
88
+ end
89
+
90
+ @@routes.push Route.new(path, method, &action)
91
+ end
92
+
93
+ # Takes a block that will be executed before every route.
94
+ def before(&action)
95
+ @@before = action
96
+ end
97
+
98
+ # Takes a block that will be executed after every route.
99
+ def after(&action)
100
+ @@after = action
101
+ end
102
+
103
+ # Redirect to another route.
104
+ # @param path [String, Regexp] the path to redirect to
105
+ # @param method [String] the HTTP method to use
106
+ # @return [String] the redirect's body
107
+ def redirect_to(path, method = 'GET')
108
+ result = new.resolve_route path, method
109
+
110
+ %i[status headers].each do |r|
111
+ set r, result[r]
112
+ end
113
+
114
+ result[:body]
115
+ end
116
+
117
+ # Override an item in the response.
118
+ # @param item [:status, :headers, :body] the item to be overriden
119
+ # @param content the content to override the item with
120
+ # @raise [ArgumentError] if item is outside the range of accepted values
121
+ def set(item, content)
122
+ unless %i[status headers body].include? item
123
+ raise ArgumentError, "Unknown item #{item}, cannot override"
124
+ end
125
+
126
+ @@override[item] = content
127
+ end
128
+
129
+ # Set or read cookies.
130
+ # Depending on the type of `value`, respectively reads, deletes, or sets
131
+ # a cookie.
132
+ # @param key [String] the name of the cookie
133
+ # @param value [nil, :delete, String]
134
+ def cookie(key, value = nil)
135
+ if value.nil?
136
+ read_cookie key
137
+ elsif value == :delete
138
+ del_cookie key
139
+ elsif value.is_a? String
140
+ set_cookie key, value
141
+ else
142
+ raise ArgumentError, 'Value should be nil, :delete, or a string'
143
+ end
144
+ end
145
+
146
+ # Returns the value of class attribute match.
147
+ def match
148
+ @@match
149
+ end
150
+
151
+ # Returns the value of class attribute request.
152
+ def request
153
+ @@request
154
+ end
155
+
156
+ private
157
+
158
+ def read_cookie(key)
159
+ @@request.env['HTTP_COOKIE']&.split('; ')&.each do |c|
160
+ s = c.split('=')
161
+ return s[1] if s[0] == key
162
+ end
163
+ nil # if not found
164
+ end
165
+
166
+ def del_cookie(key)
167
+ @@override[:headers] ||= {}
168
+ Rack::Utils.delete_cookie_header! @@override[:headers], key
169
+ end
170
+
171
+ def set_cookie(key, value)
172
+ @@override[:headers] ||= {}
173
+ Rack::Utils.set_cookie_header! @@override[:headers], key, value
174
+ end
175
+ end
176
+ end
175
177
  end
data/lib/woah/route.rb CHANGED
@@ -1,40 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Woah
4
- # A Woah! routes
5
- class Route
6
- attr_accessor :match
4
+ # A Woah! routes
5
+ class Route
6
+ attr_accessor :match
7
7
 
8
- def initialize(path, method, &action)
9
- raise 'only strings and regexps are valid paths' unless [String, Regexp].include? path.class
8
+ def initialize(path, method, &action)
9
+ unless [String, Regexp].include? path.class
10
+ raise 'only strings and regexps are valid paths'
11
+ end
10
12
 
11
- @path = path
12
- @method = method
13
- @action = action
14
- @match = nil
15
- end
13
+ @path = path
14
+ @method = method
15
+ @action = action
16
+ @match = nil
17
+ end
16
18
 
17
- # Checks if a given route is the same as this one
18
- # @param path [String, Regexp] the path to redirect to
19
- # @param method [String] the HTTP method to use
20
- # @return [Boolean] true if given method and path match this route
21
- def matches?(method, path)
22
- case @path
23
- when String
24
- @method == method && @path == path
25
- when Regexp
26
- @match = @path.match path
27
- @method == method && @match
28
- end
29
- end
19
+ # Checks if a given route is the same as this one
20
+ # @param path [String, Regexp] the path to redirect to
21
+ # @param method [String] the HTTP method to use
22
+ # @return [Boolean] true if given method and path match this route
23
+ def matches?(method, path)
24
+ case @path
25
+ when String
26
+ @method == method && @path == path
27
+ when Regexp
28
+ @match = @path.match path
29
+ @method == method && @match
30
+ end
31
+ end
30
32
 
31
- # Execute this route's actions.
32
- # @return [Hash] the route's response
33
- def execute
34
- status = 200
35
- headers = { 'Content-Type' => 'text/html; charset=utf-8' }
36
- body = @action.call
37
- { status: status, headers: headers, body: body }
38
- end
39
- end
33
+ # Execute this route's actions.
34
+ # @return [Hash] the route's response
35
+ def execute
36
+ status = 200
37
+ headers = { 'Content-Type' => 'text/html; charset=utf-8' }
38
+ body = @action.call
39
+ { status: status, headers: headers, body: body }
40
+ end
41
+ end
40
42
  end
data/lib/woah/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Woah
4
- # Woah!'s current version.
5
- VERSION = '1.2.2'
4
+ # Woah!'s current version.
5
+ VERSION = '1.2.3'
6
6
  end
@@ -1,33 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class BasicVerbsTest < MiniTest::Test
4
- def setup
5
- @env = {}
6
- end
4
+ def setup
5
+ @env = {}
6
+ end
7
7
 
8
- def test_get_root
9
- @env['REQUEST_URI'] = '/'
10
- @env['REQUEST_METHOD'] = 'GET'
11
- response = TestApp.call @env
8
+ def test_get_root
9
+ @env['REQUEST_URI'] = '/'
10
+ @env['REQUEST_METHOD'] = 'GET'
11
+ response = TestApp.call @env
12
12
 
13
- assert_equal 200, response[0]
14
- assert_equal 'hi there!', response[2][0]
15
- end
13
+ assert_equal 200, response[0]
14
+ assert_equal 'hi there!', response[2][0]
15
+ end
16
16
 
17
- def test_post
18
- @env['REQUEST_URI'] = '/'
19
- @env['REQUEST_METHOD'] = 'POST'
20
- response = TestApp.call @env
17
+ def test_post
18
+ @env['REQUEST_URI'] = '/'
19
+ @env['REQUEST_METHOD'] = 'POST'
20
+ response = TestApp.call @env
21
21
 
22
- assert_equal 200, response[0]
23
- assert_equal 'got post!', response[2][0]
24
- end
22
+ assert_equal 200, response[0]
23
+ assert_equal 'got post!', response[2][0]
24
+ end
25
25
 
26
- def test_get_404
27
- @env['REQUEST_URI'] = '/does/not/exist'
28
- @env['REQUEST_METHOD'] = 'GET'
29
- response = TestApp.call @env
26
+ def test_get_404
27
+ @env['REQUEST_URI'] = '/does/not/exist'
28
+ @env['REQUEST_METHOD'] = 'GET'
29
+ response = TestApp.call @env
30
30
 
31
- assert_equal 404, response[0]
32
- end
31
+ assert_equal 404, response[0]
32
+ end
33
33
  end
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class BeforeAfterTest < MiniTest::Test
4
- def setup
5
- @env = {}
6
- end
4
+ def setup
5
+ @env = {}
6
+ end
7
7
 
8
- def test_get_before
9
- @env['REQUEST_URI'] = '/before'
10
- @env['REQUEST_METHOD'] = 'GET'
8
+ def test_get_before
9
+ @env['REQUEST_URI'] = '/before'
10
+ @env['REQUEST_METHOD'] = 'GET'
11
11
 
12
- response = TestApp.call @env
12
+ response = TestApp.call @env
13
13
 
14
- assert_equal 200, response[0]
15
- assert_equal 'chunky', response[2][0]
14
+ assert_equal 200, response[0]
15
+ assert_equal 'chunky', response[2][0]
16
16
 
17
- @env['REQUEST_URI'] = '/after'
17
+ @env['REQUEST_URI'] = '/after'
18
18
 
19
- response = TestApp.call @env
19
+ response = TestApp.call @env
20
20
 
21
- assert_equal 200, response[0]
22
- assert_equal 'bacon', response[2][0]
23
- end
21
+ assert_equal 200, response[0]
22
+ assert_equal 'bacon', response[2][0]
23
+ end
24
24
  end
data/test/cookie_test.rb CHANGED
@@ -1,55 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class CookieTest < MiniTest::Test
4
- def setup
5
- @env = {}
6
- end
7
-
8
- def test_get_cookie
9
- @env['REQUEST_URI'] = '/get_cookie'
10
- @env['REQUEST_METHOD'] = 'GET'
11
- @env['HTTP_COOKIE'] = 'test=something'
12
- response = TestApp.call @env
13
-
14
- assert_equal 200, response[0]
15
- assert_equal 'something', response[2][0]
16
- end
17
-
18
- def test_get_nonexistent_cookie
19
- @env['REQUEST_URI'] = '/get_cookie'
20
- @env['REQUEST_METHOD'] = 'GET'
21
- response = TestApp.call @env
22
-
23
- assert_equal 200, response[0]
24
- assert_equal '', response[2][0]
25
- end
26
-
27
- def test_set_cookie
28
- @env['REQUEST_URI'] = '/set_cookie'
29
- @env['REQUEST_METHOD'] = 'GET'
30
- response = TestApp.call @env
31
-
32
- assert_equal 200, response[0]
33
- assert_equal 'fruit=apple', response[1]['Set-Cookie']
34
- assert_equal '', response[2][0]
35
- end
36
-
37
- def test_set_illegal_cookie
38
- @env['REQUEST_URI'] = '/set_illegal_cookie'
39
- @env['REQUEST_METHOD'] = 'GET'
40
-
41
- assert_raises ArgumentError do
42
- TestApp.call @env
43
- end
44
- end
45
-
46
- def test_delete_cookie
47
- @env['REQUEST_URI'] = '/delete_cookie'
48
- @env['REQUEST_METHOD'] = 'GET'
49
-
50
- response = TestApp.call @env
51
-
52
- assert_equal 200, response[0]
53
- assert response[1]['Set-Cookie'].include? 'max-age=0'
54
- end
4
+ def setup
5
+ @env = {}
6
+ end
7
+
8
+ def test_get_cookie
9
+ @env['REQUEST_URI'] = '/get_cookie'
10
+ @env['REQUEST_METHOD'] = 'GET'
11
+ @env['HTTP_COOKIE'] = 'test=something'
12
+ response = TestApp.call @env
13
+
14
+ assert_equal 200, response[0]
15
+ assert_equal 'something', response[2][0]
16
+ end
17
+
18
+ def test_get_nonexistent_cookie
19
+ @env['REQUEST_URI'] = '/get_cookie'
20
+ @env['REQUEST_METHOD'] = 'GET'
21
+ response = TestApp.call @env
22
+
23
+ assert_equal 200, response[0]
24
+ assert_equal '', response[2][0]
25
+ end
26
+
27
+ def test_set_cookie
28
+ @env['REQUEST_URI'] = '/set_cookie'
29
+ @env['REQUEST_METHOD'] = 'GET'
30
+ response = TestApp.call @env
31
+
32
+ assert_equal 200, response[0]
33
+ assert_equal 'fruit=apple', response[1]['Set-Cookie']
34
+ assert_equal '', response[2][0]
35
+ end
36
+
37
+ def test_set_illegal_cookie
38
+ @env['REQUEST_URI'] = '/set_illegal_cookie'
39
+ @env['REQUEST_METHOD'] = 'GET'
40
+
41
+ assert_raises ArgumentError do
42
+ TestApp.call @env
43
+ end
44
+ end
45
+
46
+ def test_delete_cookie
47
+ @env['REQUEST_URI'] = '/delete_cookie'
48
+ @env['REQUEST_METHOD'] = 'GET'
49
+
50
+ response = TestApp.call @env
51
+
52
+ assert_equal 200, response[0]
53
+ assert response[1]['Set-Cookie'].include? 'max-age=0'
54
+ end
55
55
  end
@@ -1,83 +1,83 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class OnMethodTest < MiniTest::Test
4
- def setup
5
- @env = {}
6
- end
7
-
8
- def test_throw_404
9
- TestApp.on '/404' do
10
- TestApp.set :status, 404
11
- "it's a secret to everybody"
12
- end
13
-
14
- @env['REQUEST_URI'] = '/404'
15
- @env['REQUEST_METHOD'] = 'GET'
16
- response = TestApp.call @env
17
-
18
- assert_equal 404, response[0]
19
- assert_equal "it's a secret to everybody", response[2][0]
20
- end
21
-
22
- def test_regexp_path
23
- TestApp.on %r{^/regex/[0-9]+$} do
24
- 'heya'
25
- end
26
-
27
- @env['REQUEST_URI'] = '/regex/22'
28
- @env['REQUEST_METHOD'] = 'GET'
29
- response = TestApp.call @env
30
-
31
- assert_equal 200, response[0]
32
-
33
- @env['REQUEST_URI'] = '/regex/seventy'
34
- response = TestApp.call @env
35
-
36
- assert_equal 404, response[0]
37
- end
38
-
39
- def test_regexp_match_data
40
- TestApp.on %r{^/myname/(\w+)$} do
41
- 'hi there, ' + TestApp.match[1]
42
- end
43
-
44
- @env['REQUEST_URI'] = '/myname/Charles'
45
- @env['REQUEST_METHOD'] = 'GET'
46
- response = TestApp.call @env
47
-
48
- assert_equal 200, response[0]
49
- assert_equal 'hi there, Charles', response[2][0]
50
- end
51
-
52
- def test_illegal_method
53
- assert_raises ArgumentError do
54
- TestApp.on '/', 'BUBBLES' do
55
- 'oOooo oO oO'
56
- end
57
- end
58
-
59
- @env['REQUEST_URI'] = '/'
60
- @env['REQUEST_METHOD'] = 'BUBBLES'
61
- response = TestApp.call @env
62
-
63
- assert_equal 404, response[0]
64
- end
65
-
66
- def test_illegal_set
67
- @env['REQUEST_URI'] = '/nose'
68
- @env['REQUEST_METHOD'] = 'GET'
69
-
70
- assert_raises ArgumentError do
71
- TestApp.call @env
72
- end
73
- end
74
-
75
- def test_request_object
76
- @env['REQUEST_URI'] = '/ip'
77
- @env['REQUEST_METHOD'] = 'GET'
78
- response = TestApp.call @env
79
-
80
- assert_equal 200, response[0]
81
- assert_equal '/ip', response[2][0]
82
- end
4
+ def setup
5
+ @env = {}
6
+ end
7
+
8
+ def test_throw_404
9
+ TestApp.on '/404' do
10
+ TestApp.set :status, 404
11
+ "it's a secret to everybody"
12
+ end
13
+
14
+ @env['REQUEST_URI'] = '/404'
15
+ @env['REQUEST_METHOD'] = 'GET'
16
+ response = TestApp.call @env
17
+
18
+ assert_equal 404, response[0]
19
+ assert_equal "it's a secret to everybody", response[2][0]
20
+ end
21
+
22
+ def test_regexp_path
23
+ TestApp.on %r{^/regex/[0-9]+$} do
24
+ 'heya'
25
+ end
26
+
27
+ @env['REQUEST_URI'] = '/regex/22'
28
+ @env['REQUEST_METHOD'] = 'GET'
29
+ response = TestApp.call @env
30
+
31
+ assert_equal 200, response[0]
32
+
33
+ @env['REQUEST_URI'] = '/regex/seventy'
34
+ response = TestApp.call @env
35
+
36
+ assert_equal 404, response[0]
37
+ end
38
+
39
+ def test_regexp_match_data
40
+ TestApp.on %r{^/myname/(\w+)$} do
41
+ 'hi there, ' + TestApp.match[1]
42
+ end
43
+
44
+ @env['REQUEST_URI'] = '/myname/Charles'
45
+ @env['REQUEST_METHOD'] = 'GET'
46
+ response = TestApp.call @env
47
+
48
+ assert_equal 200, response[0]
49
+ assert_equal 'hi there, Charles', response[2][0]
50
+ end
51
+
52
+ def test_illegal_method
53
+ assert_raises ArgumentError do
54
+ TestApp.on '/', 'BUBBLES' do
55
+ 'oOooo oO oO'
56
+ end
57
+ end
58
+
59
+ @env['REQUEST_URI'] = '/'
60
+ @env['REQUEST_METHOD'] = 'BUBBLES'
61
+ response = TestApp.call @env
62
+
63
+ assert_equal 404, response[0]
64
+ end
65
+
66
+ def test_illegal_set
67
+ @env['REQUEST_URI'] = '/nose'
68
+ @env['REQUEST_METHOD'] = 'GET'
69
+
70
+ assert_raises ArgumentError do
71
+ TestApp.call @env
72
+ end
73
+ end
74
+
75
+ def test_request_object
76
+ @env['REQUEST_URI'] = '/ip'
77
+ @env['REQUEST_METHOD'] = 'GET'
78
+ response = TestApp.call @env
79
+
80
+ assert_equal 200, response[0]
81
+ assert_equal '/ip', response[2][0]
82
+ end
83
83
  end
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedirectTest < MiniTest::Test
4
- def setup
5
- @env = {}
6
- end
4
+ def setup
5
+ @env = {}
6
+ end
7
7
 
8
- # rubocop:disable Style/GlobalVars
9
- def test_redirect
10
- TestApp.on '/goback' do
11
- $something = 'gone back'
12
- TestApp.redirect_to '/'
13
- end
8
+ # rubocop:disable Style/GlobalVars
9
+ def test_redirect
10
+ TestApp.on '/goback' do
11
+ $something = 'gone back'
12
+ TestApp.redirect_to '/'
13
+ end
14
14
 
15
- @env['REQUEST_URI'] = '/goback'
16
- @env['REQUEST_METHOD'] = 'GET'
17
- response = TestApp.call @env
15
+ @env['REQUEST_URI'] = '/goback'
16
+ @env['REQUEST_METHOD'] = 'GET'
17
+ response = TestApp.call @env
18
18
 
19
- assert_equal 200, response[0]
20
- assert_equal 'hi there!', response[2][0]
21
- assert_equal 'gone back', $something
22
- end
23
- # rubocop:enable Style/GlobalVars
19
+ assert_equal 200, response[0]
20
+ assert_equal 'hi there!', response[2][0]
21
+ assert_equal 'gone back', $something
22
+ end
23
+ # rubocop:enable Style/GlobalVars
24
24
  end
data/test/test_app.rb CHANGED
@@ -3,51 +3,51 @@
3
3
  require_relative '../lib/woah'
4
4
 
5
5
  class TestApp < Woah::Base
6
- before do
7
- @a = 'chunky'
8
- end
6
+ before do
7
+ @a = 'chunky'
8
+ end
9
9
 
10
- on '/' do
11
- 'hi there!'
12
- end
10
+ on '/' do
11
+ 'hi there!'
12
+ end
13
13
 
14
- on '/', 'POST' do
15
- 'got post!'
16
- end
14
+ on '/', 'POST' do
15
+ 'got post!'
16
+ end
17
17
 
18
- on '/before' do
19
- @a
20
- end
18
+ on '/before' do
19
+ @a
20
+ end
21
21
 
22
- on '/after' do
23
- @b
24
- end
22
+ on '/after' do
23
+ @b
24
+ end
25
25
 
26
- on '/get_cookie' do
27
- cookie 'test'
28
- end
26
+ on '/get_cookie' do
27
+ cookie 'test'
28
+ end
29
29
 
30
- on '/set_cookie' do
31
- cookie 'fruit', 'apple'
32
- end
30
+ on '/set_cookie' do
31
+ cookie 'fruit', 'apple'
32
+ end
33
33
 
34
- on '/set_illegal_cookie' do
35
- cookie 'one', 1
36
- end
34
+ on '/set_illegal_cookie' do
35
+ cookie 'one', 1
36
+ end
37
37
 
38
- on '/delete_cookie' do
39
- cookie 'foo', :delete
40
- end
38
+ on '/delete_cookie' do
39
+ cookie 'foo', :delete
40
+ end
41
41
 
42
- on '/ip' do
43
- request.env['REQUEST_URI']
44
- end
42
+ on '/ip' do
43
+ request.env['REQUEST_URI']
44
+ end
45
45
 
46
- TestApp.on '/nose' do
47
- TestApp.set :nose, true
48
- end
46
+ TestApp.on '/nose' do
47
+ TestApp.set :nose, true
48
+ end
49
49
 
50
- after do
51
- @b = 'bacon'
52
- end
50
+ after do
51
+ @b = 'bacon'
52
+ end
53
53
  end
data/test/test_helper.rb CHANGED
@@ -15,7 +15,7 @@ require 'minitest/autorun'
15
15
  require_relative 'test_app'
16
16
 
17
17
  Dir.foreach('test/') do |test|
18
- next if ['.', '..'].include? test
18
+ next if ['.', '..'].include? test
19
19
 
20
- require_relative test
20
+ require_relative test
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woah
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - knarka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-16 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -24,8 +24,9 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.6
27
- description: "Woah! is a minimal web framework built on Rack designed to let you just
28
- do your\n\tthing."
27
+ description: |-
28
+ Woah! is a minimal web framework built on Rack designed to
29
+ let you just do your thing.
29
30
  email: knarka@airmail.cc
30
31
  executables: []
31
32
  extensions: []
@@ -63,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  - !ruby/object:Gem::Version
64
65
  version: '0'
65
66
  requirements: []
66
- rubyforge_project:
67
- rubygems_version: 2.7.7
67
+ rubygems_version: 3.0.3
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Woah! is a minimal web framework built on Rack.