camping 3.1.3 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf72576fffe27b262b298dbd9355a0e801ea962c532a63010e60e72564092c77
4
- data.tar.gz: caa65f8d4585a2b99a6ddbf3699065512b7ffee4f84a6f7a03c31d2871542bd6
3
+ metadata.gz: e8f510e735548917a248d02aec9a7a36f21c3c527919799c23dc32c2c717396d
4
+ data.tar.gz: 2535878776ceb1093fd24b621db216ae5917addd76a9bc0f7f8fff33abc6f4e6
5
5
  SHA512:
6
- metadata.gz: 9094ac07b30d28d2a2e8f955793959142c00db8f1880e60adb2ff02152f0f401b336a7ccb2e5228e396a5fc2f0ead7f78597dadaeca304d3e489f0c74746f28e
7
- data.tar.gz: 1f789d875289e0632734ffb04b4765c454f050fd0efd96f8603a52cde615e452bd5dcc27f6a338a2efe86fa0fef03183f819567785a45208bdf1700aabd2722d
6
+ metadata.gz: 99b49c530feed07ee899e83d1e442b708cb44e383d8e23437896cbeea0ed945b0500edd794bd887b2d59a9be957b13556d61600d6c2d38a0389625dd1b2c6222
7
+ data.tar.gz: 1eb83d984b72e38e5a475555dd80503fbf9dcd2ca43ca6770e1b744f4f41b360698432f08c35162bc4ff422f249813a705f93e0b00a471181ba7e73b9fb74905
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
- ## RDoc
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.
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
33
42
 
43
+ ## RDoc
34
44
  begin
35
45
  gem 'rdoc', '~>3.9.0'
36
46
  rescue LoadError
@@ -82,6 +92,15 @@ Rake::TestTask.new(:configreloader) do |t|
82
92
  t.test_files = FileList['test/config_*.rb']
83
93
  end
84
94
 
95
+ Rake::TestTask.new(:integration) do |t|
96
+ `gem build`
97
+ gem = Dir.glob("camping*.gem").first
98
+ exit if gem == nil
99
+ `cd test/integration`
100
+ t.libs << "/"
101
+ t.test_files = FileList['test/test_*.rb']
102
+ end
103
+
85
104
  ## Diff
86
105
  desc "Compare camping and camping-unabridged"
87
106
  task :diff do
@@ -18,7 +18,7 @@ with the render sentence. The views do not use class.
18
18
  module Nust::Views
19
19
 
20
20
  def post_number
21
- p "you asked the post number @postn"
21
+ p "you asked the post number @post"
22
22
  end
23
23
 
24
24
  end
@@ -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 foward, to be more compact, to be faster, easier, more fun. These are our guiding principals:
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!
@@ -316,10 +316,8 @@ TXT
316
316
  # write a config.kdl
317
317
  def make_configkdl
318
318
  write 'config.kdl', <<-KDL
319
- # config.kdl
320
- hostname {
321
- default "localhost"
322
- }
319
+ // config.kdl
320
+ hostname "localhost"
323
321
  KDL
324
322
  end
325
323
 
@@ -0,0 +1,79 @@
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
+ if logger == nil
34
+ @logger = Camping::Firewatch.default_logger
35
+ else
36
+ @logger = logger
37
+ end
38
+ # @logger = Camping::Firewatch.logger = logger.nil? ? Camping::Firewatch.default_logger : logger
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ module Gear
45
+
46
+ # Fire watch Gear gives us helper methods to access the logger, log stuff,
47
+ # and do other shenanigans
48
+ module Firewatch
49
+
50
+ class << self
51
+
52
+ def included(mod)
53
+ mod::Helpers.include(HelperMethods)
54
+ end
55
+
56
+ # required for compliance reasons
57
+ def setup(app, *a, &block)
58
+ end
59
+
60
+ end
61
+
62
+ module HelperMethods
63
+
64
+ def logger
65
+ Camping::Firewatch.logger
66
+ end
67
+
68
+ # #log A helper method to log stuff.
69
+ # @message: String, Default: nil, An optional value used to directly log
70
+ # rather than requesting the logger
71
+ def log(message = nil)
72
+ return logger unless !message.nil?
73
+ logger.info message
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -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
- m.module_eval(%Q[
77
- module Controllers
78
- class #{cname} < R #{rs}
79
- end
80
- end
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
@@ -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
@@ -13,3 +13,4 @@ require 'camping/gear/filters'
13
13
  require 'camping/gear/nancy'
14
14
  require 'camping/gear/inspection'
15
15
  require 'camping/gear/kuddly'
16
+ require 'camping/gear/firewatch'
@@ -3,6 +3,7 @@ require 'erb'
3
3
  require 'rack'
4
4
  require 'rackup'
5
5
  require 'camping/version'
6
+ require 'camping/gear/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,27 @@ module Camping
103
108
  })
