|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +describe HighVoltage::Page do |
| 4 | + it "produces the id for a page" do |
| 5 | + page = page(full_file_path("exists.html.erb")) |
| 6 | + |
| 7 | + expect(page.id).to eq "exists" |
| 8 | + end |
| 9 | + |
| 10 | + it "produces the id for a page in a subdirectory" do |
| 11 | + page = page(full_file_path("dir/nested.html.erb")) |
| 12 | + |
| 13 | + expect(page.id).to eq "dir/nested" |
| 14 | + end |
| 15 | + |
| 16 | + it "is valid for a page" do |
| 17 | + page = page(full_file_path("exists.html.erb")) |
| 18 | + |
| 19 | + expect(page).to be_valid |
| 20 | + end |
| 21 | + |
| 22 | + it "is valid for a page in a subdirectory" do |
| 23 | + page = page(full_file_path("dir/nested.html.erb")) |
| 24 | + |
| 25 | + expect(page).to be_valid |
| 26 | + end |
| 27 | + |
| 28 | + it "is invalid for a directory" do |
| 29 | + page = page(full_file_path("dir")) |
| 30 | + |
| 31 | + expect(page).to_not be_valid |
| 32 | + end |
| 33 | + |
| 34 | + it "is invalid for a partial" do |
| 35 | + page = page(full_file_path("_partial.html.erb")) |
| 36 | + |
| 37 | + expect(page).to_not be_valid |
| 38 | + end |
| 39 | + |
| 40 | + it "is invalid for a non-existent page" do |
| 41 | + page = page(full_file_path("nonexistent.html.erb")) |
| 42 | + |
| 43 | + expect(page).to_not be_valid |
| 44 | + end |
| 45 | + |
| 46 | + it "is invalid for a text page" do |
| 47 | + page = page(full_file_path("text.txt.erb")) |
| 48 | + |
| 49 | + expect(page).to_not be_valid |
| 50 | + end |
| 51 | + |
| 52 | + private |
| 53 | + |
| 54 | + def full_content_path |
| 55 | + HighVoltage.full_path.to_s |
| 56 | + end |
| 57 | + |
| 58 | + def page(file_path) |
| 59 | + HighVoltage::Page.new(full_content_path, file_path) |
| 60 | + end |
| 61 | + |
| 62 | + def full_file_path(file_path) |
| 63 | + "#{full_content_path}#{file_path}" |
| 64 | + end |
| 65 | +end |
0 commit comments