gopher2000 0.5.3 → 0.5.4

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: 6c507fab7aaa1412d98ac4a18870fe786098aa9aa4e393bd1204cc476f111dfb
4
- data.tar.gz: e767f8ea12042fc19a7c6f6fc25766b3d91838f053abf1abe97b17b8c99da4e5
3
+ metadata.gz: febb4c0d9036ca121d7ee16c85346ee7afa10ad7f09158d3b6c6c823d1256256
4
+ data.tar.gz: abfa74d3dd3742bc383a176770e0c68d24ec9ec458a0b0806a288fee7f096480
5
5
  SHA512:
6
- metadata.gz: 3497713e468d3d6eefecafcb68cc7421c8af9db40bcd0e30c865f54e1a8a0e8ab0a8098fa8f5369a518cf4dfd391612ba3ada0d4a4ba51b17240934fa500275d
7
- data.tar.gz: 89145000523a7d3d7c77ebad777a0421211b05edfe973c4bc3cbe45ea37d2541bfd773be0ed2c86cf114a0a6c47c1fa6a8e64b2ab76e9a8d278423d5b19cb80b
6
+ metadata.gz: 971a695d248ddad837c5e7ff17d36d70696729ea383842d09fa289e1d20516e75b7b5c2f40727bd45b28224b3c540af4e3c0e7bf90fb389522f616c792e7db84
7
+ data.tar.gz: b0290447843496e4cf77e435f523804824be33728ba45cc236465737f574f2e443a2cd8796dc2e01170b311ea91687e6a882a8e5b19dfda8edfc043ecc6ee80d
@@ -31,7 +31,7 @@ params = {
31
31
 
32
32
  opts.on('-d', '--debug', "run in debug mode") { params[:debug] = true }
33
33
  opts.on('-p port', 'set the port (default is 70)') { |val| params[:port] = Integer(val) }
34
- opts.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| params[host] = val }
34
+ opts.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| params[:host] = val }
35
35
  opts.on('-e env', 'set the environment (default is development)') { |val| params[:env] = val.to_sym }
36
36
 
37
37
  opts.on_tail("-h", "--help", "Show this message") do
@@ -54,6 +54,13 @@ module Gopher
54
54
  config[:port] ||= 70
55
55
  end
56
56
 
57
+ #
58
+ # return the application environment
59
+ #
60
+ def env
61
+ config[:env] ||= 'development'
62
+ end
63
+
57
64
  #
58
65
  # are we in debugging mode?
59
66
  #
@@ -8,9 +8,9 @@ module Gopher
8
8
 
9
9
  def initialize(raw, ip_addr=nil)
10
10
  @selector, @input = raw.chomp.split("\t")
11
-
12
- @selector = Gopher::Application.sanitize_selector(@selector)
13
- @ip_address = ip_addr
11
+
12
+ @selector = Gopher::Application.sanitize_selector(@selector)
13
+ @ip_address = ip_addr
14
14
  end
15
15
 
16
16
  # confirm that this is actually a valid gopher request
@@ -13,7 +13,7 @@ module Gopher
13
13
  def initialize(a)
14
14
  @app = a
15
15
  end
16
-
16
+
17
17
  #
18
18
  # @return [String] name of the host specified in our config
19
19
  #
@@ -28,6 +28,13 @@ module Gopher
28
28
  @app.config[:port] ||= 70
29
29
  end
30
30
 
31
+ #
32
+ # @return [String] environment specified in config
33
+ #
34
+ def env
35
+ @app.config[:env] || 'development'
36
+ end
37
+
31
38
  #
32
39
  # main app loop. called via at_exit block defined in DSL
33
40
  #
@@ -77,8 +84,8 @@ module Gopher
77
84
  require 'optparse'
78
85
  OptionParser.new { |op|
79
86
  op.on('-p port', 'set the port (default is 70)') { |val| set :port, Integer(val) }
80
- op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
81
- op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
87
+ op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :host, val }
88
+ op.on('-e env', 'set the environment (default is development)') { |val| set :env, val.to_sym }
82
89
  }.parse!(ARGV.dup)
83
90
  end
84
91
  end
@@ -1,4 +1,4 @@
1
1
  module Gopher
2
2
  # current version of the app
3
- VERSION = "0.5.3"
3
+ VERSION = "0.5.4"
4
4
  end
@@ -14,103 +14,112 @@ describe Gopher::DSL do
14
14
 
15
15
  @server = FakeServer.new(@app)