104
109
  end
105
110
 
111
+ # redefine logging middleware
112
+ class << self
113
+ def logging_middleware
114
+ lambda { |server|
115
+ /CGI/.match?(server.server.name) || server.options[:quiet] ? nil : [Camping::Firewatch, $stderr]
116
+ }
117
+ end
118
+ end
119
+
106
120
  def middleware
107
121
  h = super
108
122
  h["development"] << [XSendfile]
123
+ h["deployment"] << [XSendfile]
109
124
  h
110
125
  end
111
126
 
112
- def start
113
-
114
- commands = []
115
- ARGV.each do |cmd|
116
- commands << cmd
117
- end
127
+ # Starts the Camping Server. Camping server inherits from Rack::Server so
128
+ # referencing their documentation would be a good idea.
129
+ # @file: String, file location for a camp.rb file.
130
+ def start(file = nil)
131
+ commands = ARGV
118
132
 
119
133
  # Parse commands
120
134
  case commands[0]
@@ -147,7 +161,7 @@ module Camping
147
161
  else
148
162
  name = server.name[/\w+$/]
149
163
  puts "** Starting #{name} on #{options[:Host]}:#{options[:Port]}"
150
- super
164
+ super()
151
165
  end
152
166
  end
153
167
 
@@ -1,5 +1,5 @@
1
1
  module Camping
2
- VERSION = "3.1.3"
2
+ VERSION = "3.2"
3
3
  def self.version
4
4
  VERSION
5
5
  end
@@ -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).send(:define_method,m,&b)
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
- m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
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.send :include,C,X,Base,Helpers,Models
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
@@ -766,11 +768,11 @@ module Camping
766
768
  # end
767
769
  #
768
770
  # This piece of code feels a bit confusing, but let's walk through it.
769
- # Rack apps all implement a Call method. This is how Rub web servers
770
- # pass call the app, or code that you're set up. In our case, our camping
771
+ # Rack apps all implement a Call method. This is how Ruby web servers
772
+ # call the app, or code that you've set up. In our case, our camping
771
773
  # apps.
772
774
  #
773
- # The Use method is setting up a new middleware, it first shifts the first
775
+ # The Use method is setting up a new middleware, it shifts the first
774
776
  # argument supplied to Use, which should be the Middleware name, then
775
777
  # initializes it. That's your new middleware. Rack based middleware accept
776
778
  # a single argument to their initialize methods, which is an app. Optionally
@@ -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:
@@ -825,6 +828,22 @@ module Camping
825
828
  # end
826
829
  # end
827
830
  #
831
+ # Camping gear can also provide Helper methods to our controllers:
832
+ #
833
+ # module MyGear
834
+ # module HelperMethods
835
+ # # Define Helper Methods here
836
+ # end
837
+ #
838
+ # # This is plumbing in our Gear to add our Helper methods.
839
+ # class << self
840
+ # def included(mod)
841
+ # mod::Helpers.include(HelperMethods)
842
+ # end
843
+ # end
844
+ # end
845
+ #
846
+ # Helper methods are available in our controllers.
828
847
  def pack(*a, &b)
829
848
  G << g = a.shift
830
849
  include g
@@ -865,7 +884,7 @@ module Camping
865
884
  # which enables you to create a Camping-based application within
866
885
  # another module.
867
886
  #
868
- # Here's an example of namespacing your web interface and
887
+ # Here's an example of name spacing your web interface and
869
888
  # code for a worker process together:
870
889
  #
871
890
  # module YourApplication
@@ -913,11 +932,10 @@ module Camping
913
932
 
914
933
  # setup caller data
915
934
  sp = caller[0].split('`')[0].split(":")
916
- fl, ln, pr = sp[0], sp[1].to_i, nil
917
- # ln = 0
935
+ fl, ln, pr = sp[0]+' <Cam\ping App> ' , sp[1].to_i, nil
918
936
 
