camping 3.1.3 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +11 -1
- data/book/04_more_about_views.md +1 -1
- data/book/07_philosophy.md +1 -1
- data/lib/camping/commands.rb +2 -4
- data/lib/camping/gear/firewatch.rb +74 -0
- data/lib/camping/gear/nancy.rb +27 -9
- data/lib/camping/loader.rb +9 -1
- data/lib/camping/loads.rb +1 -0
- data/lib/camping/server.rb +19 -5
- data/lib/camping/version.rb +1 -1
- data/lib/camping-unabridged.rb +11 -9
- data/lib/camping.rb +5 -5
- data/test/app_logger.rb +69 -0
- data/test/apps/loader/apps/donuts/controllers.rb +10 -0
- data/test/gear/gear_nancy.rb +17 -1
- data/test/test_helper.rb +28 -4
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be886915ade584cc08bca9944defc3985ff28fb9c67ea4bff803f4f5ad5c3b6a
|
4
|
+
data.tar.gz: 1d0919e7257a74b7c84cb38253fbfdcee3db82f2af4c9c525db735c93cc817ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f59a0936824edc6d51bbb6063e839d747bba292a58f022fe539fdc9c66de660065bc84050c26829fbc3497b50394c66a34db67f96025eeb4213c624c1de6bca
|
7
|
+
data.tar.gz: 143a53c658cefb5f6cc5d6195aa9096c4c26a1a5581725474bc20a3945179021fb8d817f4194391060860c033d1146476d550a52512a45a47df7824006c3f879
|
data/Rakefile
CHANGED
@@ -29,8 +29,18 @@ CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log', '.*.pt']
|
|
29
29
|
|
30
30
|
task :default => :check
|
31
31
|
|
32
|
-
|
32
|
+
# New Docs
|
33
|
+
|
34
|
+
## context for the docs sections: we're going to move to using Rdoc and yard.
|
35
|
+
## With some extras. The Docs folder will probably go away.
|
33
36
|
|
37
|
+
## New docs directly serve a website like a boss.
|
38
|
+
desc "Serves the docs locally"
|
39
|
+
task :serve do
|
40
|
+
sh "ruby -run -e httpd docs -p 8000"
|
41
|
+
end
|
42
|
+
|
43
|
+
## RDoc
|
34
44
|
begin
|
35
45
|
gem 'rdoc', '~>3.9.0'
|
36
46
|
rescue LoadError
|
data/book/04_more_about_views.md
CHANGED
data/book/07_philosophy.md
CHANGED
@@ -12,7 +12,7 @@ The End.
|
|
12
12
|
|
13
13
|
# Actual philosophy
|
14
14
|
|
15
|
-
Why The Lucky Stiff is no longer around, so those of us who contributed early on to Camping have since become its caretakers. We continue to push the framework
|
15
|
+
Why The Lucky Stiff is no longer around, so those of us who contributed early on to Camping have since become its caretakers. We continue to push the framework forward, to be more compact, to be faster, easier, more fun. These are our guiding principals:
|
16
16
|
|
17
17
|
- Camping is for everyone. It sure is great to turn an idea in to a single ruby file which creates a website. It's also great to organise an app in to several files sometimes. You can plug bits together all in a row, and grow your evil monkey in to an entire army of evil circus animals!
|
18
18
|
- Camping isn't for making money. You can make money using camping. Nobody will stop you. But we don't have any buzzwords to offer, we won't make your unit tests easier, nor help you do market research. Our main contributors certainly aren't using camping in large scale deployments, and while camping is blazingly fast, we have no idea how well it would work if you ran it on lots of servers!
|
data/lib/camping/commands.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'rack/common_logger'
|
4
|
+
require 'dry/logger'
|
5
|
+
|
6
|
+
|
7
|
+
# Firewatch is Camping's logger.
|
8
|
+
# It wraps Rack::CommonLogger, and gives a mechanism to Redirect logs.
|
9
|
+
module Camping
|
10
|
+
class Firewatch < Rack::CommonLogger
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def logger
|
14
|
+
@logger ||= default_logger
|
15
|
+
end
|
16
|
+
def logger=(new_logger)
|
17
|
+
@logger = new_logger
|
18
|
+
end
|
19
|
+
def default_logger
|
20
|
+
Dry.Logger(:Camping, template: default_template).add_backend(stream: "logs/development.log")
|
21
|
+
end
|
22
|
+
def default_template
|
23
|
+
"[<green>%<severity>s</green> - %<time>s] %<message>s"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# +logger+ can be any object that supports the +write+ or +<<+ methods,
|
28
|
+
# which includes the standard library Logger. These methods are called
|
29
|
+
# with a single string argument, the log message.
|
30
|
+
# If +logger+ is nil, Firewatch(CommonLogger) will fall back <tt>env['rack.errors']</tt>.
|
31
|
+
def initialize(app, logger = nil)
|
32
|
+
@app = app
|
33
|
+
@logger = Camping::Firewatch.logger = logger.nil? ? Camping::Firewatch.default_logger : logger
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Gear
|
40
|
+
|
41
|
+
# Fire watch Gear gives us helper methods to access the logger, log stuff,
|
42
|
+
# and do other shenanigans
|
43
|
+
module Firewatch
|
44
|
+
|
45
|
+
class << self
|
46
|
+
|
47
|
+
def included(mod)
|
48
|
+
mod::Helpers.include(HelperMethods)
|
49
|
+
end
|
50
|
+
|
51
|
+
# required for compliance reasons
|
52
|
+
def setup(app, *a, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
module HelperMethods
|
58
|
+
|
59
|
+
def logger
|
60
|
+
Camping::Firewatch.logger
|
61
|
+
end
|
62
|
+
|
63
|
+
# #log A helper method to log stuff.
|
64
|
+
# @message: String, Default: nil, An optional value used to directly log
|
65
|
+
# rather than requesting the logger
|
66
|
+
def log(message = nil)
|
67
|
+
return logger unless !message.nil?
|
68
|
+
logger.info message
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/lib/camping/gear/nancy.rb
CHANGED
@@ -21,14 +21,13 @@ module Gear
|
|
21
21
|
s = ""
|
22
22
|
rs = ""
|
23
23
|
routes.each do |r|
|
24
|
+
rs += "'#{r}'" + ","
|
24
25
|
if r == '/'
|
25
26
|
r = 'Index'
|
26
27
|
end
|
27
|
-
rs += "'#{r}'" + ","
|
28
28
|
r.split("/").each(&:capitalize!).each{|t|
|
29
29
|
s << t.gsub(/[^a-z0-9A-Z ]/, '')
|
30
30
|
}
|
31
|
-
# s << r
|
32
31
|
end
|
33
32
|
rs.chop!
|
34
33
|
|
@@ -73,12 +72,11 @@ module Gear
|
|
73
72
|
cname = "#{meth.capitalize}#{symbol.to_s}"
|
74
73
|
|
75
74
|
begin
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
], file_name, line_number.to_i)
|
75
|
+
|
76
|
+
# Find out which eval script to use.
|
77
|
+
eval_script = m.name.include?("Controllers") ? controller_script(name: cname,routes: rs) : module_script(name: cname,routes: rs)
|
78
|
+
|
79
|
+
m.module_eval(eval_script, file_name, line_number.to_i)
|
82
80
|
rescue => error
|
83
81
|
if error.message.include? "superclass mismatch for class"
|
84
82
|
raise "You've probably tried to define the same route twice using the sinatra method. ['#{rs}']"
|
@@ -93,7 +91,8 @@ module Gear
|
|
93
91
|
# If we have a rack response instead of string, then we need to extract
|
94
92
|
# the response then reassign the values. the r method is a great helper
|
95
93
|
# for that.
|
96
|
-
constantine = m::X.const_get("#{cname}")
|
94
|
+
constantine = m.name.include?("Controllers") ? m.const_get("#{cname}") : m::X.const_get("#{cname}")
|
95
|
+
|
97
96
|
if block.arity == -1
|
98
97
|
constantine.send(:define_method, meth) { |*args|
|
99
98
|
block[*args]
|
@@ -115,8 +114,27 @@ module Gear
|
|
115
114
|
return nil
|
116
115
|
end
|
117
116
|
|
117
|
+
# returns a formatted string for making a controller class in the App module
|
118
|
+
def module_script(name:, routes:)
|
119
|
+
%Q[
|
120
|
+
module Controllers
|
121
|
+
class #{name} < R #{routes}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
]
|
125
|
+
end
|
126
|
+
|
127
|
+
# returns a formatted string for making a controller class in the Controllers module
|
128
|
+
def controller_script(name:, routes:)
|
129
|
+
%Q[
|
130
|
+
class #{name} < R #{routes}
|
131
|
+
end
|
132
|
+
]
|
133
|
+
end
|
134
|
+
|
118
135
|
def included(mod)
|
119
136
|
mod.extend(ClassMethods)
|
137
|
+
mod::Controllers.extend(ClassMethods)
|
120
138
|
end
|
121
139
|
|
122
140
|
# required for compliance reasons
|
data/lib/camping/loader.rb
CHANGED
@@ -85,7 +85,13 @@ module Camping
|
|
85
85
|
all_requires = $LOADED_FEATURES.dup
|
86
86
|
all_apps = Camping::Apps.dup
|
87
87
|
|
88
|
+
# Zeitwerk will Autoload stuff, which is great. But we don't want Zeitwerk
|
89
|
+
# autoloading when we evaluate the camp.rb file because it will try to
|
90
|
+
# autoload any controllers and helpers that we've defined in there from
|
91
|
+
# the descendant /apps and /lib directory, which then make it break.
|
92
|
+
@zeit.unload
|
88
93
|
load_file
|
94
|
+
@zeit.setup
|
89
95
|
reload_directory("#{@root}/apps")
|
90
96
|
reload_directory("#{@root}/lib")
|
91
97
|
Camping.make_camp
|
@@ -138,7 +144,7 @@ module Camping
|
|
138
144
|
# so everything in /apps, and /lib in relation from this script.
|
139
145
|
def remove_constants
|
140
146
|
@requires.each do |(path, full)|
|
141
|
-
$LOADED_FEATURES.delete(path)
|
147
|
+
$LOADED_FEATURES.delete(path) unless path.match? "concurrent-ruby"
|
142
148
|
end
|
143
149
|
|
144
150
|
@apps.each do |name, app|
|
@@ -200,6 +206,7 @@ module Camping
|
|
200
206
|
end
|
201
207
|
|
202
208
|
# Splits the descendent files and folders found in a given directory for eager loading and recursion.
|
209
|
+
# If the given directory doesn't exist or is empty, then nothing is returned.
|
203
210
|
def folders_and_files_in(directory)
|
204
211
|
directory = directory + "/*" # unless directory
|
205
212
|
[Dir.glob(directory).select {|f| !File.directory? f },
|
@@ -207,6 +214,7 @@ module Camping
|
|
207
214
|
end
|
208
215
|
|
209
216
|
# Reloads a directory recursively. loading more shallow files before deeper files.
|
217
|
+
# If the given directory doesn't exist or is empty, then nothing happens.
|
210
218
|
def reload_directory(directory)
|
211
219
|
files, folders = folders_and_files_in(directory)
|
212
220
|
files.each {|file|
|
data/lib/camping/loads.rb
CHANGED
data/lib/camping/server.rb
CHANGED
@@ -3,6 +3,7 @@ require 'erb'
|
|
3
3
|
require 'rack'
|
4
4
|
require 'rackup'
|
5
5
|
require 'camping/version'
|
6
|
+
require 'camping/firewatch'
|
6
7
|
require 'camping/loader'
|
7
8
|
require 'camping/commands'
|
8
9
|
|
@@ -93,6 +94,10 @@ module Camping
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
97
|
+
def loader
|
98
|
+
@reloader || nil
|
99
|
+
end
|
100
|
+
|
96
101
|
def opt_parser
|
97
102
|
Options.new
|
98
103
|
end
|
@@ -103,18 +108,25 @@ module Camping
|
|
103
108
|
})
|
104
109
|
end
|
105
110
|
|
111
|
+
# redefine logging middleware
|
112
|
+
class << self
|
113
|
+
def logging_middleware
|
114
|
+
@logger ||= Camping::Firewatch.logger
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
106
118
|
def middleware
|
107
119
|
h = super
|
108
120
|
h["development"] << [XSendfile]
|
109
121
|
h
|
110
122
|
end
|
111
123
|
|
112
|
-
|
124
|
+
# Starts the Camping Server. Camping server inherits from Rack::Server so
|
125
|
+
# referencing their documentation would be a good idea.
|
126
|
+
# @file: String, file location for a camp.rb file.
|
127
|
+
def start(file = nil)
|
113
128
|
|
114
|
-
commands =
|
115
|
-
ARGV.each do |cmd|
|
116
|
-
commands << cmd
|
117
|
-
end
|
129
|
+
commands = ARGV
|
118
130
|
|
119
131
|
# Parse commands
|
120
132
|
case commands[0]
|
@@ -131,6 +143,8 @@ module Camping
|
|
131
143
|
@reloader.reload!
|
132
144
|
r = @reloader
|
133
145
|
|
146
|
+
logger = r.apps.first.options[:logger]
|
147
|
+
|
134
148
|
if options[:routes] == true
|
135
149
|
eval("self", TOPLEVEL_BINDING).meta_def(:reload!) { r.reload!; nil }
|
136
150
|
ARGV.clear
|
data/lib/camping/version.rb
CHANGED
data/lib/camping-unabridged.rb
CHANGED
@@ -17,7 +17,7 @@ Z ||= "text/html"
|
|
17
17
|
|
18
18
|
class Object #:nodoc:
|
19
19
|
def meta_def(m,&b) #:nodoc:
|
20
|
-
(class<<self;self end).
|
20
|
+
(class<<self;self end).define_method(m,&b)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -81,7 +81,7 @@ module Camping
|
|
81
81
|
# => :macadamian
|
82
82
|
#
|
83
83
|
def method_missing(m,*a)
|
84
|
-
|
84
|
+
m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
|
85
85
|
end
|
86
86
|
undef id, type if ?? == 63
|
87
87
|
end
|
@@ -672,7 +672,7 @@ module Camping
|
|
672
672
|
# TODO: Refactor this to make it less convoluted around making urls.
|
673
673
|
constants.filter {|c| c.to_s != 'Camper'}.map { |c|
|
674
674
|
k = const_get(c)
|
675
|
-
k.
|
675
|
+
k.include(C,X,Base,Helpers,Models)
|
676
676
|
@r=[k]+@r if @r-[k]==@r
|
677
677
|
mu = false # Should we make urls?
|
678
678
|
ka = k.ancestors
|
@@ -703,9 +703,8 @@ module Camping
|
|
703
703
|
# helps Camping::Server map routes to multiple apps.
|
704
704
|
# Usage:
|
705
705
|
#
|
706
|
-
# Nuts.routes
|
706
|
+
# Nuts.routes # returns routes for Nuts
|
707
707
|
# Camping.routes
|
708
|
-
# Nuts.routes
|
709
708
|
#
|
710
709
|
def routes
|
711
710
|
(Apps.map(&:routes)<<X.v).flatten
|
@@ -714,6 +713,7 @@ module Camping
|
|
714
713
|
# An internal method used to return the current app's url_prefix.
|
715
714
|
# the prefix is processed to make sure that it's not all wonky. excessive
|
716
715
|
# trailing and leading slashes are removed. A trailing slash is added.
|
716
|
+
# @return [String] A reference to the URL response
|
717
717
|
def prx
|
718
718
|
@_prx ||= CampTools.normalize_slashes(O[:url_prefix])
|
719
719
|
end
|
@@ -723,6 +723,8 @@ module Camping
|
|
723
723
|
# Array with [status, headers, body] is expected at the output.
|
724
724
|
#
|
725
725
|
# See: https://github.com/rack/rack/blob/main/SPEC.rdoc
|
726
|
+
# @param [Array] A rack response
|
727
|
+
# @return [Array] A rack response
|
726
728
|
def call(e)
|
727
729
|
k,m,*a=X.D e["PATH_INFO"],e['REQUEST_METHOD'].downcase,e
|
728
730
|
k.new(e,m,prx).service(*a).to_a
|
@@ -791,6 +793,7 @@ module Camping
|
|
791
793
|
def use(*a, &b)
|
792
794
|
m = a.shift.new(method(:call), *a, &b)
|
793
795
|
meta_def(:call) { |e| m.call(e) }
|
796
|
+
m
|
794
797
|
end
|
795
798
|
|
796
799
|
# Add gear to your app:
|
@@ -913,11 +916,10 @@ module Camping
|
|
913
916
|
|
914
917
|
# setup caller data
|
915
918
|
sp = caller[0].split('`')[0].split(":")
|
916
|
-
fl, ln, pr = sp[0], sp[1].to_i, nil
|
917
|
-
# ln = 0
|
919
|
+
fl, ln, pr = sp[0]+' <Cam\ping App> ' , sp[1].to_i, nil
|
918
920
|
|
919
921
|
# Create the app
|
920
|
-
Apps << a = eval(S.gsub(/Camping/,m.to_s), g, fl,
|
922
|
+
Apps << a = eval(S.gsub(/Camping/,m.to_s), g, fl, 1)
|
921
923
|
|
922
924
|
caller[0]=~/:/
|
923
925
|
IO.read(a.set:__FILE__,$`)=~/^__END__/ &&
|
@@ -995,7 +997,7 @@ module Camping
|
|
995
997
|
#
|
996
998
|
# Models cannot be referred from Views at this time.
|
997
999
|
module Models
|
998
|
-
Helpers.
|
1000
|
+
Helpers.include(X, self)
|
999
1001
|
end
|
1000
1002
|
|
1001
1003
|
autoload :Mab, 'camping/mab'
|
data/lib/camping.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "cam\ping/loads";E||="content-type";Z||="text/html"
|
2
2
|
class Object;def meta_def m,&b;(class<<self;self
|
3
|
-
end).
|
3
|
+
end).define_method(m,&b) end;end
|
4
4
|
module Camping;C=self;S=IO.read(__FILE__)rescue nil
|
5
5
|
P="<h1>Cam\ping Problem!</h1><h2>%s</h2>";U=Rack::Utils;Apps=[];SK="camping";G=[]
|
6
6
|
class H<Hash;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m
|
@@ -58,7 +58,7 @@ if c.to_s=="Index";while d[-1]=="/";d.chop! end;u.prepend("/"+d)end;u}
|
|
58
58
|
N=H.new{|_,x|x.downcase}.merge! "N"=>'(\d+)',"X"=>'([^/]+)',"Index"=>''
|
59
59
|
def M p;def M p;end
|
60
60
|
constants.filter{|c|c.to_s!='Camper'}.map{|c|k=const_get(c);
|
61
|
-
k.
|
61
|
+
k.include(C,X,Base,Helpers,Models)
|
62
62
|
@r=[k]+@r if @r-[k]==@r;mu=false;ka=k.ancestors
|
63
63
|
if (k.respond_to?(:urls) && ka[1].respond_to?(:urls)) && (k.urls == ka[1].urls)
|
64
64
|
mu = true unless ka[1].name == nil end
|
@@ -71,16 +71,16 @@ downcase,e;k.new(e,m,prx).service(*a).to_a;rescue;r500(:I,k,m,$!,:env=>e).to_a e
|
|
71
71
|
def method_missing m,c,*a;h=Hash===a[-1]?a.pop : {};e=H[Rack::MockRequest.
|
72
72
|
env_for('',h.delete(:env)||{})];k=X.const_get(c).new(e,m.to_s,prx);h.each{|i,v|
|
73
73
|
k.send"#{i}=",v};k.service(*a)end
|
74
|
-
def use*a,&b;m=a.shift.new(method(:call),*a,&b);meta_def(:call){|e|m.call(e)}end
|
74
|
+
def use*a,&b;m=a.shift.new(method(:call),*a,&b);meta_def(:call){|e|m.call(e)};m;end
|
75
75
|
def pack*a,&b;G<< g=a.shift;include g;g.setup(self,*a,&b)end
|
76
76
|
def gear;G end;def options;O;end;def set k,v;O[k]=v end
|
77
77
|
def goes m,g=TOPLEVEL_BINDING;sp=caller[0].split('`')[0].split(":");fl,ln,pr=
|
78
|
-
sp[0],sp[1].to_i,nil;Apps<< a=eval(S.gsub(/Camping/,m.to_s),g,fl,
|
78
|
+
sp[0]+' <Cam\ping App> ',sp[1].to_i,nil;Apps<< a=eval(S.gsub(/Camping/,m.to_s),g,fl,1);caller[0]=~/:/
|
79
79
|
IO.read(a.set:__FILE__,$`)=~/^__END__/&&(b=$'.split(/^@@\s*(.+?)\s*\r?\n/m)
|
80
80
|
).shift rescue nil;a.set :_t,H[*b||[]]
|
81
81
|
a.set :_meta, H[file: fl, line_number: ln, parent: self,
|
82
82
|
root: (name != "Cam\ping" ? '/' + CampTools.to_snake(name) : '/')];C.configure(a)end end
|
83
83
|
module Views;include X,Helpers end;module Models
|
84
|
-
Helpers.
|
84
|
+
Helpers.include(X,self) end;autoload:Mab,'camping/mab'
|
85
85
|
autoload:Template,'camping/template';pack Gear::Inspection;pack Gear::Filters
|
86
86
|
pack Gear::Nancy;pack Gear::Kuddly;C end
|
data/test/app_logger.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'camping'
|
3
|
+
|
4
|
+
Camping.goes :Loggy
|
5
|
+
|
6
|
+
Loggy.pack Gear::Firewatch
|
7
|
+
|
8
|
+
module Loggy::Controllers
|
9
|
+
|
10
|
+
class Index
|
11
|
+
def get
|
12
|
+
# @env['rack.errors'] = StringIO.new
|
13
|
+
log.debug("Created Logger")
|
14
|
+
log.info("Program Started")
|
15
|
+
log.warn("Nothing to do!")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Loggy::Test < TestCase
|
21
|
+
|
22
|
+
def logs
|
23
|
+
File.read Dir["./**/logs/development.log"].first
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_all
|
27
|
+
`rm -rf logs` if File.exist?('logs/development.log')
|
28
|
+
`rm -rf logs` if File.exist?('logs/formatter.log')
|
29
|
+
`rm -rf logs` if File.exist?('logs/production.log')
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_logging
|
34
|
+
get '/'
|
35
|
+
assert_log "Program Started"
|
36
|
+
assert_log "INFO"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_log_levels
|
40
|
+
get '/'
|
41
|
+
assert(/(INFO).*Program Started$/.match?(logs), "Log level of INFO not found.")
|
42
|
+
assert(/(WARN).*Nothing to do!$/.match?(logs), "Log level of WARN not found.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_log_on_error
|
46
|
+
get '/'
|
47
|
+
assert_raises {
|
48
|
+
raise "[Error]: There was a big error and I don't like it."
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_change_log_location
|
53
|
+
Camping::Firewatch.logger = Dry.Logger(:Camping, template: Camping::Firewatch.default_template).add_backend(stream: "logs/production.log")
|
54
|
+
puts Camping::Firewatch.logger
|
55
|
+
get '/'
|
56
|
+
lags = File.read Dir["./**/logs/production.log"].first
|
57
|
+
assert(/(INFO).*Program Started$/.match?(lags), "Log level of INFO not found.")
|
58
|
+
|
59
|
+
# the end of the test means we set it back.
|
60
|
+
Camping::Firewatch.logger = Dry.Logger(:Camping, template: Camping::Firewatch.default_template).add_backend(stream: "logs/development.log")
|
61
|
+
end
|
62
|
+
|
63
|
+
# def test_changing_loggging_formatter
|
64
|
+
# logger = Dry.Logger(:Camping, formatter: :rack).add_backend(stream: "logs/formatter.log")
|
65
|
+
# get '/'
|
66
|
+
# assert(/(INFO).*Program Started$/.match?(logs), "Log level of INFO not found.")
|
67
|
+
# end
|
68
|
+
|
69
|
+
end
|
data/test/gear/gear_nancy.rb
CHANGED
@@ -53,6 +53,13 @@ module Frank
|
|
53
53
|
"start over?"
|
54
54
|
end
|
55
55
|
|
56
|
+
# Test Controllers too
|
57
|
+
module Controllers
|
58
|
+
get "/even_more" do
|
59
|
+
"I need even more."
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
56
63
|
end
|
57
64
|
|
58
65
|
Camping.goes :Bill
|
@@ -85,7 +92,7 @@ class Frank::Test < TestCase
|
|
85
92
|
|
86
93
|
def test_number_of_controllers
|
87
94
|
controllers = the_controllers
|
88
|
-
assert (controllers.count ==
|
95
|
+
assert (controllers.count == 13), "There are not the right number of controllers: #{controllers.count}."
|
89
96
|
end
|
90
97
|
|
91
98
|
def test_controller_names
|
@@ -103,7 +110,11 @@ class Frank::Test < TestCase
|
|
103
110
|
assert controllers.include?(:PatchThisBoat), "Not Found: :PatchThisBoat. Controllers: #{controllers}."
|
104
111
|
assert controllers.include?(:LinkToThePast), "Not Found: :LinkToThePast. Controllers: #{controllers}."
|
105
112
|
assert controllers.include?(:UnlinkGameOver), "Not Found: :UnlinkGameOver. Controllers: #{controllers}."
|
113
|
+
end
|
106
114
|
|
115
|
+
def test_index_controller_works
|
116
|
+
get '/'
|
117
|
+
assert_body "Hello Friends", "Body is not what we expect."
|
107
118
|
end
|
108
119
|
|
109
120
|
def test_get_works_for_controllers
|
@@ -121,6 +132,11 @@ class Frank::Test < TestCase
|
|
121
132
|
assert_body "It looks like you have lots of friends.", "Well this is a bummer. Frank is left out, and not called."
|
122
133
|
end
|
123
134
|
|
135
|
+
def test_that_using_nancy_in_a_controller_works
|
136
|
+
get '/even_more'
|
137
|
+
assert_body 'I need even more.'
|
138
|
+
end
|
139
|
+
|
124
140
|
# TODO: Test that we are returning proper headers, that are not symbols, When Nancying.
|
125
141
|
def test_that_header_keys_aint_symbols
|
126
142
|
|
data/test/test_helper.rb
CHANGED
@@ -47,9 +47,28 @@ module CommandLineCommands
|
|
47
47
|
|
48
48
|
# deletes the temporary directories found in the /apps directory for reloader testing.
|
49
49
|
def leave_reloader
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
Dir.chdir @original_dir
|
51
|
+
`rm -rf test/apps/reloader/apps` if File.exist?('test/apps/reloader/apps')
|
52
|
+
`rm -rf test/apps/reloader/lib` if File.exist?('test/apps/reloader/lib')
|
53
|
+
end
|
54
|
+
|
55
|
+
# move_to_app
|
56
|
+
# Moves to an app directory,
|
57
|
+
# @app_name: String,
|
58
|
+
def move_to_app(app_name = "")
|
59
|
+
@original_dir = Dir.pwd
|
60
|
+
Dir.chdir "test"
|
61
|
+
Dir.chdir "apps"
|
62
|
+
Dir.chdir directory
|
63
|
+
Dir.mkdir("apps") unless Dir.exist?("apps")
|
64
|
+
Dir.mkdir("lib") unless Dir.exist?("lib")
|
65
|
+
end
|
66
|
+
|
67
|
+
def leave_app(app_name = "", purge_directorys = [])
|
68
|
+
Dir.chdir @original_dir
|
69
|
+
purge_directorys.each do |dir|
|
70
|
+
`rm -rf test/apps/#{app_name}/#{dir}` if File.exist?('test/apps/#{app_name}/#{dir}')
|
71
|
+
end
|
53
72
|
end
|
54
73
|
|
55
74
|
# Moves to the loader directory
|
@@ -87,7 +106,7 @@ module CommandLineCommands
|
|
87
106
|
write 'config.kdl', <<-TXT
|
88
107
|
// config.kdl
|
89
108
|
database {
|
90
|
-
default adapter="sqlite3"
|
109
|
+
default adapter="sqlite3" host="localhost" max_connections=5 timeout=5000
|
91
110
|
development
|
92
111
|
production adapter="postgres" database="kow"
|
93
112
|
}
|
@@ -145,6 +164,11 @@ class TestCase < MiniTest::Test
|
|
145
164
|
end
|
146
165
|
end
|
147
166
|
|
167
|
+
def assert_log(str, message="")
|
168
|
+
logs = File.read Dir["./**/logs/development.log"].first
|
169
|
+
assert(logs.to_s.match?(str), message)
|
170
|
+
end
|
171
|
+
|
148
172
|
def assert_status(code, message="")
|
149
173
|
assert_equal(code, last_response.status, message)
|
150
174
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- why the lucky stiff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mab
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
version: '1.0'
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.0.
|
96
|
+
version: 1.0.4
|
97
97
|
type: :runtime
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -103,7 +103,7 @@ dependencies:
|
|
103
103
|
version: '1.0'
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: 1.0.
|
106
|
+
version: 1.0.4
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
108
|
name: zeitwerk
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- lib/camping/campguide.rb
|
197
197
|
- lib/camping/commands.rb
|
198
198
|
- lib/camping/gear/filters.rb
|
199
|
+
- lib/camping/gear/firewatch.rb
|
199
200
|
- lib/camping/gear/inspection.rb
|
200
201
|
- lib/camping/gear/kuddly.rb
|
201
202
|
- lib/camping/gear/nancy.rb
|
@@ -219,6 +220,7 @@ files:
|
|
219
220
|
- test/app_inception.rb
|
220
221
|
- test/app_inline_templates.rb
|
221
222
|
- test/app_loader.rb
|
223
|
+
- test/app_logger.rb
|
222
224
|
- test/app_markup.rb
|
223
225
|
- test/app_migrations.rb
|
224
226
|
- test/app_partials.rb
|
@@ -230,6 +232,7 @@ files:
|
|
230
232
|
- test/apps/forms.rb
|
231
233
|
- test/apps/forward_to_other_controller.rb
|
232
234
|
- test/apps/loader/apps/donuts.rb
|
235
|
+
- test/apps/loader/apps/donuts/controllers.rb
|
233
236
|
- test/apps/loader/apps/donuts/controllers/index.rb
|
234
237
|
- test/apps/loader/camp.rb
|
235
238
|
- test/apps/migrations.rb
|
@@ -243,7 +246,7 @@ files:
|
|
243
246
|
- test/gear/gear_nancy.rb
|
244
247
|
- test/reload_reloader.rb
|
245
248
|
- test/test_helper.rb
|
246
|
-
homepage: http://
|
249
|
+
homepage: http://rubycamping.org/
|
247
250
|
licenses: []
|
248
251
|
metadata: {}
|
249
252
|
post_install_message:
|
@@ -269,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
272
|
- !ruby/object:Gem::Version
|
270
273
|
version: '0'
|
271
274
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
275
|
+
rubygems_version: 3.5.10
|
273
276
|
signing_key:
|
274
277
|
specification_version: 4
|
275
|
-
summary:
|
278
|
+
summary: miniature rails for anyone
|
276
279
|
test_files: []
|