| @@ -113,12 +113,12 @@ class DocsDocTest < MiniTest::Spec · 112 unmodified lines |
| 113 | 113 | end |
| 114 | 114 | end |
| 115 | 115 | |
| 116 | | − describe ".index_page" do |
| 116 | + describe ".store_page" do |
| 117 | 117 | it "builds a page" do |
| 118 | 118 | any_instance_of(doc) do |instance| |
| 119 | 119 | stub(instance).build_page('id') { @called = true; nil } |
| 120 | 120 | end |
| 121 | | − doc.index_page('id') {} |
| 121 | + doc.store_page(store, 'id') {} |
| 122 | 122 | assert @called |
| 123 | 123 | end |
| 124 | 124 | |
| @@ -130,20 +130,23 @@ class DocsDocTest < MiniTest::Spec · 5 unmodified lines |
| 130 | 130 | end |
| 131 | 131 | |
| 132 | 132 | context "and it has :entries" do |
| 133 | | − it "yields the page's :store_path and :output" do |
| 134 | | − doc.index_page('') { |*args| @args = args } |
| 135 | | − assert_equal [page[:store_path], page[:output]], @args |
| 133 | + it "returns true" do |
| 134 | + assert doc.store_page(store, 'id') |
| 136 | 135 | end |
| 137 | 136 | |
| 138 | | − it "returns an EntryIndex" do |
| 139 | | − assert_instance_of Docs::EntryIndex, doc.index_page('') {} |
| 137 | + it "stores a file" do |
| 138 | + mock(store).write(page[:store_path], page[:output]) |
| 139 | + doc.store_page(store, 'id') |
| 140 | 140 | end |
| 141 | 141 | |
| 142 | | − describe "the index" do |
| 143 | | − it "contains the page's entries" do |
| 144 | | − index = doc.index_page('') {} |
| 145 | | − assert_equal page[:entries], index.entries |
| 142 | + it "opens the .path directory before storing the file" do |
| 143 | + stub(doc).path { 'path' } |
| 144 | + stub(store).write { assert false } |
| 145 | + mock(store).open('path') do |_, block| |
| 146 | + stub(store).write |
| 147 | + block.call |
| 146 | 148 | end |
| 149 | + doc.store_page(store, 'id') |
| 147 | 150 | end |
| 148 | 151 | end |
| 149 | 152 | |
| @@ -152,13 +155,13 @@ class DocsDocTest < MiniTest::Spec · 2 unmodified lines |
| 152 | 155 | page[:entries] = [] |
| 153 | 156 | end |
| 154 | 157 | |
| 155 | | − it "doesn't yield" do |
| 156 | | − doc.index_page('') { |*_| @yield = true } |
| 157 | | − refute @yield |
| 158 | + it "returns false" do |
| 159 | + refute doc.store_page(store, 'id') |
| 158 | 160 | end |
| 159 | 161 | |
| 160 | | − it "returns nil" do |
| 161 | | − assert_nil doc.index_page('') {} |
| 162 | + it "doesn't store a file" do |
| 163 | + dont_allow(store).write |
| 164 | + doc.store_page(store, 'id') |
| 162 | 165 | end |
| 163 | 166 | end |
| 164 | 167 | end |
| @@ -170,13 +173,13 @@ class DocsDocTest < MiniTest::Spec · 5 unmodified lines |
| 170 | 173 | end |
| 171 | 174 | end |
| 172 | 175 | |
| 173 | | − it "doesn't yield" do |
| 174 | | − doc.index_page('') { |*_| @yield = true } |
| 175 | | − refute @yield |
| 176 | + it "returns false" do |
| 177 | + refute doc.store_page(store, 'id') |
| 176 | 178 | end |
| 177 | 179 | |
| 178 | | − it "returns nil" do |
| 179 | | − assert_nil doc.index_page('') {} |
| 180 | + it "doesn't store a file" do |
| 181 | + dont_allow(store).write |
| 182 | + doc.store_page(store, 'id') |
| 180 | 183 | end |
| 181 | 184 | end |
| 182 | 185 | end |
| @@ -256,48 +259,6 @@ class DocsDocTest < MiniTest::Spec · 73 unmodified lines |
| 256 | 259 | end |
| 257 | 260 | end |
| 258 | 261 | |
| 259 | | − describe ".store_page" do |
| 260 | | − context "when the page is indexed successfully" do |
| 261 | | − before do |
| 262 | | − stub(doc).index_page('id').yields(page[:store_path], page[:output]) { index } |
| 263 | | − end |
| 264 | | − |
| 265 | | − it "returns true" do |
| 266 | | − assert doc.store_page(store, 'id') |
| 267 | | − end |
| 268 | | − |
| 269 | | − it "stores a file" do |
| 270 | | − mock(store).write(page[:store_path], page[:output]) |
| 271 | | − doc.store_page(store, 'id') |
| 272 | | − end |
| 273 | | − |
| 274 | | − it "opens the .path directory before storing the file" do |
| 275 | | − stub(doc).path { 'path' } |
| 276 | | − stub(store).write { assert false } |
| 277 | | − mock(store).open('path') do |_, block| |
| 278 | | − stub(store).write |
| 279 | | − block.call |
| 280 | | − end |
| 281 | | − doc.store_page(store, 'id') |
| 282 | | − end |
| 283 | | − end |
| 284 | | − |
| 285 | | − context "when the page isn't indexed successfully" do |
| 286 | | − before do |
| 287 | | − stub(doc).index_page('id') { nil } |
| 288 | | − end |
| 289 | | − |
| 290 | | − it "returns false" do |
| 291 | | − refute doc.store_page(store, 'id') |
| 292 | | − end |
| 293 | | − |
| 294 | | − it "doesn't store a file" do |
| 295 | | − dont_allow(store).write |
| 296 | | − doc.store_page(store, 'id') |
| 297 | | − end |
| 298 | | − end |
| 299 | | − end |
| 300 | | − |
| 301 | 262 | describe ".store_pages" do |
| 302 | 263 | context "when pages are indexed successfully" do |
| 303 | 264 | before do |