Skip to content

Commit 3ca2b5a

Browse files
committed
use empty folder; check more details in result #1568
1 parent 3e6b42c commit 3ca2b5a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tests/cli/init.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
1+
use std::fs::read_to_string;
2+
use std::path::PathBuf;
3+
14
use crate::cli::cmd::mdbook_cmd;
25
use crate::dummy_book::DummyBook;
6+
use tempfile::Builder as TempFileBuilder;
37

48
use mdbook::config::Config;
59

610
/// Run `mdbook init` with `--force` to skip the confirmation prompts
711
#[test]
812
fn base_mdbook_init_can_skip_confirmation_prompts() {
9-
let temp = DummyBook::new().build().unwrap();
13+
let temp = TempFileBuilder::new()
14+
.prefix("testbook-")
15+
.tempdir()
16+
.unwrap();
1017

11-
// doesn't exist before
12-
assert!(!temp.path().join("book").exists());
18+
// empty folder
19+
assert_eq!(temp.path().read_dir().unwrap().count(), 0);
1320

1421
let mut cmd = mdbook_cmd();
1522
cmd.args(["init", "--force"]).current_dir(temp.path());
1623
cmd.assert()
1724
.success()
18-
.stdout(predicates::str::contains("\nAll done, no errors...\n"));
25+
.stdout(predicates::str::contains("\nAll done, no errors...\n"))
26+
.stderr(predicates::str::contains(
27+
"Creating a new book with stub content",
28+
));
1929

2030
let config = Config::from_disk(temp.path().join("book.toml")).unwrap();
2131
assert_eq!(config.book.title, None);
32+
assert_eq!(config.book.language, Some(String::from("en")));
33+
assert_eq!(config.book.src, PathBuf::from("src"));
2234

2335
assert!(!temp.path().join(".gitignore").exists());
36+
let summary = read_to_string(temp.path().join("src").join("SUMMARY.md")).unwrap();
37+
assert_eq!(summary, "# Summary\n\n- [Chapter 1](./chapter_1.md)\n");
38+
let chapter_1 = read_to_string(temp.path().join("src").join("chapter_1.md")).unwrap();
39+
assert_eq!(chapter_1, "# Chapter 1\n");
40+
assert!(temp.path().join("book").exists());
2441
}
2542

2643
/// Run `mdbook init` with `--title` without git config.

0 commit comments

Comments
 (0)