919
937
  # Create the app
920
- Apps << a = eval(S.gsub(/Camping/,m.to_s), g, fl, ln)
938
+ Apps << a = eval(S.gsub(/Camping/,m.to_s), g, fl, 1)
921
939
 
922
940
  caller[0]=~/:/
923
941
  IO.read(a.set:__FILE__,$`)=~/^__END__/ &&
@@ -995,7 +1013,7 @@ module Camping
995
1013
  #
996
1014
  # Models cannot be referred from Views at this time.
997
1015
  module Models
998
- Helpers.send(:include, X, self)
1016
+ Helpers.include(X, self)
999
1017
  end
1000
1018
 
1001
1019
  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).send:define_method,m,&b end;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.send:include,C,X,Base,Helpers,Models
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,ln);caller[0]=~/:/
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.send:include,X,self end;autoload:Mab,'camping/mab'
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
@@ -0,0 +1,70 @@
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
+ log "what up"
17
+ end
18
+ end
19
+ end
20
+
21
+ class Loggy::Test < TestCase
22
+
23
+ def logs
24
+ File.read Dir["./**/logs/development.log"].first
25
+ end
26
+
27
+ def after_all
28
+ `rm -rf logs` if File.exist?('logs/development.log')
29
+ `rm -rf logs` if File.exist?('logs/formatter.log')
30
+ `rm -rf logs` if File.exist?('logs/production.log')
31
+ super
32
+ end
33
+
34
+ def test_logging
35
+ get '/'
36
+ assert_log "Program Started"
37
+ assert_log "INFO"
38
+ end
39
+
40
+ def test_log_levels
41
+ get '/'
42
+ assert(/(INFO).*Program Started$/.match?(logs), "Log level of INFO not found.")
43
+ assert(/(WARN).*Nothing to do!$/.match?(logs), "Log level of WARN not found.")
44
+ end
45
+
46
+ def test_log_on_error
47
+ get '/'
48
+ assert_raises {
49
+ raise "[Error]: There was a big error and I don't like it."
50
+ }
51
+ end
52
+
53
+ def test_change_log_location
54
+ Camping::Firewatch.logger = Dry.Logger(:Camping, template: Camping::Firewatch::default_template).add_backend(stream: "logs/production.log")
55
+ puts Camping::Firewatch.logger
56
+ get '/'
57
+ lags = File.read Dir["./**/logs/production.log"].first
58
+ assert(/(INFO).*Program Started$/.match?(lags), "Log level of INFO not found.")
59
+
60
+ # the end of the test means we set it back.
61
+ Camping::Firewatch.logger = Dry.Logger(:Camping, template: Camping::Firewatch::default_template).add_backend(stream: "logs/development.log")
62
+ end
63
+
64
+ # def test_changing_loggging_formatter
65
+ # logger = Dry.Logger(:Camping, formatter: :rack).add_backend(stream: "logs/formatter.log")
66
+ # get '/'
67
+ # assert(/(INFO).*Program Started$/.match?(logs), "Log level of INFO not found.")
68
+ # end
69
+
70
+ end
@@ -0,0 +1,10 @@
1
+ module Donuts
2
+ module Controllers
3
+ class Index
4
+ def get
5
+ "hello friends"
6
+ end
7
+ end
8
+
9
+ end
10
+ end
@@ -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 == 12), "There are not the right number of controllers: #{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
- 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')
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" host="localhost" max_connections=5 timeout=5000
109
+ default adapter="sqlite3" host="localhost" max_connections=5 timeout=5000
91
110
  development
92
111
  production adapter="postgres" database="kow"
93
112
  }
@@ -102,7 +121,7 @@ TXT
102
121
 
103
122
  end
104
123
 
105
- class TestCase < MiniTest::Test
124
+ class TestCase < Minitest::Test
106
125
  include Rack::Test::Methods
107
126
  include CommandLineCommands
108
127
  include Minitest::Hooks
@@ -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,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camping
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.2.2
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: 2023-06-24 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 13.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 13.2.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: mab
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,6 +44,20 @@ dependencies:
30
44
  - - ">="
31
45
  - !ruby/object:Gem::Version
32
46
  version: 0.0.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: tilt
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.3.0
33
61
  - !ruby/object:Gem::Dependency
34
62
  name: rack
35
63
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +121,7 @@ dependencies:
93
121
  version: '1.0'
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
- version: 1.0.3
124
+ version: 1.0.5
97
125
  type: :runtime
98
126
  prerelease: false
99
127
  version_requirements: !ruby/object:Gem::Requirement
@@ -103,47 +131,61 @@ dependencies:
103
131
  version: '1.0'
104
132
  - - ">="
105
133
  - !ruby/object:Gem::Version
106
- version: 1.0.3
134
+ version: 1.0.5
107
135
  - !ruby/object:Gem::Dependency
108
136
  name: zeitwerk
109
137
  requirement: !ruby/object:Gem::Requirement
110
138
  requirements:
111
139
  - - "~>"
112
140
  - !ruby/object:Gem::Version
113
- version: 2.6.8
141
+ version: 2.6.15
114
142
  - - ">="
115
143
  - !ruby/object:Gem::Version
116
- version: 2.6.8
144
+ version: 2.6.15
117
145
  type: :runtime
118
146
  prerelease: false
119
147
  version_requirements: !ruby/object:Gem::Requirement
120
148
  requirements:
121
149
  - - "~>"
122
150
  - !ruby/object:Gem::Version
123
- version: 2.6.8
151
+ version: 2.6.15
124
152
  - - ">="
125
153
  - !ruby/object:Gem::Version
126
- version: 2.6.8
154
+ version: 2.6.15
127
155
  - !ruby/object:Gem::Dependency
128
156
  name: listen
129
157
  requirement: !ruby/object:Gem::Requirement
130
158
  requirements:
131
159
  - - "~>"
132
160
  - !ruby/object:Gem::Version
133
- version: 3.8.0
161
+ version: 3.9.0
134
162
  - - ">="
135
163
  - !ruby/object:Gem::Version
136
- version: 3.8.0
164
+ version: 3.9.0
137
165
  type: :runtime
138
166
  prerelease: false
139
167
  version_requirements: !ruby/object:Gem::Requirement
140
168
  requirements:
141
169
  - - "~>"
142
170
  - !ruby/object:Gem::Version
143
- version: 3.8.0
171
+ version: 3.9.0
144
172
  - - ">="
145
173
  - !ruby/object:Gem::Version
146
- version: 3.8.0
174
+ version: 3.9.0
175
+ - !ruby/object:Gem::Dependency
176
+ name: dry-logger
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: 1.0.4
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: 1.0.4
147
189
  description:
148
190
  email: why@ruby-lang.org
149
191
  executables:
@@ -196,6 +238,7 @@ files:
196
238
  - lib/camping/campguide.rb
197
239
  - lib/camping/commands.rb
198
240
  - lib/camping/gear/filters.rb
241
+ - lib/camping/gear/firewatch.rb
199
242
  - lib/camping/gear/inspection.rb
200
243
  - lib/camping/gear/kuddly.rb
201
244
  - lib/camping/gear/nancy.rb
@@ -219,6 +262,7 @@ files:
219
262
  - test/app_inception.rb
220
263
  - test/app_inline_templates.rb
221
264
  - test/app_loader.rb
265
+ - test/app_logger.rb
222
266
  - test/app_markup.rb
223
267
  - test/app_migrations.rb
224
268
  - test/app_partials.rb
@@ -230,6 +274,7 @@ files:
230
274
  - test/apps/forms.rb
231
275
  - test/apps/forward_to_other_controller.rb
232
276
  - test/apps/loader/apps/donuts.rb
277
+ - test/apps/loader/apps/donuts/controllers.rb
233
278
  - test/apps/loader/apps/donuts/controllers/index.rb
234
279
  - test/apps/loader/camp.rb
235
280
  - test/apps/migrations.rb
@@ -243,7 +288,7 @@ files:
243
288
  - test/gear/gear_nancy.rb
244
289
  - test/reload_reloader.rb
245
290
  - test/test_helper.rb
246
- homepage: http://camping.rubyforge.org/
291
+ homepage: http://rubycamping.org/
247
292
  licenses: []
248
293
  metadata: {}
249
294
  post_install_message:
@@ -269,8 +314,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
314
  - !ruby/object:Gem::Version
270
315
  version: '0'
271
316
  requirements: []
272
- rubygems_version: 3.4.12
317
+ rubygems_version: 3.3.9
273
318
  signing_key:
274
319
  specification_version: 4
275
- summary: micro mighty websites for anyone
320
+ summary: miniature rails for anyone
276
321
  test_files: []