gopher2000 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/dsl_spec.rb CHANGED
@@ -14,103 +14,112 @@ describe Gopher::DSL do
14
14
 
15
15
  @server = FakeServer.new(@app)
16
16
  @server.send :require, 'gopher2000/dsl'
17
- @server.stub!(: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
- @app.config[:foo].should == '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
- @app.should_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
- @app.should_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
- @app.should_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
- @app.should_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
- @app.should_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
- @app.should_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
- @app.should_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
- @app.scripts.should_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
- @server.should_receive(:set).with(:x, 1)
96
- @server.should_receive(:set).with(:y, 2)
97
- @server.stub!(: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
- @server.should_receive(:watch).with("foo.rb")
105
- @server.should_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
- @server.should_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
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '/spec_helper')
2
2
 
3
3
  describe Gopher::Handlers::DirectoryHandler do
4
4
  before(:each) do
5
- app = mock(Gopher::Application,
5
+ app = double(Gopher::Application,
6
6
  :host => "host",
7
7
  :port => 1234,
8
8
  :config => {})
@@ -13,18 +13,18 @@ describe Gopher::Handlers::DirectoryHandler do
13
13
 
14
14
  describe "filtering" do
15
15
  before(:each) do
16
- File.should_receive(:directory?).with("/tmp/bar/baz").and_return(true)
17
- File.should_receive(:directory?).with("/tmp/bar/baz/a.txt").and_return(false)
18
- File.should_receive(:directory?).with("/tmp/bar/baz/b.exe").and_return(false)
19
- File.should_receive(:directory?).with("/tmp/bar/baz/dir2").and_return(true)
16
+ expect(File).to receive(:directory?).with("/tmp/bar/baz").and_return(true)
17
+ expect(File).to receive(:directory?).with("/tmp/bar/baz/a.txt").and_return(false)
18
+ expect(File).to receive(:directory?).with("/tmp/bar/baz/b.exe").and_return(false)
19
+ expect(File).to receive(:directory?).with("/tmp/bar/baz/dir2").and_return(true)
20
20
 
21
- File.should_receive(:file?).with("/tmp/bar/baz/a.txt").and_return(true)
22
- File.should_receive(:file?).with("/tmp/bar/baz/b.exe").and_return(true)
21
+ expect(File).to receive(:file?).with("/tmp/bar/baz/a.txt").and_return(true)
22
+ expect(File).to receive(:file?).with("/tmp/bar/baz/b.exe").and_return(true)
23
23
 
24
- File.should_receive(:fnmatch).with("*.txt", "/tmp/bar/baz/a.txt").and_return(true)
25
- File.should_receive(:fnmatch).with("*.txt", "/tmp/bar/baz/b.exe").and_return(false)
24
+ expect(File).to receive(:fnmatch).with("*.txt", "/tmp/bar/baz/a.txt").and_return(true)
25
+ expect(File).to receive(:fnmatch).with("*.txt", "/tmp/bar/baz/b.exe").and_return(false)
26
26
 
27
- Dir.should_receive(:glob).with("/tmp/bar/baz/*.*").and_return([
27
+ expect(Dir).to receive(:glob).with("/tmp/bar/baz/*").and_return([
28
28
  "/tmp/bar/baz/a.txt",
29
29
  "/tmp/bar/baz/b.exe",
30
30
  "/tmp/bar/baz/dir2"])
@@ -39,78 +39,78 @@ describe Gopher::Handlers::DirectoryHandler do
39
39
 
40
40
  describe "request_path" do
41
41
  it "should join existing path with incoming path" do
42
- @h.request_path(:splat => "bar/baz").should == "/tmp/bar/baz"
42
+ expect(@h.request_path(:splat => "bar/baz")).to eq("/tmp/bar/baz")
43
43
  end
44
44
  end
45
45
 
46
46
  describe "to_selector" do
47
47
  it "should work" do
48
- @h.to_selector("/tmp/foo/bar.html").should == "/xyz/123/foo/bar.html"
49
- @h.to_selector("/tmp/foo/baz").should == "/xyz/123/foo/baz"
50
- @h.to_selector("/tmp").should == "/xyz/123"
48
+ expect(@h.to_selector("/tmp/foo/bar.html")).to eq("/xyz/123/foo/bar.html")
49
+ expect(@h.to_selector("/tmp/foo/baz")).to eq("/xyz/123/foo/baz")
50
+ expect(@h.to_selector("/tmp")).to eq("/xyz/123")
51
51
  end
52
52
  end
53
53
 
54
54
  describe "contained?" do
55
55
  it "should be false if not under base path" do
56
- @h.contained?("/home/gopher").should == false
56
+ expect(@h.contained?("/home/gopher")).to eq(false)
57
57
  end
58
58
  it "should be true if under base path" do
59
- @h.contained?("/tmp/gopher").should == true
59
+ expect(@h.contained?("/tmp/gopher")).to eq(true)
60
60
  end
61
61
  end
62
62
 
63
63
  describe "safety checks" do
64
64
  it "should raise exception for invalid directory" do
65
- lambda {
66
- @h.call(:splat => "../../../home/foo/bar/baz").to_s.should == "0a\t/tmp/bar/baz/a\thost\t1234"
67
- }.should raise_error(Gopher::InvalidRequest)
65
+ expect {
66
+ expect(@h.call(:splat => "../../../home/foo/bar/baz").to_s).to eq("0a\t/tmp/bar/baz/a\thost\t1234")
67
+ }.to raise_error(Gopher::InvalidRequest)
68
68
  end
69
69
  end
70
70
 
71
71
  describe "directories" do
72
72
  before(:each) do
73
- File.should_receive(:directory?).with("/tmp/bar/baz").and_return(true)
74
- File.should_receive(:directory?).with("/tmp/bar/baz/a").and_return(false)
75
- File.should_receive(:directory?).with("/tmp/bar/baz/dir2").and_return(true)
73
+ expect(File).to receive(:directory?).with("/tmp/bar/baz").and_return(true)
74
+ expect(File).to receive(:directory?).with("/tmp/bar/baz/a").and_return(false)
75
+ expect(File).to receive(:directory?).with("/tmp/bar/baz/dir2").and_return(true)
76
76
 
77
- File.should_receive(:file?).with("/tmp/bar/baz/a").and_return(true)
78
- File.should_receive(:fnmatch).with("*.*", "/tmp/bar/baz/a").and_return(true)
77
+ expect(File).to receive(:file?).with("/tmp/bar/baz/a").and_return(true)
78
+ expect(File).to receive(:fnmatch).with("*.*", "/tmp/bar/baz/a").and_return(true)
79
79
 
80
- Dir.should_receive(:glob).with("/tmp/bar/baz/*.*").and_return([
80
+ expect(Dir).to receive(:glob).with("/tmp/bar/baz/*").and_return([
81
81
  "/tmp/bar/baz/a",
82
82
  "/tmp/bar/baz/dir2"])
83
83
  end
84
84
 
85
85
  it "should work" do
86
- @h.call(:splat => "bar/baz").to_s.should == "iBrowsing: /tmp/bar/baz\tnull\t(FALSE)\t0\r\n0a\t/xyz/123/bar/baz/a\thost\t1234\r\n1dir2\t/xyz/123/bar/baz/dir2\thost\t1234\r\n"
86
+ expect(@h.call(:splat => "bar/baz").to_s).to eq("iBrowsing: /tmp/bar/baz\tnull\t(FALSE)\t0\r\n9a\t/xyz/123/bar/baz/a\thost\t1234\r\n1dir2\t/xyz/123/bar/baz/dir2\thost\t1234\r\n")
87
87
  end
88
88
  end
89
89
 
90
90
  describe "files" do
91
91
  before(:each) do
92
- @file = mock(File)
93
- File.should_receive(:directory?).with("/tmp/baz.txt").and_return(false)
92
+ @file = double(File)
93
+ expect(File).to receive(:directory?).with("/tmp/baz.txt").and_return(false)
94
94
 
95
- File.should_receive(:file?).with("/tmp/baz.txt").and_return(true)
96
- File.should_receive(:new).with("/tmp/baz.txt").and_return(@file)
95
+ expect(File).to receive(:file?).with("/tmp/baz.txt").and_return(true)
96
+ expect(File).to receive(:new).with("/tmp/baz.txt").and_return(@file)
97
97
  end
98
98
 
99
99
  it "should work" do
100
- @h.call(:splat => "baz.txt").should == @file
100
+ expect(@h.call(:splat => "baz.txt")).to eq(@file)
101
101
  end
102
102
  end
103
103
 
104
104
  describe "missing stuff" do
105
105
  before(:each) do
106
- File.should_receive(:directory?).with("/tmp/baz.txt").and_return(false)
107
- File.should_receive(:file?).with("/tmp/baz.txt").and_return(false)
106
+ expect(File).to receive(:directory?).with("/tmp/baz.txt").and_return(false)
107
+ expect(File).to receive(:file?).with("/tmp/baz.txt").and_return(false)
108
108
  end
109
109
 
110
110
  it "should return not found" do
111
- lambda {
111
+ expect {
112
112
  @h.call(:splat => "baz.txt")
113
- }.should raise_error(Gopher::NotFoundError)
113
+ }.to raise_error(Gopher::NotFoundError)
114
114
  end
115
115
  end
116
116
  end
data/spec/helpers_spec.rb CHANGED
@@ -11,6 +11,6 @@ describe Gopher::Application do
11
11
  def foo; "FOO"; end
12
12
  end
13
13
 
14
- @obj.foo.should == "FOO"
14
+ expect(@obj.foo).to eq("FOO")
15
15
  end
16
16
  end
@@ -8,52 +8,71 @@ describe Gopher::Rendering::Base do
8
8
  it 'should add text' do
9
9
  @ctx.text("line 1")
10
10
  @ctx.text("line 2")
11
- @ctx.result.should == "line 1\r\nline 2\r\n"
11
+ expect(@ctx.result).to eq("line 1\r\nline 2\r\n")
12
12
  end
13
-
13
+
14
14
  it "should add breaks correctly" do
15
15
  @ctx.spacing 2
16
16
  @ctx.text("line 1")
17
17
  @ctx.text("line 2")
18
- @ctx.result.should == "line 1\r\n\r\nline 2\r\n\r\n"
18
+ expect(@ctx.result).to eq("line 1\r\n\r\nline 2\r\n\r\n")
19
19
  end
20
20
 
21
+ it "should add extra period to lines beginning with period" do
22
+ @ctx.text("line 1")
23
+ @ctx.text(".")
24
+ @ctx.text("line 2")
25
+ expect(@ctx.result).to eq("line 1\r\n..\r\nline 2\r\n")
26
+ end
27
+
21
28
  it "br outputs a bunch of newlines" do
22
- @ctx.br(2).should == "\r\n\r\n"
29
+ expect(@ctx.br(2)).to eq("\r\n\r\n")
23
30
  end
24
31
 
25
32
  describe "underline" do
26
33
  it "underline outputs a pretty line" do
27
- @ctx.underline(1, 'x').should == "x\r\n"
34
+ expect(@ctx.underline(1, 'x')).to eq("x\r\n")
28
35
  end
29
36
  it "has defaults" do
30
- @ctx.underline.should == "=" * 70 + "\r\n"
37
+ expect(@ctx.underline).to eq("=" * 70 + "\r\n")
38
+ end
39
+ end
40
+
41
+ describe "figlet" do
42
+ it "outputs a figlet" do
43
+ expect(@ctx.figlet('pie')).to eq(" _ \r\n (_) \r\n _ __ _ ___ \r\n | '_ \\| |/ _ \\\r\n | |_) | | __/\r\n | .__/|_|\\___|\r\n | | \r\n |_| \r\n")
31
44
  end
32
45
  end
33
46
 
47
+
34
48
  describe "big_header" do
35
49
  it "outputs a box with text" do
36
50
  @ctx.width(5)
37
- @ctx.big_header('pie').should == "\r\n=====\r\n=pie=\r\n=====\r\n\r\n"
51
+ expect(@ctx.big_header('pie')).to eq("\r\n=====\r\n=pie=\r\n=====\r\n\r\n")
38
52
  end
39
53
  end
40
54
 
41
55
  describe "header" do
42
56
  it "outputs underlined text" do
43
57
  @ctx.width(5)
44
- @ctx.header('pie').should == " pie \r\n=====\r\n"
58
+ expect(@ctx.header('pie')).to eq(" pie \r\n=====\r\n")
45
59
  end
46
60
  end
47
61
 
48
62
  it "uses to_s to output result" do
49
63
  @ctx.text("line 1")
50
- @ctx.to_s.should == @ctx.result
64
+ expect(@ctx.to_s).to eq(@ctx.result)
51
65
  end
52
66
 
53
67
  describe "block" do
54
68
  it "wraps text" do
55
- @ctx.should_receive(:text).twice.with "a"
56
- @ctx.block("a a",1)
69
+ expect(@ctx).to receive(:text).twice.with "a"
70
+ @ctx.block("a a", 1)
71
+ end
72
+
73
+ it "handles stray period" do
74
+ @ctx.block("a a .", 1)
75
+ expect(@ctx.result).to eq("a\r\na\r\n..\r\n")
57
76
  end
58
77
  end
59
78
  end
@@ -12,80 +12,102 @@ describe Gopher::Rendering::Menu do
12
12
 
13
13
  it 'should add text as a gopher line' do
14
14
  @ctx.text("gopher forever")
15
- @ctx.result.should == "igopher forever\tnull\t(FALSE)\t0\r\n"
15
+ expect(@ctx.result).to eq("igopher forever\tnull\t(FALSE)\t0\r\n")
16
16
  end
17
17
 
18
18
  describe "sanitize_text" do
19
19
  it "should remove extra whitespace from end of line" do
20
- @ctx.sanitize_text("x ").should == "x"
20
+ expect(@ctx.sanitize_text("x ")).to eq("x")
21
21
  end
22
22
 
23
23
  it "should convert tabs to spaces" do
24
- @ctx.sanitize_text("x\tx").should == "x x"
24
+ expect(@ctx.sanitize_text("x\tx")).to eq("x x")
25
25
  end
26
26
 
27
27
  it "should remove newlines" do
28
- @ctx.sanitize_text("x\nx").should == "xx"
28
+ expect(@ctx.sanitize_text("x\nx")).to eq("xx")
29
29
  end
30
30
  end
31
31
 
32
32
  describe "line" do
33
33
  it "should work" do
34
- @ctx.line("type", "text", "selector", "host", "port").should == "typetext\tselector\thost\tport\r\n"
34
+ expect(@ctx.line("type", "text", "selector", "host", "port")).to eq("typetext\tselector\thost\tport\r\n")
35
35
  end
36
36
 
37
37
  it "should use application host/port as defaults" do
38
- @ctx.line("type", "text", "selector").should == "typetext\tselector\thost\t1234\r\n"
38
+ expect(@ctx.line("type", "text", "selector")).to eq("typetext\tselector\thost\t1234\r\n")
39
39
  end
40
40
  end
41
41
 
42
42
  describe "error" do
43
43
  it "should call text with right selector" do
44
- @ctx.should_receive(:text).with("foo", '3')
44
+ expect(@ctx).to receive(:text).with("foo", '3')
45
45
  @ctx.error("foo")
46
46
  end
47
47
  end
48
48
 
49
49
  describe "directory" do
50
50
  it "should call link with right selector" do
51
- @ctx.should_receive(:line).with("1", "foo", "/bar/foo", nil, nil)
51
+ expect(@ctx).to receive(:line).with("1", "foo", "/bar/foo", nil, nil)
52
52
  @ctx.directory("foo", "/bar/foo")
53
53
  end
54
54
  end
55
55
 
56
56
  describe "link" do
57
- it "should get type with determine_type" do
58
- @ctx.should_receive(:determine_type).with("foo.txt").and_return("A")
59
- @ctx.link("FILE", "foo.txt").should == "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")
76
+ end
77
+ end
78
+
79
+ describe "http" do
80
+ it "should work" do
81
+ expect(@ctx.http("weblink", "http://google.com")).to eq("hweblink\tURL:http://google.com\thost\t1234\r\n")
60
82
  end
61
83
  end
62
84
 
63
85
  describe "search" do
64
86
  it "should output link type/text" do
65
- @ctx.search("FIND", "search").should == "7FIND\tsearch\thost\t1234\r\n"
87
+ expect(@ctx.search("FIND", "search")).to eq("7FIND\tsearch\thost\t1234\r\n")
66
88
  end
67
89
  end
68
90
 
69
91
  describe "menu" do
70
92
  it "should output link type/text" do
71
- @ctx.menu("MENU ITEM", "item").should == "1MENU ITEM\titem\thost\t1234\r\n"
93
+ expect(@ctx.menu("MENU ITEM", "item")).to eq("1MENU ITEM\titem\thost\t1234\r\n")
72
94
  end
73
95
  end
74
96
 
75
97
  describe "br" do
76
98
  it "should generate an empty text line" do
77
- @ctx.should_receive(:text).with("i", "")
99
+ expect(@ctx).to receive(:text).with("i", "")
78
100
  @ctx.br
79
101
  end
80
102
 
81
103
  it "should call #text multiple times" do
82
- @ctx.should_receive(:text).twice.with("i", "")
104
+ expect(@ctx).to receive(:text).twice.with("i", "")
83
105
  @ctx.br(2)
84
106
  end
85
107
 
86
108
  it "should output an empty menu item" do
87
109
  @ctx.br
88
- @ctx.result.should == "i\tnull\t(FALSE)\t0\r\n"
110
+ expect(@ctx.result).to eq("i\tnull\t(FALSE)\t0\r\n")
89
111
  end
90
112
  end
91
113
 
@@ -99,10 +121,10 @@ describe Gopher::Rendering::Menu do
99
121
  "foo.png" => 'I',
100
122
  "foo.mp3" => 's',
101
123
  "foo.wav" => 's',
102
- "foo.random-file" => "0"
124
+ "foo.random-file" => "9"
103
125
  }.each do |file, expected|
104
126
  it "should have right selector for #{file}" do
105
- @ctx.determine_type(file).should == expected
127
+ expect(@ctx.determine_type(file)).to eq(expected)
106
128
  end
107
129
  end
108
130
  end