16
16
  @server.send :require, 'gopher2000/dsl'
17
- allow(@server).to receive(:application).and_return(@app)
18
- @app.reset!
19
17
  end
20
18
 
21
-
22
- describe "set" do
23
- it "should set a config var" do
24
- @server.set :foo, 'bar'
25
- expect(@app.config[:foo]).to eq('bar')
19
+ describe "application" do
20
+ it "should return a Gopher::Application" do
21
+ expect(@server.application).to be_a(Gopher::Application)
26
22
  end
27
23
  end
28
24
 
29
- describe "route" do
30
- it "should pass a lookup and block to the app" do
31
- expect(@app).to receive(:route).with('/foo')
32
- @server.route '/foo' do
33
- "hi"
25
+ context "with application" do
26
+ before do
27
+ allow(@server).to receive(:application).and_return(@app)
28
+ @app.reset!
29
+ end
30
+
31
+ describe "set" do
32
+ it "should set a config var" do
33
+ @server.set :foo, 'bar'
34
+ expect(@app.config[:foo]).to eq('bar')
34
35
  end
35
36
  end
36
- end
37
37
 
38
- describe "default_route" do
39
- it "should pass a default block to the app" do
40
- expect(@app).to receive(:default_route)
41
- @server.default_route do
42
- "hi"
38
+ describe "route" do
39
+ it "should pass a lookup and block to the app" do
40
+ expect(@app).to receive(:route).with('/foo')
41
+ @server.route '/foo' do
42
+ "hi"
43
+ end
43
44
  end
44
45
  end
45
- end
46
46
 
47
- describe "mount" do
48
- it "should pass a route, path, and some opts to the app" do
49
- expect(@app).to receive(:mount).with('/foo', {:path => "/bar"})
50
- @server.mount "/foo" => "/bar"
47
+ describe "default_route" do
48
+ it "should pass a default block to the app" do
49
+ expect(@app).to receive(:default_route)
50
+ @server.default_route do
51
+ "hi"
52
+ end
53
+ end
51
54
  end
52
55
 
53
- it "should pass a route, path, filter, and some opts to the app" do
54
- expect(@app).to receive(:mount).with('/foo', {:path => "/bar", :filter => "*.jpg"})
55
- @server.mount "/foo" => "/bar", :filter => "*.jpg"
56
+ describe "mount" do
57
+ it "should pass a route, path, and some opts to the app" do
58
+ expect(@app).to receive(:mount).with('/foo', {:path => "/bar"})
59
+ @server.mount "/foo" => "/bar"
60
+ end
61
+
62
+ it "should pass a route, path, filter, and some opts to the app" do
63
+ expect(@app).to receive(:mount).with('/foo', {:path => "/bar", :filter => "*.jpg"})
64
+ @server.mount "/foo" => "/bar", :filter => "*.jpg"
65
+ end
56
66
  end
57
- end
58
67
 
59
- describe "menu" do
60
- it "should pass a menu key and block to the app" do
61
- expect(@app).to receive(:menu).with('/foo')
62
- @server.menu '/foo' do
63
- "hi"
68
+ describe "menu" do
69
+ it "should pass a menu key and block to the app" do
70
+ expect(@app).to receive(:menu).with('/foo')
71
+ @server.menu '/foo' do
72
+ "hi"
73
+ end
64
74
  end
65
75
  end
66
- end
67
76
 
68
- describe "text" do
69
- it "should pass a text_template key and block to the app" do
70
- expect(@app).to receive(:text).with('/foo')
71
- @server.text '/foo' do
72
- "hi"
77
+ describe "text" do
78
+ it "should pass a text_template key and block to the app" do
79
+ expect(@app).to receive(:text).with('/foo')
80
+ @server.text '/foo' do
81
+ "hi"
82
+ end
73
83
  end
74
84
  end
75
- end
76
85
 
77
- describe "helpers" do
78
- it "should pass a block to the app" do
79
- expect(@app).to receive(:helpers)
80
- @server.helpers do
81
- "hi"
86
+ describe "helpers" do
87
+ it "should pass a block to the app" do
88
+ expect(@app).to receive(:helpers)
89
+ @server.helpers do
90
+ "hi"
91
+ end
82
92
  end
83
93
  end
84
- end
85
94
 
