-
Notifications
You must be signed in to change notification settings - Fork 2
/
integration.rs
53 lines (46 loc) · 1.37 KB
/
integration.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use assert_cmd::Command;
use assert_fs::prelude::*;
use color_eyre::eyre::Result;
use predicates::prelude::*;
#[test]
/// make sure help runs. This indicates the binary works
fn test_help() -> Result<()> {
let mut cmd = Command::cargo_bin("garden")?;
let assert = cmd.arg("--help").assert();
assert.success().stderr("");
Ok(())
}
#[test]
/// make sure we have a write command by running `garden write --help`
fn test_write_help() -> Result<()> {
let mut cmd = Command::cargo_bin("garden")?;
let assert = cmd.arg("write").arg("--help").assert();
assert.success().stderr("");
Ok(())
}
#[test]
fn test_write_with_title() {
let temp_dir = assert_fs::TempDir::new().unwrap();
let mut cmd = Command::cargo_bin("garden").unwrap();
let fake_editor_path = std::env::current_dir()
.expect("expect to be in a dir")
.join("tests")
.join("fake-editor.sh");
if !fake_editor_path.exists() {
panic!(
"fake editor shell script could not be found"
)
}
let assert = cmd
.env("EDITOR", fake_editor_path.into_os_string())
.env("GARDEN_PATH", temp_dir.path())
.arg("write")
.arg("-t")
.arg("atitle")
.write_stdin("N\n".as_bytes())
.assert();
assert.success();
temp_dir
.child("atitle.md")
.assert(predicate::path::exists());
}