playgroundbook 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +110 -0
- data/Changelog.md +4 -0
- data/Gemfile +10 -9
- data/Gemfile.lock +4 -2
- data/Guardfile +2 -2
- data/Rakefile +3 -3
- data/bin/playgroundbook +9 -7
- data/lib/{playgroundbook_lint → linter}/abstract_linter.rb +2 -2
- data/lib/{playgroundbook_lint → linter}/chapter_linter.rb +4 -4
- data/lib/{playgroundbook_lint → linter}/chapter_manifest_linter.rb +5 -5
- data/lib/{playgroundbook_lint → linter}/contents_linter.rb +3 -3
- data/lib/{playgroundbook_lint → linter}/cutscene_page_linter.rb +2 -2
- data/lib/{playgroundbook_lint → linter}/cutscene_page_manifest_linter.rb +2 -2
- data/lib/{playgroundbook_lint → linter}/manifest_linter.rb +5 -5
- data/lib/{playgroundbook_lint → linter}/page_linter.rb +2 -2
- data/lib/{playgroundbook_lint → linter}/page_manifest_linter.rb +3 -3
- data/lib/{playgroundbook_lint → linter}/playgroundbook_lint.rb +6 -6
- data/lib/{playgroundbook_lint → linter}/root_manifest_linter.rb +9 -9
- data/lib/playgroundbook.rb +8 -7
- data/lib/{playgroundbook_renderer → renderer}/chapter_collator.rb +18 -18
- data/lib/renderer/contents_manifest_generator.rb +35 -0
- data/lib/{playgroundbook_renderer → renderer}/glossary_generator.rb +13 -16
- data/lib/{playgroundbook_renderer → renderer}/page_parser.rb +4 -3
- data/lib/{playgroundbook_renderer → renderer}/page_processor.rb +0 -0
- data/lib/{playgroundbook_renderer → renderer}/page_writer.rb +11 -11
- data/lib/{playgroundbook_renderer → renderer}/playgroundbook_renderer.rb +29 -29
- data/lib/version.rb +1 -1
- data/lib/wrapper/markdown_wrapper.rb +58 -0
- data/playground_book_lint.gemspec +14 -14
- data/spec/fixtures/wrapper/destination/swift_at_artsy_1.swift +199 -0
- data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/Contents.swift +199 -0
- data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/contents.xcplayground +4 -0
- data/spec/fixtures/wrapper/source/swift_at_artsy_1.md +183 -0
- data/spec/{playground_book_lint → linter}/chapter_linter_spec.rb +5 -5
- data/spec/{playground_book_lint → linter}/chapter_manifest_linter_spec.rb +12 -12
- data/spec/{playground_book_lint → linter}/contents_linter_spec.rb +3 -3
- data/spec/{playground_book_lint → linter}/cutscene_page_linter_spec.rb +2 -2
- data/spec/linter/cutscene_page_manifest_linter_spec.rb +63 -0
- data/spec/linter/manfiest_linter_spec.rb +71 -0
- data/spec/{playground_book_lint → linter}/page_linter_spec.rb +4 -4
- data/spec/{playground_book_lint → linter}/page_manifest_linter_spec.rb +13 -13
- data/spec/{playground_book_lint → linter}/playgroundbook_lint_spec.rb +6 -6
- data/spec/linter/root_manifest_linter_spec.rb +35 -0
- data/spec/renderer/chapter_collator_spec.rb +70 -0
- data/spec/renderer/contents_manfiest_generator_spec.rb +41 -0
- data/spec/renderer/glossary_generator_spec.rb +54 -0
- data/spec/{playgroundbook_renderer_spec → renderer}/page_processor_spec.rb +12 -12
- data/spec/{playgroundbook_renderer_spec → renderer}/page_writer_spec.rb +19 -19
- data/spec/renderer/playgroundbook_renderer_spec.rb +122 -0
- data/spec/spec_helper.rb +38 -38
- data/spec/wrapper/markdown_wrapper_spec.rb +33 -0
- metadata +43 -37
- data/lib/playgroundbook_renderer/contents_manifest_generator.rb +0 -35
- data/spec/playground_book_lint/cutscene_page_manifest_linter_spec.rb +0 -63
- data/spec/playground_book_lint/manfiest_linter_spec.rb +0 -71
- data/spec/playground_book_lint/root_manifest_linter_spec.rb +0 -35
- data/spec/playgroundbook_renderer_spec/chapter_collator_spec.rb +0 -70
- data/spec/playgroundbook_renderer_spec/contents_manfiest_generator_spec.rb +0 -41
- data/spec/playgroundbook_renderer_spec/glossary_generator_spec.rb +0 -52
- data/spec/playgroundbook_renderer_spec/playgroundbook_renderer_spec.rb +0 -122
@@ -1,24 +1,24 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe RootManifestLinter do
|
5
5
|
include FakeFS::SpecHelpers
|
6
6
|
let(:chapter_linter) { ChapterLinter.new(chapter_manifest_linter) }
|
7
7
|
let(:chapter_manifest_linter) { double(ChapterManifestLinter) }
|
8
|
-
let
|
8
|
+
let(:chapter_directory_name) { "test_chapter" }
|
9
9
|
|
10
|
-
it
|
10
|
+
it "fails when chapter directory does not exist" do
|
11
11
|
expect { chapter_linter.lint(chapter_directory_name) }.to raise_error(SystemExit)
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it "fails when Pages subdirectory of chapter dir does not exist" do
|
15
15
|
FakeFS do
|
16
16
|
Dir.mkdir(chapter_directory_name)
|
17
17
|
expect { chapter_linter.lint(chapter_directory_name) }.to raise_error(SystemExit)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "calls through to chapter manifest linter" do
|
22
22
|
FakeFS do
|
23
23
|
expect(chapter_manifest_linter).to receive(:lint)
|
24
24
|
FileUtils.mkdir_p("#{chapter_directory_name}/Pages")
|
@@ -1,36 +1,36 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe ChapterManifestLinter do
|
5
5
|
include FakeFS::SpecHelpers
|
6
6
|
let(:chapter_manifest_linter) { ChapterManifestLinter.new(page_linter) }
|
7
7
|
let(:page_linter) { double(PageLinter) }
|
8
|
-
let
|
8
|
+
let(:page_directory_name) { "test.playgroundpage" }
|
9
9
|
|
10
|
-
it
|
10
|
+
it "fails if no Pages defined in Manifest" do
|
11
11
|
FakeFS do
|
12
|
-
plist = {
|
13
|
-
File.open(
|
12
|
+
plist = { "Name" => "Test" }.to_plist
|
13
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
14
14
|
|
15
15
|
expect { chapter_manifest_linter.lint }.to raise_error(SystemExit)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "fails if Pages dir specified in Manifest does not exist" do
|
20
20
|
FakeFS do
|
21
|
-
plist = {
|
22
|
-
File.open(
|
23
|
-
Dir.mkdir(
|
21
|
+
plist = { "Name" => "Test", "Pages" => [page_directory_name] }.to_plist
|
22
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
23
|
+
Dir.mkdir("Pages")
|
24
24
|
|
25
25
|
expect { chapter_manifest_linter.lint }.to raise_error(SystemExit)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "calls through to page linter" do
|
30
30
|
FakeFS do
|
31
31
|
expect(page_linter).to receive(:lint)
|
32
|
-
plist = {
|
33
|
-
File.open(
|
32
|
+
plist = { "Name" => "Test", "Pages" => [page_directory_name] }.to_plist
|
33
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
34
34
|
FileUtils.mkdir_p("Pages/#{page_directory_name}")
|
35
35
|
|
36
36
|
expect { chapter_manifest_linter.lint }.to_not raise_error
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe ContentsLinter do
|
@@ -6,11 +6,11 @@ module Playgroundbook
|
|
6
6
|
let(:contents_linter) { ContentsLinter.new(root_manifest_linter) }
|
7
7
|
let(:root_manifest_linter) { double(RootManifestLinter) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "calls through to root manifest linter" do
|
10
10
|
expect(root_manifest_linter).to receive(:lint)
|
11
11
|
|
12
12
|
FakeFS do
|
13
|
-
Dir.mkdir
|
13
|
+
Dir.mkdir "Contents"
|
14
14
|
contents_linter.lint
|
15
15
|
end
|
16
16
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe CutscenePageLinter do
|
@@ -6,7 +6,7 @@ module Playgroundbook
|
|
6
6
|
let(:cutscene_page_linter) { CutscenePageLinter.new(cutscene_page_manifest_linter) }
|
7
7
|
let(:cutscene_page_manifest_linter) { double(CutscenePageManifestLinter) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "passes through to cutscene_page_manifest_linter" do
|
10
10
|
expect(cutscene_page_manifest_linter).to receive(:lint)
|
11
11
|
expect { cutscene_page_linter.lint }.to_not raise_error
|
12
12
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Playgroundbook
|
4
|
+
describe CutscenePageManifestLinter do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
let(:cutscene_page_manifest_linter) { CutscenePageManifestLinter.new }
|
7
|
+
|
8
|
+
it "given a valid manifest does not fail" do
|
9
|
+
FakeFS do
|
10
|
+
cutscene_reference = "RealFile.html"
|
11
|
+
plist = {
|
12
|
+
"Name" => "Test Page",
|
13
|
+
"CutsceneReference" => cutscene_reference
|
14
|
+
}.to_plist
|
15
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
16
|
+
File.open(cutscene_reference, "w")
|
17
|
+
|
18
|
+
expect { cutscene_page_manifest_linter.lint }.not_to raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "given a cutscene path" do
|
23
|
+
it "fails if the key doesn't exist" do
|
24
|
+
FakeFS do
|
25
|
+
cutscene_reference = "FakeFile.html"
|
26
|
+
plist = {
|
27
|
+
"Name" => "Test Page"
|
28
|
+
}.to_plist
|
29
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
30
|
+
|
31
|
+
expect { cutscene_page_manifest_linter.lint }.to raise_error(SystemExit)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "fails if that file doesn't exist" do
|
36
|
+
FakeFS do
|
37
|
+
cutscene_reference = "FakeFile.html"
|
38
|
+
plist = {
|
39
|
+
"Name" => "Test Page",
|
40
|
+
"CutsceneReference" => cutscene_reference
|
41
|
+
}.to_plist
|
42
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
43
|
+
|
44
|
+
expect { cutscene_page_manifest_linter.lint }.to raise_error(SystemExit)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "fails with a non-HTML file" do
|
49
|
+
FakeFS do
|
50
|
+
cutscene_reference = "RealFile.xml"
|
51
|
+
plist = {
|
52
|
+
"Name" => "Test Page",
|
53
|
+
"CutsceneReference" => cutscene_reference
|
54
|
+
}.to_plist
|
55
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
56
|
+
File.open(cutscene_reference, "w")
|
57
|
+
|
58
|
+
expect { cutscene_page_manifest_linter.lint }.to raise_error(SystemExit)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Playgroundbook
|
4
|
+
describe RootManifestLinter do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
let(:manifest_linter) { ManifestLinter.new }
|
7
|
+
|
8
|
+
it "fails if a Manifest.plist file does not exist" do
|
9
|
+
expect { manifest_linter.lint }.to raise_error(SystemExit)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "fails if the Manifest.plist file does not contain a Name value" do
|
13
|
+
FakeFS do
|
14
|
+
plist = {}.to_plist
|
15
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
16
|
+
|
17
|
+
expect { manifest_linter.lint }.to raise_error(SystemExit)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "succeeds if the Manifest.plist file is well-formed" do
|
22
|
+
FakeFS do
|
23
|
+
plist = { "Name" => "My Test Name" }.to_plist
|
24
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
25
|
+
|
26
|
+
expect { manifest_linter.lint }.to_not raise_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "extracts Manfiest.plist contents from pwd" do
|
31
|
+
FakeFS do
|
32
|
+
contents = { "key" => "value" }
|
33
|
+
File.open("Manifest.plist", "w") { |f| f.write(contents.to_plist) }
|
34
|
+
|
35
|
+
expect(manifest_linter.manifest_plist_contents).to eq(contents)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "key-value checking" do
|
40
|
+
before do
|
41
|
+
end
|
42
|
+
|
43
|
+
it "checks for non-defined keys in manifest" do
|
44
|
+
FakeFS do
|
45
|
+
plist = {}.to_plist
|
46
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
47
|
+
|
48
|
+
expect(manifest_linter.value_defined_in_manifest?("key")).to be_falsy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "checks for nil keys in manifest" do
|
53
|
+
FakeFS do
|
54
|
+
plist = { "key" => nil }.to_plist
|
55
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
56
|
+
|
57
|
+
expect(manifest_linter.value_defined_in_manifest?("key")).to be_falsy
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "checks for empty keys in manifest" do
|
62
|
+
FakeFS do
|
63
|
+
plist = { "key" => "value" }.to_plist
|
64
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
65
|
+
|
66
|
+
expect(manifest_linter.value_defined_in_manifest?("key")).to be_truthy
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe PageLinter do
|
@@ -6,12 +6,12 @@ module Playgroundbook
|
|
6
6
|
let(:page_linter) { PageLinter.new(page_manifest_linter) }
|
7
7
|
let(:page_manifest_linter) { double(PageManifestLinter) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "fails if Contents.swift does not exist" do
|
10
10
|
expect { page_linter.lint }.to raise_error(SystemExit)
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
File.open(ContentsSwiftFileName,
|
13
|
+
it "passes through to page_manifest_linter" do
|
14
|
+
File.open(ContentsSwiftFileName, "w") { |f| f.write("") }
|
15
15
|
expect(page_manifest_linter).to receive(:lint)
|
16
16
|
expect { page_linter.lint }.to_not raise_error
|
17
17
|
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe PageManifestLinter do
|
5
5
|
include FakeFS::SpecHelpers
|
6
6
|
let(:page_manifest_linter) { PageManifestLinter.new }
|
7
7
|
|
8
|
-
it
|
8
|
+
it "given a valid manifest does not fail" do
|
9
9
|
# TODO: We're not checking optional values yet, more tests to come.
|
10
10
|
# See page_manifest_linter.rb and https://github.com/ashfurrow/playground-book-lint/issues/3 for details.
|
11
11
|
|
12
12
|
FakeFS do
|
13
|
-
plist = {
|
14
|
-
File.open(
|
13
|
+
plist = { "Name" => "Test Page" }.to_plist
|
14
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
15
15
|
expect { page_manifest_linter.lint }.to_not raise_error
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
it
|
19
|
+
describe "context given a live view mode" do
|
20
|
+
it "succeeds with valid values" do
|
21
21
|
FakeFS do
|
22
22
|
plist = {
|
23
|
-
|
24
|
-
|
23
|
+
"Name" => "Test Page",
|
24
|
+
"LiveViewMode" => "HiddenByDefault"
|
25
25
|
}.to_plist
|
26
|
-
File.open(
|
26
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
27
27
|
expect { page_manifest_linter.lint }.to_not raise_error
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it "fails with invalid values" do
|
32
32
|
FakeFS do
|
33
33
|
plist = {
|
34
|
-
|
35
|
-
|
34
|
+
"Name" => "Test Page",
|
35
|
+
"LiveViewMode" => "UnsupportedViewMode"
|
36
36
|
}.to_plist
|
37
|
-
File.open(
|
37
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
38
38
|
expect { page_manifest_linter.lint }.to raise_error(SystemExit)
|
39
39
|
end
|
40
40
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
3
|
module Playgroundbook
|
4
4
|
describe Linter do
|
5
5
|
let(:linter) { Linter.new(test_playground_book, contents_linter) }
|
6
6
|
let(:contents_linter) { double(ContentsLinter) }
|
7
7
|
|
8
|
-
it
|
8
|
+
it "initializes correctly" do
|
9
9
|
expect(linter.playground_file_name) == test_playground_book
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it "exits on lint failure" do
|
13
13
|
allow(linter).to receive(:contents_dir_exists?)
|
14
14
|
.and_return(false)
|
15
15
|
|
16
16
|
expect { linter.lint }.to raise_error(SystemExit)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "fails when file does not exist" do
|
20
20
|
allow(linter).to receive(:contents_dir_exists?)
|
21
21
|
.and_return(false)
|
22
22
|
allow(linter).to receive(:fail_lint)
|
23
|
-
.with(
|
23
|
+
.with("No Contents directory")
|
24
24
|
.and_raise(SystemExit)
|
25
25
|
|
26
26
|
expect { linter.lint }.to raise_error(SystemExit)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it "lints" do
|
30
30
|
allow(linter).to receive(:contents_dir_exists?)
|
31
31
|
.and_return(true)
|
32
32
|
allow(contents_linter).to receive(:lint)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Playgroundbook
|
4
|
+
describe RootManifestLinter do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
let(:root_manifest_linter) { RootManifestLinter.new(chapter_linter) }
|
7
|
+
let(:chapter_linter) { double(ChapterLinter) }
|
8
|
+
|
9
|
+
it "fails if Chapters directory does not exist" do
|
10
|
+
expect { root_manifest_linter.lint }.to raise_error(SystemExit)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "fails if manfiest does not include Chapters" do
|
14
|
+
FakeFS do
|
15
|
+
Dir.mkdir("Chapters")
|
16
|
+
plist = { "Name" => "Test" }.to_plist
|
17
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
18
|
+
|
19
|
+
expect { root_manifest_linter.lint }.to raise_error(SystemExit)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "calls through to lint each chapter" do
|
24
|
+
FakeFS do
|
25
|
+
plist = { "Chapters" => ["test_chapter_name"], "Name" => "Test" }.to_plist
|
26
|
+
File.open("Manifest.plist", "w") { |f| f.write(plist) }
|
27
|
+
Dir.mkdir("Chapters")
|
28
|
+
|
29
|
+
expect(chapter_linter).to receive(:lint).with("test_chapter_name")
|
30
|
+
|
31
|
+
expect { root_manifest_linter.lint }.to_not raise_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Playgroundbook
|
4
|
+
describe ChapterCollator do
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
let(:collator) { ChapterCollator.new(page_writer, test_ui) }
|
7
|
+
let(:page_writer) { double(PageWriter) }
|
8
|
+
let(:test_ui) { Cork::Board.new(silent: true) }
|
9
|
+
let(:parsed_chapter) { PageParser.new.parse_chapter_pages(test_chapter_contents) }
|
10
|
+
let(:chapter_name) { "test_chapter" }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(page_writer).to receive(:write_page)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates a chapter manifest" do
|
17
|
+
collator.collate(chapter_name, parsed_chapter, [])
|
18
|
+
|
19
|
+
expect(File.exist?("#{chapter_name}.playgroundchapter/#{ManifestFileName}")).to be_truthy
|
20
|
+
end
|
21
|
+
|
22
|
+
context "the chapter manifest" do
|
23
|
+
before do
|
24
|
+
collator.collate(chapter_name, parsed_chapter, ["UIKit"])
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has the correct name" do
|
28
|
+
expect(get_manifest("#{chapter_name}.playgroundchapter/#{ManifestFileName}")["Name"]).to eq(chapter_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has the correct pages" do
|
32
|
+
expect(get_manifest("#{chapter_name}.playgroundchapter/#{ManifestFileName}")["Pages"]).to eq([
|
33
|
+
"Page 1.playgroundpage",
|
34
|
+
"Page 2.playgroundpage"
|
35
|
+
])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "calls the page_writer for each page" do
|
40
|
+
expect(page_writer).to receive(:write_page).with("Page 1", "Page 1.playgroundpage", [], "str = \"Yo, it's page 1.\"\nsharedFunc()")
|
41
|
+
expect(page_writer).to receive(:write_page).with("Page 2", "Page 2.playgroundpage", [], "str = \"Page 2 awww yeah.\"\nsharedFunc()")
|
42
|
+
|
43
|
+
collator.collate(chapter_name, parsed_chapter, [])
|
44
|
+
end
|
45
|
+
|
46
|
+
it "does not explode if a Source directory already exists" do
|
47
|
+
expect { collator.collate(chapter_name, parsed_chapter, []) }.to_not raise_error
|
48
|
+
end
|
49
|
+
|
50
|
+
context "having colated" do
|
51
|
+
before do
|
52
|
+
collator.collate(chapter_name, parsed_chapter, [])
|
53
|
+
end
|
54
|
+
|
55
|
+
it "creates a Source directory if one does not exist" do
|
56
|
+
expect(Dir.exist?("#{chapter_name}.playgroundchapter/#{SharedSourcesDirectoryName}")).to be_truthy
|
57
|
+
end
|
58
|
+
|
59
|
+
context "Sources folder" do
|
60
|
+
it "has a Preamble.swift file" do
|
61
|
+
expect(File.exist?("#{chapter_name}.playgroundchapter/#{SharedSourcesDirectoryName}/#{PreambleFileName}")).to be_truthy
|
62
|
+
end
|
63
|
+
|
64
|
+
it "has the correct preamble contents" do
|
65
|
+
expect(File.read("#{chapter_name}.playgroundchapter/#{SharedSourcesDirectoryName}/#{PreambleFileName}")).to eq("import UIKit\n\nvar str = \"Hello, playground\"\n\nfunc sharedFunc() {\n print(\"This should be accessible to all pages.\")\n}")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|