aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cli.rs
blob: 4d54a55b075058fb457bae7514357936a268315b (plain)
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
54
55
56
57
58
59
60
61
62
//! Command-line contract. Everything here runs offline: real lookups are
//! tested against the fixtures in the unit tests.

use assert_cmd::Command;
use predicates::prelude::PredicateBooleanExt;
use predicates::str::contains;

fn drae() -> Command {
    let mut c = Command::cargo_bin("drae").unwrap();
    // A separate cache, so the user's is neither touched nor relied upon.
    c.env("XDG_CACHE_HOME", env!("CARGO_TARGET_TMPDIR"));
    c.env("NO_COLOR", "1");
    c
}

#[test]
fn prints_help_without_arguments() {
    drae()
        .assert()
        .success()
        .stdout(contains("Diccionario de la lengua española"))
        .stdout(contains("conjugar"));
}

#[test]
fn reports_its_version() {
    drae()
        .arg("--version")
        .assert()
        .success()
        .stdout(contains(env!("CARGO_PKG_VERSION")));
}

#[test]
fn search_needs_the_cache() {
    drae()
        .args(["buscar", "edificio", "--sin-cache"])
        .assert()
        .failure()
        .stderr(contains("está desactivada"));
}

#[test]
fn cache_commands_work_on_an_empty_cache() {
    drae().args(["cache", "info"]).assert().success();
    drae()
        .args(["cache", "listar"])
        .assert()
        .success()
        .stdout(contains("vacía").or(contains("rae-api")));
}

#[test]
fn definir_exists_for_words_that_clash_with_command_names() {
    // `drae sin` is the synonyms command, so the word «sin» is looked up
    // with `drae definir sin`.
    drae()
        .args(["definir", "--help"])
        .assert()
        .success()
        .stdout(contains("PALABRA"));
}