sinatra-pages 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/spec/pages_spec.rb +78 -22
  2. metadata +1 -1
data/spec/pages_spec.rb CHANGED
@@ -10,7 +10,14 @@ describe Sinatra::Pages do
10
10
  PAGES = ['Home', 'Generic', 'Generic Test', 'Another Generic Test', 'Not Found']
11
11
 
12
12
  file_of = ->(page){page.downcase.gsub ' ', '_'}
13
- create_file_for = ->(page){File.open("views/#{file_of.(page)}.haml", 'w'){|file| file << page}}
13
+ separate = ->(text){text.chomp.split("\n")}
14
+ create_file_for = ->(page, content=[]) do
15
+ File.open("views/#{file_of.(page)}.haml", 'w') do |file|
16
+ content.empty? ? file << page :
17
+ content.each{|line| file.puts line}
18
+ end
19
+ end
20
+
14
21
 
15
22
  before :all do
16
23
  FileUtils.mkdir 'views'
@@ -18,35 +25,84 @@ describe Sinatra::Pages do
18
25
  end
19
26
 
20
27
  context "when using the HTTP GET request method" do
21
- it "should render the Home page if the given route is either empty or root." do
22
- File.exist?("views/#{file_of.('Home')}.haml").should be_true
23
-
24
- ['/', ''].each do |route|
25
- get route
28
+ context "and there is no Layout file" do
29
+ it "should render the Layout and Home page if the given route is either empty or root." do
30
+ File.exist?("views/#{file_of.('Home')}.haml").should be_true
26
31
 
27
- last_response.should be_ok
28
- last_response.body.chomp.should == 'Home'
32
+ ['/', ''].each do |route|
33
+ get route
34
+
35
+ last_response.should be_ok
36
+ last_response.body.chomp.should == 'Home'
37
+ end
29
38
  end
30
- end
31
-
32
- it "should render an existing page if the given route match the '/:page' pattern." do
33
- PAGES.each do |page|
34
- File.exist?("views/#{file_of.(page)}.haml").should be_true
35
39
 
36
- get "/#{file_of.(page)}"
37
-
38
- last_response.should be_ok
39
- last_response.body.chomp.should == page
40
+ it "should render the Layout and an existing page if the given route match the '/:page' pattern." do
41
+ PAGES.each do |page|
42
+ File.exist?("views/#{file_of.(page)}.haml").should be_true
43
+
44
+ get "/#{file_of.(page)}"
45
+
46
+ last_response.should be_ok
47
+ last_response.body.chomp.should == page
48
+ end
49
+ end
50
+
51
+ it "should render the Layout and the Not Found page if a given route can't find its static page on 'views/'." do
52
+ File.exist?("views/#{file_of.('Do Not Exist')}.haml").should be_false
53
+
54
+ get "/#{file_of.('Do Not Exist')}"
55
+
56
+ last_response.should be_not_found
57
+ last_response.body.chomp.should == 'Not Found'
40
58
  end
41
59
  end
42
60
 
43
- it "should render the Not Found page if the given route can't find its static page on the 'views' directory." do
44
- File.exist?("views/#{file_of.('Do Not Exist')}.haml").should be_false
61
+ context "and there is a Layout file" do
62
+ before :all do
63
+ create_file_for.('Layout', ['Layout', '= yield'])
64
+ end
65
+
66
+ it "should render the Layout and Home page if the given route is either empty or root." do
67
+ File.exist?("views/#{file_of.('Layout')}.haml").should be_true
68
+ File.exist?("views/#{file_of.('Home')}.haml").should be_true
69
+
70
+ ['/', ''].each do |route|
71
+ get route
72
+
73
+ last_response.should be_ok
74
+ separate.(last_response.body).first.should == 'Layout'
75
+ separate.(last_response.body).last.should == 'Home'
76
+ end
77
+ end
78
+
79
+ it "should render the Layout and an existing page if the given route match the '/:page' pattern." do
80
+ PAGES.each do |page|
81
+ File.exist?("views/#{file_of.('Layout')}.haml").should be_true
82
+ File.exist?("views/#{file_of.(page)}.haml").should be_true
83
+
84
+ get "/#{file_of.(page)}"
45
85
 
46
- get "/#{file_of.('Do Not Exist')}"
86
+ last_response.should be_ok
87
+ separate.(last_response.body).first.should == 'Layout'
88
+ separate.(last_response.body).last.should == page
89
+ end
90
+ end
91
+
92
+ it "should render the Layout and the Not Found page if a given route can't find its static page on 'views/'." do
93
+ File.exist?("views/#{file_of.('Layout')}.haml").should be_true
94
+ File.exist?("views/#{file_of.('Do Not Exist')}.haml").should be_false
95
+
96
+ get "/#{file_of.('Do Not Exist')}"
97
+
98
+ last_response.should be_not_found
99
+ separate.(last_response.body).first.should == 'Layout'
100
+ separate.(last_response.body).last.should == 'Not Found'
101
+ end
47
102
 
48
- last_response.should be_not_found
49
- last_response.body.chomp.should == 'Not Found'
103
+ after :all do
104
+ FileUtils.rm 'views/layout.haml'
105
+ end
50
106
  end
51
107
  end
52
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julio Javier Cicchelli