Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Do I Write An Integration Test For Inquire (Confirm)? #107

Closed
JimLynchCodes opened this issue Mar 20, 2023 · 3 comments
Closed

How Do I Write An Integration Test For Inquire (Confirm)? #107

JimLynchCodes opened this issue Mar 20, 2023 · 3 comments

Comments

@JimLynchCodes
Copy link

JimLynchCodes commented Mar 20, 2023

I have a little cli tool that basically asks the user a yes or no question and then prints a response to the console.

Here is what I currently have:

#[test]
fn always_works() -> Result<(), Box<dyn std::error::Error>> {
    let mut cmd = Command::cargo_bin("mybin")?;
    
    cmd.assert().success();

    Ok(())
}

This always works, and I don't really know how to do any assertions...

Is it possible for me to pass some .arg("--yes") or .arg("--no") that will simulate a user responding to the prompt?

Also, is there any way for me to assert that the proper question, prompt and response text is output in the console?

Thanks! 🙏

@JimLynchCodes JimLynchCodes changed the title How Do I Write An Integration Test For Confirm? How Do I Write An Integration Test For Inquire (Confirm)? Mar 20, 2023
@JimLynchCodes
Copy link
Author

@JimLynchCodes
Copy link
Author

JimLynchCodes commented Mar 23, 2023

I think this issue may be related… not sure how exactly I use this Key struct to simulate hitting the enter key in my test though. 🤔

@mikaelmello
Copy link
Owner

Working on making this possible, tracked on #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants