Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 286 lines (238 sloc) 10.75 kb
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
1 require 'test/test_helper'
836ce9b dont test Time, test Date
cloudhead authored
2 require 'date'
8505c63 Initial commit to toto.
cloudhead authored
3
81b3826 added lots of tests
cloudhead authored
4 URL = "http://toto.oz"
5 AUTHOR = "toto"
6
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
7 context Toto do
8 setup do
ef1584f fixed bug where single article view didnt call methods, but accessed key...
cloudhead authored
9 @config = Toto::Config.new(:markdown => true, :author => AUTHOR, :url => URL)
81b3826 added lots of tests
cloudhead authored
10 @toto = Rack::MockRequest.new(Toto::Server.new(@config))
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
11 Toto::Paths[:articles] = "test/articles"
12 Toto::Paths[:pages] = "test/templates"
13 Toto::Paths[:templates] = "test/templates"
14 end
15
16 context "GET /" do
17 setup { @toto.get('/') }
18
81b3826 added lots of tests
cloudhead authored
19 asserts("returns a 200") { topic.status }.equals 200
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
20 asserts("body is not empty") { not topic.body.empty? }
81b3826 added lots of tests
cloudhead authored
21 asserts("content type is set properly") { topic.content_type }.equals "text/html"
feca420 tests tests!
cloudhead authored
22 should("include a couple of article") { topic.body }.includes_elements("#articles li", 3)
23 should("include an archive") { topic.body }.includes_elements("#archives li", 2)
24
25 context "with no articles" do
26 setup { Rack::MockRequest.new(Toto::Server.new(@config.merge(:ext => 'oxo'))).get('/') }
27
28 asserts("body is not empty") { not topic.body.empty? }
29 asserts("returns a 200") { topic.status }.equals 200
30 end
0756130 ability to specify a custom to_html function through the :to_html config...
cloudhead authored
31
32 context "with a user-defined to_html" do
33 setup do
34 @config[:to_html] = lambda do |path, page, binding|
35 ERB.new(File.read("#{path}/#{page}.rhtml")).result(binding)
36 end
37 @toto.get('/')
38 end
39
40 asserts("returns a 200") { topic.status }.equals 200
41 asserts("body is not empty") { not topic.body.empty? }
42 asserts("content type is set properly") { topic.content_type }.equals "text/html"
43 should("include a couple of article") { topic.body }.includes_elements("#articles li", 3)
44 should("include an archive") { topic.body }.includes_elements("#archives li", 2)
0393dfd fix Etag test
cloudhead authored
45 asserts("Etag header present") { topic.headers.include? "ETag" }
46 asserts("Etag header has a value") { not topic.headers["ETag"].empty? }
0756130 ability to specify a custom to_html function through the :to_html config...
cloudhead authored
47 end
feca420 tests tests!
cloudhead authored
48 end
49
ba478a5 added support for pages in templates/pages/
cloudhead authored
50 context "GET /about" do
51 setup { @toto.get('/about') }
52 asserts("returns a 200") { topic.status }.equals 200
53 asserts("body is not empty") { not topic.body.empty? }
d0ad213 give access to articles from all pages, through @articles var
cloudhead authored
54 should("have access to @articles") { topic.body }.includes_html("#count" => /5/)
ba478a5 added support for pages in templates/pages/
cloudhead authored
55 end
56
feca420 tests tests!
cloudhead authored
57 context "GET a single article" do
58 setup { @toto.get("/1900/05/17/the-wonderful-wizard-of-oz") }
59 asserts("returns a 200") { topic.status }.equals 200
60 asserts("content type is set properly") { topic.content_type }.equals "text/html"
ef1584f fixed bug where single article view didnt call methods, but accessed key...
cloudhead authored
61 should("contain the article") { topic.body }.includes_html("p" => /<em>Once upon a time<\/em>/)
feca420 tests tests!
cloudhead authored
62 end
63
64 context "GET to the archive" do
65 context "through a year" do
66 setup { @toto.get('/2009') }
67 asserts("returns a 200") { topic.status }.equals 200
68 should("includes the entries for that year") { topic.body }.includes_elements("li.entry", 3)
69 end
70
71 context "through a year & month" do
72 setup { @toto.get('/2009/12') }
73 asserts("returns a 200") { topic.status }.equals 200
74 should("includes the entries for that month") { topic.body }.includes_elements("li.entry", 2)
1abc027 pass the path around, to be able to use it in templates, as @path
cloudhead authored
75 should("includes the year & month") { topic.body }.includes_html("h1" => /2009\/12/)
feca420 tests tests!
cloudhead authored
76 end
77
78 context "through /archive" do
79 setup { @toto.get('/archive') }
80 end
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
81 end
82
211e079 better test for custom error
cloudhead authored
83 context "GET to an unknown route with a custom error" do
84 setup do
85 @config[:error] = lambda {|code| "error: #{code}" }
86 @toto.get('/unknown')
87 end
88
ba478a5 added support for pages in templates/pages/
cloudhead authored
89 should("returns a 404") { topic.status }.equals 404
211e079 better test for custom error
cloudhead authored
90 should("return the custom error") { topic.body }.equals "error: 404"
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
91 end
92
93 context "Request is invalid" do
94 setup { @toto.delete('/invalid') }
95 should("returns a 400") { topic.status }.equals 400
96 end
97
98 context "GET /index.xml (atom feed)" do
99 setup { @toto.get('/index.xml') }
100 asserts("content type is set properly") { topic.content_type }.equals "application/xml"
81b3826 added lots of tests
cloudhead authored
101 asserts("body should be valid xml") { topic.body }.includes_html("feed > entry" => /.+/)
102 asserts("summary shouldn't be empty") { topic.body }.includes_html("summary" => /.{10,}/)
103 end
c8622d5 (test) env
Sven Kräuter authored
104 context "GET /index?param=testparam (get parameter)" do
105 setup { @toto.get('/index?param=testparam') }
106 asserts("returns a 200") { topic.status }.equals 200
107 asserts("content type is set properly") { topic.content_type }.equals "text/html"
108 asserts("contain the env variable") { topic.body }.includes_html("p" => /env passed: true/)
109 asserts("access the http get parameter") { topic.body }.includes_html("p" => /request method type: GET/)
110 asserts("access the http parameter name value pair") { topic.body }.includes_html("p" => /request name value pair: param=testparam/)
111 end
112
113
81b3826 added lots of tests
cloudhead authored
114
95d13f4 support dynamic loading of github READMEs
cloudhead authored
115 context "GET to a repo name" do
116 setup do
791d64e tests for repo stuff
cloudhead authored
117 class Toto::Repo
118 def readme() "#{self[:name]}'s README" end
119 end
120 end
121
122 context "when the repo is in the :repos array" do
123 setup do
124 @config[:github] = {:user => "cloudhead", :repos => ['the-repo']}
125 @toto.get('/the-repo')
126 end
127 should("return the-repo's README") { topic.body }.includes("the-repo's README")
128 end
129
130 context "when the repo is not in the :repos array" do
131 setup do
132 @config[:github] = {:user => "cloudhead", :repos => []}
133 @toto.get('/the-repo')
134 end
135 should("return a 404") { topic.status }.equals 404
95d13f4 support dynamic loading of github READMEs
cloudhead authored
136 end
137 end
138
81b3826 added lots of tests
cloudhead authored
139 context "creating an article" do
140 setup do
141 @config[:markdown] = true
bd349f6 fixed tests to work with new version of riot
cloudhead authored
142 @config[:date] = lambda {|t| "the time is #{t.strftime("%Y/%m/%d %H:%M")}" }
eb1cc4f :summary config *has* to be a hash for now, we dont need the added compl...
cloudhead authored
143 @config[:summary] = {:length => 50}
81b3826 added lots of tests
cloudhead authored
144 end
145
146 context "with the bare essentials" do
147 setup do
148 Toto::Article.new({
149 :title => "Toto & The Wizard of Oz.",
150 :body => "#Chapter I\nhello, *stranger*."
151 }, @config)
152 end
153
154 should("have a title") { topic.title }.equals "Toto & The Wizard of Oz."
155 should("parse the body as markdown") { topic.body }.equals "<h1>Chapter I</h1>\n\n<p>hello, <em>stranger</em>.</p>\n"
156 should("create an appropriate slug") { topic.slug }.equals "toto-and-the-wizard-of-oz"
836ce9b dont test Time, test Date
cloudhead authored
157 should("set the date") { topic.date }.equals "the time is #{Date.today.strftime("%Y/%m/%d %H:%M")}"
81b3826 added lots of tests
cloudhead authored
158 should("create a summary") { topic.summary == topic.body }
159 should("have an author") { topic.author }.equals AUTHOR
836ce9b dont test Time, test Date
cloudhead authored
160 should("have a path") { topic.path }.equals Date.today.strftime("/%Y/%m/%d/toto-and-the-wizard-of-oz/")
161 should("have a url") { topic.url }.equals Date.today.strftime("#{URL}/%Y/%m/%d/toto-and-the-wizard-of-oz/")
81b3826 added lots of tests
cloudhead authored
162 end
163
6521efb user defined summary + delimiter functionality
cloudhead authored
164 context "with a user-defined summary" do
165 setup do
166 Toto::Article.new({
167 :title => "Toto & The Wizard of Oz.",
168 :body => "Well,\nhello ~\n, *stranger*."
169 }, @config.merge(:markdown => false, :summary => {:max => 150, :delim => /~\n/}))
170 end
171
172 should("split the article at the delimiter") { topic.summary }.equals "Well,\nhello"
c109424 fixed delimiter present in body
cloudhead authored
173 should("not have the delimiter in the body") { topic.body !~ /~/ }
6521efb user defined summary + delimiter functionality
cloudhead authored
174 end
175
81b3826 added lots of tests
cloudhead authored
176 context "with everything specified" do
177 setup do
178 Toto::Article.new({
179 :title => "The Wizard of Oz",
180 :body => ("a little bit of text." * 5) + "\n" + "filler" * 10,
181 :date => "19/10/1976",
182 :slug => "wizard-of-oz",
183 :author => "toetoe"
184 }, @config)
185 end
186
187 should("parse the date") { [topic[:date].month, topic[:date].year] }.equals [10, 1976]
188 should("use the slug") { topic.slug }.equals "wizard-of-oz"
189 should("use the author") { topic.author }.equals "toetoe"
190
191 context "and long first paragraph" do
c3c40db added auto ellipsis on summary
cloudhead authored
192 should("create a valid summary") { topic.summary }.equals "<p>" + ("a little bit of text." * 5).chop + "&hellip;</p>\n"
81b3826 added lots of tests
cloudhead authored
193 end
194
195 context "and a short first paragraph" do
196 setup do
197 @config[:markdown] = false
198 Toto::Article.new({:body => "there ain't such thing as a free lunch\n" * 10}, @config)
199 end
200
fccedf9 range doesnt need parens
cloudhead authored
201 should("create a valid summary") { topic.summary.size }.within 75..80
81b3826 added lots of tests
cloudhead authored
202 end
203 end
e6c61c0 @evaryont Add tests for :prefix & :error
evaryont authored
204
205 context "in a subdirectory" do
db06bef @evaryont More tests about subdirectories
evaryont authored
206 context "with implicit leading forward slash" do
207 setup do
208 conf = Toto::Config.new({})
209 conf.set(:prefix, "blog")
210 Toto::Article.new({
211 :title => "Toto & The Wizard of Oz.",
212 :body => "#Chapter I\nhello, *stranger*."
213 }, conf)
214 end
215
216 should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/")
217 end
218
219 context "with explicit leading forward slash" do
220 setup do
221 conf = Toto::Config.new({})
222 conf.set(:prefix, "/blog")
223 Toto::Article.new({
224 :title => "Toto & The Wizard of Oz.",
225 :body => "#Chapter I\nhello, *stranger*."
226 }, conf)
227 end
228
229 should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/")
e6c61c0 @evaryont Add tests for :prefix & :error
evaryont authored
230 end
231
db06bef @evaryont More tests about subdirectories
evaryont authored
232 context "with explicit trailing forward slash" do
233 setup do
234 conf = Toto::Config.new({})
235 conf.set(:prefix, "blog/")
236 Toto::Article.new({
237 :title => "Toto & The Wizard of Oz.",
238 :body => "#Chapter I\nhello, *stranger*."
239 }, conf)
240 end
241
242 should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/")
243 end
e6c61c0 @evaryont Add tests for :prefix & :error
evaryont authored
244 end
8505c63 Initial commit to toto.
cloudhead authored
245 end
aeef399 when setting a config var to a hash, merge with current value instead of...
cloudhead authored
246
247 context "using Config#set with a hash" do
248 setup do
249 conf = Toto::Config.new({})
250 conf.set(:summary, {:delim => /%/})
251 conf
252 end
253
254 should("set summary[:delim] to /%/") { topic[:summary][:delim].source }.equals "%"
255 should("leave the :max intact") { topic[:summary][:max] }.equals 150
256 end
1c84d4c allow passing a block instead of a lambda to Config#set
cloudhead authored
257
258 context "using Config#set with a block" do
259 setup do
260 conf = Toto::Config.new({})
261 conf.set(:to_html) {|path, p, _| path + p }
262 conf
263 end
264
265 should("set the value to a proc") { topic[:to_html] }.respond_to :call
266 end
3569f97 @evaryont Add Date#iso8601, for the default feed builder
evaryont authored
267
e6c61c0 @evaryont Add tests for :prefix & :error
evaryont authored
268 context "testing individual configuration parameters" do
269 context "generate error pages" do
270 setup do
271 conf = Toto::Config.new({})
272 conf.set(:error) {|code| "error code #{code}" }
273 conf
274 end
275
276 should("create an error page") { topic[:error].call(400) }.equals "error code 400"
277 end
278 end
279
3569f97 @evaryont Add Date#iso8601, for the default feed builder
evaryont authored
280 context "extensions to the core Ruby library" do
281 should("respond to iso8601") { Date.today }.respond_to?(:iso8601)
282 end
8505c63 Initial commit to toto.
cloudhead authored
283 end
75de139 complete refactor & simplification + some riot tests!
cloudhead authored
284
81b3826 added lots of tests
cloudhead authored
285
Something went wrong with that request. Please try again.