86
- describe "watch" do
87
- it "should pass a script app for watching" do
88
- expect(@app.scripts).to receive(:<<).with("foo")
89
- @server.watch("foo")
95
+ describe "watch" do
96
+ it "should pass a script app for watching" do
97
+ expect(@app.scripts).to receive(:<<).with("foo")
98
+ @server.watch("foo")
99
+ end
90
100
  end
91
- end
92
101
 
93
- describe "run" do
94
- it "should set any incoming opts" do
95
- expect(@server).to receive(:set).with(:x, 1)
96
- expect(@server).to receive(:set).with(:y, 2)
97
- allow(@server).to receive(:load)
102
+ describe "run" do
103
+ it "should set any incoming opts" do
104
+ expect(@server).to receive(:set).with(:x, 1)
105
+ expect(@server).to receive(:set).with(:y, 2)
106
+ allow(@server).to receive(:load)
98
107
 
99
- @server.run("foo", {:x => 1, :y => 2})
100
- end
108
+ @server.run("foo", {:x => 1, :y => 2})
109
+ end
101
110
 
102
- it "should turn on script watching if in debug mode" do
103
- @app.config[:debug] = true
104
- expect(@server).to receive(:watch).with("foo.rb")
105
- expect(@server).to receive(:load).with("foo.rb")
111
+ it "should turn on script watching if in debug mode" do
112
+ @app.config[:debug] = true
113
+ expect(@server).to receive(:watch).with("foo.rb")
114
+ expect(@server).to receive(:load).with("foo.rb")
106
115
 
107
- @server.run("foo.rb")
108
- end
116
+ @server.run("foo.rb")
117
+ end
109
118
 
110
- it "should load the script" do
111
- expect(@server).to receive(:load).with("foo.rb")
112
- @server.run("foo.rb")
119
+ it "should load the script" do
120
+ expect(@server).to receive(:load).with("foo.rb")
121
+ @server.run("foo.rb")
122
+ end
113
123
  end
114
124
  end
115
-
116
125
  end
@@ -54,9 +54,25 @@ describe Gopher::Rendering::Menu do
54
54
  end
55
55
 
56
56
  describe "link" do
57
- it "should get type with determine_type" do
58
- expect(@ctx).to receive(:determine_type).with("foo.txt").and_return("A")
59
- expect(@ctx.link("FILE", "foo.txt")).to eq("AFILE\tfoo.txt\thost\t1234\r\n")
57
+ context "with filepath" do
58
+ it "should get type with determine_type" do
59
+ expect(@ctx).to receive(:determine_type).with("foo.txt").and_return("A")
60
+ expect(@ctx.link("FILE", "thing", "external-server.com", 70, "foo.txt")).to eq("AFILE\tthing\texternal-server.com\t70\r\n")
61
+ end
62
+ end
63
+
64
+ context "without filepath" do
65
+ it "should get type with determine_type" do
66
+ expect(@ctx).to receive(:determine_type).with("foo.txt").and_return("A")
67
+ expect(@ctx.link("FILE", "foo.txt")).to eq("AFILE\tfoo.txt\thost\t1234\r\n")
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe "text_link" do
74
+ it "should work" do
75
+ expect(@ctx.text_link("text link", "/files/foo.txt")).to eq("0text link\t/files/foo.txt\thost\t1234\r\n")
60
76
  end
61
77
  end
62
78
 
@@ -18,17 +18,33 @@ if ENV["WITH_SERVER_SPECS"].to_i == 1
18
18
 
19
19
  @host = "0.0.0.0"
20
20
  @port = 12345
21
+ @environment = 'test'
21
22
 
22
23
  @application.config[:host] = @host
23
24
  @application.config[:port] = @port
25
+ @application.config[:env] = @environment
24
26
 
25
27
  @request = Gopher::Request.new("foo", "bar")
26
28
 
27
- @response = Gopher::Response.new(@request)
29
+ @response = Gopher::Response.new
28
30
  @response.code = :success
29
31
  @response.body = "hi"
30
32
  end
31
33
 
34
+ it "returns host" do
35
+ @application.config[:host] = 'gopher-site.test'
36
+ expect(@application.host).to eql('gopher-site.test')
37
+ end
38
+
39
+ it "returns port" do
40
+ expect(@application.port).to eql(@port)
41
+ end
42
+
43
+ it "returns environment" do
44
+ expect(@application.env).to eql(@environment)
45
+ end
46
+
47
+
32
48
  it "should work in non-blocking mode" do
33
49
  @application.fake_response = @response
34
50
  allow(@application).to receive(:non_blocking?).and_return(false)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gopher2000
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2020-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec