| @@ -17,10 +17,6 @@ class DocsDocTest < MiniTest::Spec · 16 unmodified lines |
| 17 | 17 | Docs::Entry.new |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | | − let :index do |
| 21 | | − Docs::EntryIndex.new |
| 22 | | − end |
| 23 | | − |
| 24 | 20 | let :store do |
| 25 | 21 | Docs::NullStore.new |
| 26 | 22 | end |
| @@ -184,18 +180,18 @@ class DocsDocTest < MiniTest::Spec · 157 unmodified lines |
| 184 | 180 | end |
| 185 | 181 | end |
| 186 | 182 | |
| 187 | | − describe ".index_pages" do |
| 183 | + describe ".store_pages" do |
| 188 | 184 | it "build the pages" do |
| 189 | 185 | any_instance_of(doc) do |instance| |
| 190 | 186 | stub(instance).build_pages { @called = true } |
| 191 | 187 | end |
| 192 | | − doc.index_pages {} |
| 188 | + doc.store_pages(store) {} |
| 193 | 189 | assert @called |
| 194 | 190 | end |
| 195 | 191 | |
| 196 | 192 | context "when pages are built successfully" do |
| 197 | 193 | let :pages do |
| 198 | | − [page, page.dup] |
| 194 | + [page.dup, page.dup] |
| 199 | 195 | end |
| 200 | 196 | |
| 201 | 197 | before do |
| @@ -204,39 +200,51 @@ class DocsDocTest < MiniTest::Spec · 2 unmodified lines |
| 204 | 200 | end |
| 205 | 201 | end |
| 206 | 202 | |
| 207 | | − it "yields pages that have :entries" do |
| 208 | | − doc.index_pages { |*args| (@args ||= []) << args } |
| 209 | | − assert_equal pages.length, @args.length |
| 210 | | − assert_equal [page[:store_path], page[:output]], @args.first |
| 211 | | − end |
| 203 | + context "and at least one page has :entries" do |
| 204 | + it "returns true" do |
| 205 | + assert doc.store_pages(store) |
| 206 | + end |
| 212 | 207 | |
| 213 | | − it "doesn't yield pages that don't have :entries" do |
| 214 | | − pages.first[:entries] = [] |
| 215 | | − doc.index_pages { |*args| (@args ||= []) << args } |
| 216 | | − assert_equal pages.length - 1, @args.length |
| 217 | | − end |
| 208 | + it "stores a file for each page that has :entries" do |
| 209 | + pages.first.merge!(entries: [], output: '') |
| 210 | + mock(store).write(page[:store_path], page[:output]) |
| 211 | + mock(store).write('index.json', anything) |
| 212 | + doc.store_pages(store) |
| 213 | + end |
| 218 | 214 | |
| 219 | | − describe "and at least one has :entries" do |
| 220 | | − it "returns an EntryIndex" do |
| 221 | | − assert_instance_of Docs::EntryIndex, doc.index_pages {} |
| 215 | + it "stores an index that contains all the pages' entries" do |
| 216 | + stub(store).write(page[:store_path], page[:output]) |
| 217 | + mock(store).write('index.json', anything) do |path, json| |
| 218 | + json = JSON.parse(json) |
| 219 | + assert_equal pages.length, json['entries'].length |
| 220 | + assert_includes json['entries'], entry.as_json.stringify_keys |
| 221 | + end |
| 222 | + doc.store_pages(store) |
| 222 | 223 | end |
| 223 | 224 | |
| 224 | | − describe "the index" do |
| 225 | | − it "contains all the pages' entries" do |
| 226 | | − index = doc.index_pages {} |
| 227 | | − assert_equal pages.length, index.entries.length |
| 228 | | − assert_includes index.entries, entry |
| 225 | + it "replaces the .path directory before storing the files" do |
| 226 | + stub(doc).path { 'path' } |
| 227 | + stub(store).write { assert false } |
| 228 | + mock(store).replace('path') do |_, block| |
| 229 | + stub(store).write |
| 230 | + block.call |
| 229 | 231 | end |
| 232 | + doc.store_pages(store) |
| 230 | 233 | end |
| 231 | 234 | end |
| 232 | 235 | |
| 233 | | − context "and none have :entries" do |
| 236 | + context "and no pages have :entries" do |
| 234 | 237 | before do |
| 235 | 238 | pages.each { |page| page[:entries] = [] } |
| 236 | 239 | end |
| 237 | 240 | |
| 238 | | − it "returns nil" do |
| 239 | | − assert_nil doc.index_pages {} |
| 241 | + it "returns false" do |
| 242 | + refute doc.store_pages(store) |
| 243 | + end |
| 244 | + |
| 245 | + it "doesn't store files" do |
| 246 | + dont_allow(store).write |
| 247 | + doc.store_pages(store) |
| 240 | 248 | end |
| 241 | 249 | end |
| 242 | 250 | end |
| @@ -248,57 +256,6 @@ class DocsDocTest < MiniTest::Spec · 5 unmodified lines |
| 248 | 256 | end |
| 249 | 257 | end |
| 250 | 258 | |
| 251 | | − it "doesn't yield" do |
| 252 | | − doc.index_pages { |*_| @yield = true } |
| 253 | | − refute @yield |
| 254 | | − end |
| 255 | | − |
| 256 | | − it "returns nil" do |
| 257 | | − assert_nil doc.index_pages {} |
| 258 | | − end |
| 259 | | − end |
| 260 | | − end |
| 261 | | − |
| 262 | | − describe ".store_pages" do |
| 263 | | − context "when pages are indexed successfully" do |
| 264 | | − before do |
| 265 | | − stub(store).write |
| 266 | | − stub(doc).index_pages do |block| |
| 267 | | − 2.times { block.call page[:store_path], page[:output] } |
| 268 | | − index |
| 269 | | − end |
| 270 | | − end |
| 271 | | − |
| 272 | | − it "returns true" do |
| 273 | | − assert doc.store_pages(store) |
| 274 | | − end |
| 275 | | − |
| 276 | | − it "stores a file for each page" do |
| 277 | | − 2.times { mock(store).write(page[:store_path], page[:output]) } |
| 278 | | − doc.store_pages(store) |
| 279 | | − end |
| 280 | | − |
| 281 | | − it "stores the index" do |
| 282 | | − mock(store).write('index.json', index.to_json) |
| 283 | | − doc.store_pages(store) |
| 284 | | − end |
| 285 | | − |
| 286 | | − it "replaces the .path directory before storing the files" do |
| 287 | | − stub(doc).path { 'path' } |
| 288 | | − stub(store).write { assert false } |
| 289 | | − mock(store).replace('path') do |_, block| |
| 290 | | − stub(store).write |
| 291 | | − block.call |
| 292 | | − end |
| 293 | | − doc.store_pages(store) |
| 294 | | − end |
| 295 | | − end |
| 296 | | − |
| 297 | | − context "when no pages are indexed successfully" do |
| 298 | | − before do |
| 299 | | − stub(doc).index_pages { nil } |
| 300 | | − end |
| 301 | | − |
| 302 | 259 | it "returns false" do |
| 303 | 260 | refute doc.store_pages(store) |
| 304 | 261 | end |