angelo 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -4
- data/CHANGELOG.md +22 -0
- data/Gemfile +5 -4
- data/README.md +101 -57
- data/angelo.gemspec +13 -10
- data/lib/angelo.rb +5 -2
- data/lib/angelo/base.rb +136 -54
- data/lib/angelo/main.rb +47 -0
- data/lib/angelo/minitest/helpers.rb +51 -23
- data/lib/angelo/params_parser.rb +33 -17
- data/lib/angelo/responder.rb +10 -9
- data/lib/angelo/responder/eventsource.rb +21 -20
- data/lib/angelo/responder/websocket.rb +1 -2
- data/lib/angelo/stash.rb +5 -3
- data/lib/angelo/tilt/erb.rb +38 -11
- data/lib/angelo/version.rb +1 -1
- data/test/angelo/erb_spec.rb +65 -3
- data/test/angelo/mustermann_spec.rb +1 -8
- data/test/angelo/options_spec.rb +19 -0
- data/test/angelo/params_spec.rb +27 -2
- data/test/angelo_spec.rb +18 -0
- data/test/main/app.rb +38 -0
- data/test/main/main_spec.rb +101 -0
- data/test/spec_helper.rb +7 -39
- metadata +37 -6
- data/lib/angelo/mustermann.rb +0 -98
data/test/angelo/erb_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
-
require 'angelo/tilt/erb'
|
3
2
|
|
4
3
|
describe Angelo::Base do
|
5
4
|
describe Angelo::Tilt::ERB do
|
@@ -54,8 +53,6 @@ JS
|
|
54
53
|
|
55
54
|
define_app do
|
56
55
|
|
57
|
-
include Angelo::Tilt::ERB
|
58
|
-
|
59
56
|
@root = TEST_APP_ROOT
|
60
57
|
|
61
58
|
def set_vars
|
@@ -218,6 +215,71 @@ HTML
|
|
218
215
|
last_response.body.must_equal expected_json
|
219
216
|
last_response.headers['Content-Type'].must_equal 'application/json'
|
220
217
|
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe 'reload_templates!' do
|
221
|
+
|
222
|
+
expected_html = <<HTML
|
223
|
+
<!doctype html>
|
224
|
+
<html>
|
225
|
+
<head>
|
226
|
+
<title>test</title>
|
227
|
+
</head>
|
228
|
+
<body>
|
229
|
+
foo - asdf
|
230
|
+
locals :bar - bat
|
231
|
+
|
232
|
+
</body>
|
233
|
+
</html>
|
234
|
+
HTML
|
235
|
+
|
236
|
+
reloaded_expected_html = <<HTML
|
237
|
+
<!doctype html>
|
238
|
+
<html>
|
239
|
+
<head>
|
240
|
+
<title>test</title>
|
241
|
+
</head>
|
242
|
+
<body>
|
243
|
+
foo - asdf
|
244
|
+
locals :bar - bat
|
245
|
+
hi
|
246
|
+
|
247
|
+
</body>
|
248
|
+
</html>
|
249
|
+
HTML
|
250
|
+
|
251
|
+
define_app do
|
252
|
+
@root = TEST_APP_ROOT
|
253
|
+
|
254
|
+
def set_vars
|
255
|
+
@title = 'test'
|
256
|
+
@foo = params[:foo]
|
257
|
+
end
|
258
|
+
|
259
|
+
reload_templates!
|
260
|
+
|
261
|
+
get '/' do
|
262
|
+
set_vars
|
263
|
+
erb :index, locals: {bar: 'bat'}
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'reloads templates' do
|
268
|
+
original_index = File.read TEST_APP_ROOT + '/views/index.html.erb'
|
269
|
+
begin
|
270
|
+
get '/', foo: 'asdf'
|
271
|
+
last_response_must_be_html expected_html
|
272
|
+
File.open TEST_APP_ROOT + '/views/index.html.erb', 'a' do |f|
|
273
|
+
f.puts 'hi'
|
274
|
+
end
|
275
|
+
get '/', foo: 'asdf'
|
276
|
+
last_response_must_be_html reloaded_expected_html
|
277
|
+
ensure
|
278
|
+
File.open TEST_APP_ROOT + '/views/index.html.erb', 'w' do |f|
|
279
|
+
f.write original_index
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
221
283
|
|
222
284
|
end
|
223
285
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
if RUBY_VERSION =~ /^2\.(\d)/ and $1.to_i > 0 and RUBY_PLATFORM != 'java'
|
2
2
|
|
3
3
|
require_relative '../spec_helper'
|
4
|
-
require 'angelo/mustermann'
|
5
|
-
require 'angelo/tilt/erb'
|
6
4
|
|
7
|
-
describe
|
5
|
+
describe 'mustermann integration' do
|
8
6
|
|
9
7
|
describe 'pattern matching' do
|
10
8
|
|
@@ -12,7 +10,6 @@ if RUBY_VERSION =~ /^2\.(\d)/ and $1.to_i > 0 and RUBY_PLATFORM != 'java'
|
|
12
10
|
let(:mm_pattern){ ::Mustermann.new(pattern) }
|
13
11
|
|
14
12
|
define_app do
|
15
|
-
include Angelo::Mustermann
|
16
13
|
content_type :json
|
17
14
|
|
18
15
|
get pattern do
|
@@ -59,8 +56,6 @@ if RUBY_VERSION =~ /^2\.(\d)/ and $1.to_i > 0 and RUBY_PLATFORM != 'java'
|
|
59
56
|
describe 'tilt/erb integration' do
|
60
57
|
|
61
58
|
define_app do
|
62
|
-
include Angelo::Tilt::ERB
|
63
|
-
include Angelo::Mustermann
|
64
59
|
|
65
60
|
@root = TEST_APP_ROOT
|
66
61
|
|
@@ -99,7 +94,6 @@ HTML
|
|
99
94
|
describe 'params in route blocks' do
|
100
95
|
|
101
96
|
define_app do
|
102
|
-
include Angelo::Mustermann
|
103
97
|
|
104
98
|
before '/before/:foo' do
|
105
99
|
@foo = params[:foo]
|
@@ -127,7 +121,6 @@ HTML
|
|
127
121
|
describe 'wildcard' do
|
128
122
|
|
129
123
|
define_app do
|
130
|
-
include Angelo::Mustermann
|
131
124
|
|
132
125
|
before do
|
133
126
|
@foo = params[:foo]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "parse_options" do
|
4
|
+
describe "parses" do
|
5
|
+
it "-p port" do
|
6
|
+
Class.new(Angelo::Base) do
|
7
|
+
parse_options("-p 12345".split)
|
8
|
+
port.must_equal 12345
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "-o addr" do
|
13
|
+
Class.new(Angelo::Base) do
|
14
|
+
parse_options("-o 3.2.1.0".split)
|
15
|
+
addr.must_equal "3.2.1.0"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/angelo/params_spec.rb
CHANGED
@@ -60,6 +60,13 @@ describe Angelo::ParamsParser do
|
|
60
60
|
parser.parse_post_body.must_equal post_params
|
61
61
|
end
|
62
62
|
|
63
|
+
it "doesn't choke on empty JSON POST bodies" do
|
64
|
+
parser.form_encoded = false
|
65
|
+
parser.json = true
|
66
|
+
parser.body = ""
|
67
|
+
parser.parse_post_body.must_equal({})
|
68
|
+
end
|
69
|
+
|
63
70
|
it 'recursively symhashes JSON POST bodies params' do
|
64
71
|
nested = {
|
65
72
|
foo: {
|
@@ -84,7 +91,7 @@ describe Angelo::ParamsParser do
|
|
84
91
|
parser.json = true
|
85
92
|
parser.query_string = get_params
|
86
93
|
parser.body = json_params
|
87
|
-
parser.
|
94
|
+
parser.parse_query_string_and_post_body.must_equal post_params
|
88
95
|
end
|
89
96
|
|
90
97
|
it 'does not parse POST bodies if no Content-Type' do
|
@@ -92,8 +99,26 @@ describe Angelo::ParamsParser do
|
|
92
99
|
parser.json = false
|
93
100
|
parser.query_string = get_params
|
94
101
|
parser.body = nil
|
95
|
-
parser.parse_post_body.must_equal params_s
|
96
102
|
parser.parse_query_string.must_equal params_s
|
103
|
+
parser.parse_post_body.must_equal({})
|
104
|
+
parser.parse_query_string_and_post_body.must_equal params_s
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe Angelo::SymHash do
|
110
|
+
|
111
|
+
describe ".new" do
|
112
|
+
it "returns a Hash" do
|
113
|
+
Angelo::SymHash.new.must_be_kind_of Hash
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it "fetches values for Symbols that were inserted with Strings" do
|
118
|
+
symhash = Angelo::SymHash.new
|
119
|
+
symhash["x"] = "y"
|
120
|
+
symhash["x"].must_equal "y"
|
121
|
+
symhash[:x].must_equal "y"
|
97
122
|
end
|
98
123
|
|
99
124
|
end
|
data/test/angelo_spec.rb
CHANGED
@@ -442,6 +442,24 @@ describe Angelo::Base do
|
|
442
442
|
|
443
443
|
end
|
444
444
|
|
445
|
+
describe 'test Angelo::Base subclasses' do
|
446
|
+
|
447
|
+
class MyWebApp < Angelo::Base
|
448
|
+
get '/up_and_running' do
|
449
|
+
content_type :html
|
450
|
+
'ok'
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
define_app MyWebApp
|
455
|
+
|
456
|
+
it 'answers to up_and_running' do
|
457
|
+
get '/up_and_running'
|
458
|
+
assert_equal(last_response.body, 'ok')
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
|
445
463
|
describe 'dsl configs' do
|
446
464
|
|
447
465
|
describe 'addr' do
|
data/test/main/app.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file is run by main_test.rb. It starts a separate server
|
2
|
+
# process that main_spec.rb queries to make sure things get set up and
|
3
|
+
# work correctly with require "angelo/main" which we don't want to
|
4
|
+
# require in the test process because it wants to take over: parse
|
5
|
+
# args, add methods to main, and run a server. So we isolate it in
|
6
|
+
# its own process here.
|
7
|
+
|
8
|
+
require "rubygems"
|
9
|
+
require "bundler/setup"
|
10
|
+
|
11
|
+
$:.unshift File.expand_path "../../../lib", __FILE__
|
12
|
+
require "angelo/main"
|
13
|
+
|
14
|
+
# Use top-level DSL to make sure it works. And the server should
|
15
|
+
# auto-run at exit.
|
16
|
+
|
17
|
+
helpers do
|
18
|
+
def help_me
|
19
|
+
"help me!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
get "/app_file" do
|
24
|
+
self.class.app_file
|
25
|
+
end
|
26
|
+
|
27
|
+
get "/mainonly" do
|
28
|
+
begin
|
29
|
+
Object.new.send(:get, "/spud") {}
|
30
|
+
"false"
|
31
|
+
rescue NameError
|
32
|
+
"true"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
get "/help" do
|
37
|
+
help_me
|
38
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# These tests start a real server and talk to it over TCP so we can
|
2
|
+
# isolate the effects of require "angelo/main" in a separate process
|
3
|
+
# but still test them.
|
4
|
+
#
|
5
|
+
# See test/main/app.rb for the code of the app we test against.
|
6
|
+
|
7
|
+
require_relative '../spec_helper'
|
8
|
+
|
9
|
+
class MainSpec < Minitest::Spec
|
10
|
+
|
11
|
+
# Info for starting the server.
|
12
|
+
|
13
|
+
app_file = File.expand_path("../app.rb", __FILE__)
|
14
|
+
address = "127.0.0.1"
|
15
|
+
port = 14410
|
16
|
+
|
17
|
+
server_command = "#{RbConfig.ruby} #{app_file} -o #{address} -p #{port}"
|
18
|
+
|
19
|
+
# Start the server.
|
20
|
+
|
21
|
+
pid = spawn server_command, out: "/dev/null", err: "/dev/null"
|
22
|
+
|
23
|
+
# Prepare to shut it down.
|
24
|
+
|
25
|
+
MiniTest.after_run do
|
26
|
+
begin
|
27
|
+
Process.kill("KILL", pid)
|
28
|
+
rescue Errno::ESRCH
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Client for talking to the server.
|
33
|
+
|
34
|
+
client = HTTPClient.new
|
35
|
+
client.connect_timeout = 1
|
36
|
+
client.send_timeout = 1
|
37
|
+
client.receive_timeout = 1
|
38
|
+
|
39
|
+
# Use define method so client_get's body is a closure that captures
|
40
|
+
# the lovely variables we just set up. Nevermind all the hoops we
|
41
|
+
# have to jump through to do that. Define this on the class because
|
42
|
+
# we're going to need it in a bit to check that the server is alive.
|
43
|
+
|
44
|
+
self.singleton_class.class_eval do
|
45
|
+
define_method :client_get do |url|
|
46
|
+
client.get("http://#{address}:#{port}#{url}").body
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def client_get(url)
|
51
|
+
self.class.client_get(url)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Wait for the server to start up. If it doesn't start, the
|
55
|
+
# cleanest thing to do seems ot be to let the tests run anyway and
|
56
|
+
# fail to connect.
|
57
|
+
|
58
|
+
def self.wait_for_server(timeout)
|
59
|
+
started = Time.now
|
60
|
+
while !(alive = alive?) && Time.now - started < timeout
|
61
|
+
sleep 0.1
|
62
|
+
end
|
63
|
+
alive
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.alive?
|
67
|
+
# This will 404 but that's good enough.
|
68
|
+
3.times { client_get("/ping") }
|
69
|
+
true
|
70
|
+
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError, SystemCallError
|
71
|
+
# No doubt that's not an exhaustive list of exceptions we should
|
72
|
+
# rescue.
|
73
|
+
false
|
74
|
+
end
|
75
|
+
|
76
|
+
if !self.wait_for_server(2)
|
77
|
+
# Write this out after the tests finish, where it's likely to be seen.
|
78
|
+
MiniTest.after_run do
|
79
|
+
STDERR.puts
|
80
|
+
STDERR.puts "The server for main_spec.rb failed to start."
|
81
|
+
STDERR.puts "Try running it manually for debugging like this:"
|
82
|
+
STDERR.puts " #{server_command}"
|
83
|
+
STDERR.puts
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'require "angelo/main"' do
|
88
|
+
it "sets app_file to the file being run" do
|
89
|
+
client_get("/app_file").must_equal app_file
|
90
|
+
end
|
91
|
+
|
92
|
+
it "only extends main" do
|
93
|
+
client_get("/mainonly").must_equal "true"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "makes helpers accessible" do
|
97
|
+
client_get("/help").must_equal "help me!"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/test/spec_helper.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
$:.unshift File.expand_path '../../lib', __FILE__
|
2
2
|
|
3
|
+
if RUBY_ENGINE == "ruby" && ENV['TRAVIS'] != 'true'
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.coverage_dir File.join('test', 'coverage')
|
6
|
+
SimpleCov.start
|
7
|
+
SimpleCov.command_name 'minitest'
|
8
|
+
end
|
9
|
+
|
3
10
|
require 'bundler'
|
4
11
|
Bundler.require :default, :development, :test
|
5
12
|
require 'minitest/pride'
|
@@ -42,47 +49,8 @@ class CountDownLatch
|
|
42
49
|
|
43
50
|
end
|
44
51
|
|
45
|
-
module Cellper
|
46
|
-
|
47
|
-
@@stop = false
|
48
|
-
@@testers = {}
|
49
|
-
|
50
|
-
def define_action sym, &block
|
51
|
-
define_method sym, &block
|
52
|
-
end
|
53
|
-
|
54
|
-
def remove_action sym
|
55
|
-
remove_method sym
|
56
|
-
end
|
57
|
-
|
58
|
-
def unstop!
|
59
|
-
@@stop = false
|
60
|
-
end
|
61
|
-
|
62
|
-
def stop!
|
63
|
-
@@stop = true
|
64
|
-
end
|
65
|
-
|
66
|
-
def stop?
|
67
|
-
@@stop
|
68
|
-
end
|
69
|
-
|
70
|
-
def testers; @@testers; end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
class Reactor
|
75
|
-
include Celluloid::IO
|
76
|
-
extend Cellper
|
77
|
-
end
|
78
|
-
|
79
52
|
$reactor = Reactor.new
|
80
53
|
|
81
|
-
class ActorPool
|
82
|
-
include Celluloid
|
83
|
-
extend Cellper
|
84
|
-
end
|
85
|
-
|
86
54
|
$pool = ActorPool.pool size: CONCURRENCY
|
87
55
|
|
88
56
|
def obj
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angelo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenichi Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reel
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tilt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mustermann
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: mime-types
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +66,7 @@ dependencies:
|
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '2.4'
|
41
|
-
description: A Sinatra-
|
69
|
+
description: A Sinatra-like DSL for Reel
|
42
70
|
email:
|
43
71
|
- kenichi.nakamura@gmail.com
|
44
72
|
executables: []
|
@@ -55,8 +83,8 @@ files:
|
|
55
83
|
- angelo.gemspec
|
56
84
|
- lib/angelo.rb
|
57
85
|
- lib/angelo/base.rb
|
86
|
+
- lib/angelo/main.rb
|
58
87
|
- lib/angelo/minitest/helpers.rb
|
59
|
-
- lib/angelo/mustermann.rb
|
60
88
|
- lib/angelo/params_parser.rb
|
61
89
|
- lib/angelo/responder.rb
|
62
90
|
- lib/angelo/responder/eventsource.rb
|
@@ -70,11 +98,14 @@ files:
|
|
70
98
|
- test/angelo/eventsource_spec.rb
|
71
99
|
- test/angelo/filter_spec.rb
|
72
100
|
- test/angelo/mustermann_spec.rb
|
101
|
+
- test/angelo/options_spec.rb
|
73
102
|
- test/angelo/params_spec.rb
|
74
103
|
- test/angelo/stash_spec.rb
|
75
104
|
- test/angelo/static_spec.rb
|
76
105
|
- test/angelo/websocket_spec.rb
|
77
106
|
- test/angelo_spec.rb
|
107
|
+
- test/main/app.rb
|
108
|
+
- test/main/main_spec.rb
|
78
109
|
- test/spec_helper.rb
|
79
110
|
- test/test_app_root/public/jquery-1.7.1.min.js
|
80
111
|
- test/test_app_root/public/test.css
|
@@ -99,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
130
|
requirements:
|
100
131
|
- - ">="
|
101
132
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
133
|
+
version: 2.1.0
|
103
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
135
|
requirements:
|
105
136
|
- - ">="
|
@@ -110,5 +141,5 @@ rubyforge_project:
|
|
110
141
|
rubygems_version: 2.4.5
|
111
142
|
signing_key:
|
112
143
|
specification_version: 4
|
113
|
-
summary: A Sinatra-
|
144
|
+
summary: A Sinatra-like DSL for Reel
|
114
145
|
test_files: []
|