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

feat: allow getting the Assert from an AssertError #144

Merged
merged 1 commit into from Oct 20, 2022

Conversation

jbtrystram
Copy link
Contributor

I'm in the process of writing integration tests with this awesome crate :)

My tool is basically a CRUD cli for a distant API, and while writing tests I ran into this problem while testing deletions.
In some cases, i need to check the output of the Assert even if it succeeded when I expected a failure ( but that would work the other way around.

An example : to verify a deletion process you'd do :delete, then read and expect an error :

    Command::cargo_bin("myTool")
        .unwrap()
        .arg("delete")
        .arg("resource")
		.assert()
		.success();

    Command::cargo_bin("myTool")
        .unwrap()
        .arg("read")
        .arg("resource")
		.assert()
		.failure();
}

However in some cases the "read" operation succeed because the resource was not yet deleted by the remote system.
I would need to check, because even if I was expecting a failure, a success might not invalidate the test.
Continuing the above example :

// first assert to delete the resource

// then read back: 

    let read = Command::cargo_bin("myTool")
        .unwrap()
        .arg("read")
        .arg("resource")
		.assert();

match read.try_failure() {
        Ok(assert) => {
				// here we are good but may want to verify a couple of things from the output
            	let output: &assert.get_output().stdout;
        }
        Err(err) => {
            let output: myType = serde_json::from_slice(&err.0.get_output().stdout).unwrap();
            // we check if it was marked for deletion. If so, it's all good.
            assert!(output.metadata.deletion_timestamp.is_some());
        }
    }

I was not sure if a getter method or simply marking the field public was the better choice there.. Let me know what you think.

@jbtrystram
Copy link
Contributor Author

@epage Bumping this. Would you be interested in that change ?

src/assert.rs Outdated Show resolved Hide resolved
@jbtrystram jbtrystram force-pushed the assert_error branch 2 times, most recently from ceb1876 to 36b6080 Compare October 18, 2022 07:27
@epage epage merged commit 7b0b08b into assert-rs:master Oct 20, 2022
@epage
Copy link
Contributor

epage commented Oct 20, 2022

This is now available in v2.0.5

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

Successfully merging this pull request may close these issues.

None yet

2 participants