|
| 1 | +use std::fs::read_to_string; |
| 2 | +use std::path::PathBuf; |
| 3 | + |
1 | 4 | use crate::cli::cmd::mdbook_cmd;
|
2 | 5 | use crate::dummy_book::DummyBook;
|
| 6 | +use tempfile::Builder as TempFileBuilder; |
3 | 7 |
|
4 | 8 | use mdbook::config::Config;
|
5 | 9 |
|
6 | 10 | /// Run `mdbook init` with `--force` to skip the confirmation prompts
|
7 | 11 | #[test]
|
8 | 12 | 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(); |
10 | 17 |
|
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); |
13 | 20 |
|
14 | 21 | let mut cmd = mdbook_cmd();
|
15 | 22 | cmd.args(["init", "--force"]).current_dir(temp.path());
|
16 | 23 | cmd.assert()
|
17 | 24 | .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 | + )); |
19 | 29 |
|
20 | 30 | let config = Config::from_disk(temp.path().join("book.toml")).unwrap();
|
21 | 31 | 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")); |
22 | 34 |
|
23 | 35 | 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()); |
24 | 41 | }
|
25 | 42 |
|
26 | 43 | /// Run `mdbook init` with `--title` without git config.
|
|
0 commit comments