sinatra-pages 0.2.1 → 0.3.0
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.
- data/lib/sinatra/pages.rb +6 -2
- data/spec/pages_spec.rb +18 -2
- metadata +1 -1
data/lib/sinatra/pages.rb
CHANGED
data/spec/pages_spec.rb
CHANGED
@@ -7,14 +7,19 @@ describe Sinatra::Pages do
|
|
7
7
|
Sinatra::Pages
|
8
8
|
end
|
9
9
|
|
10
|
+
PAGES = ['Home', 'Generic', 'Generic Test', 'Another Generic Test']
|
11
|
+
|
12
|
+
file_of = ->(page){page.downcase.gsub ' ', '_'}
|
13
|
+
create_file_for = ->(page){File.open("views/#{file_of.(page)}.haml", 'w'){|file| file << page}}
|
14
|
+
|
10
15
|
before :all do
|
11
16
|
FileUtils.mkdir 'views'
|
12
|
-
|
17
|
+
PAGES.each{|page| create_file_for.(page)}
|
13
18
|
end
|
14
19
|
|
15
20
|
context "when using the HTTP GET request method" do
|
16
21
|
it "should render the Home page if the given route is either empty or root." do
|
17
|
-
File.exist?(
|
22
|
+
File.exist?("views/#{file_of.('Home')}.haml").should be_true
|
18
23
|
|
19
24
|
['/', ''].each do |route|
|
20
25
|
get route
|
@@ -23,6 +28,17 @@ describe Sinatra::Pages do
|
|
23
28
|
last_response.body.chomp.should == 'Home'
|
24
29
|
end
|
25
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
|
+
|
36
|
+
get "/#{file_of.(page)}"
|
37
|
+
|
38
|
+
last_response.should be_ok
|
39
|
+
last_response.body.chomp.should == page
|
40
|
+
end
|
41
|
+
end
|
26
42
|
end
|
27
43
|
|
28
44
|
after :all do
|