Skip to content

Commit 03c7768

Browse files
Add test for init to verify prompt responses work
1 parent 9d4a38c commit 03c7768

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/testsuite/init.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ src = "src"
101101
assert!(!test.dir.join(".gitignore").exists());
102102
}
103103

104+
// Run `mdbook init` and provide responses to the prompts to create a `.gitignore` file and set a book title.
105+
#[test]
106+
fn init_with_prompts() {
107+
let mut test = BookTest::empty();
108+
test.run("init", |cmd| {
109+
cmd.stdin("y\nMy Book Title\n")
110+
.expect_stdout(str![[r#"
111+
112+
Do you want a .gitignore to be created? (y/n)
113+
What title would you like to give the book?
114+
115+
All done, no errors...
116+
117+
"#]])
118+
.expect_stderr(str![[r#"
119+
[TIMESTAMP] [INFO] (mdbook::book::init): Creating a new book with stub content
120+
121+
"#]]);
122+
})
123+
.check_file(
124+
"book.toml",
125+
str![[r#"
126+
[book]
127+
authors = []
128+
language = "en"
129+
src = "src"
130+
title = "My Book Title"
131+
132+
"#]],
133+
);
134+
assert!(test.dir.join(".gitignore").exists());
135+
}
136+
104137
// Run `mdbook init` with `--title` without git config.
105138
//
106139
// Regression test for https://github.com/rust-lang/mdBook/issues/2485

0 commit comments

Comments
 (0)