//! 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")); }