-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Pass on values from the pipeline to Assert-Equivalent #51
Comments
You are correct, and even though this module is now maintenance only this feature is super easy to implement so if you’d like to make a PR please go ahead. Otherwise, please check out the port of the module to Pester 6-alpha, where I’ve already fixed this issue for should-beequivalent assertion
Odesláno z aplikace Outlook pro iOS<https://aka.ms/o0ukef>
…________________________________
Od: Ronald Borman ***@***.***>
Odesláno: Saturday, June 15, 2024 12:21:41 PM
Komu: nohwnd/Assert ***@***.***>
Kopie: Subscribed ***@***.***>
Předmět: [nohwnd/Assert] Pass on values from the pipeline to Assert-Equivalent (Issue #51)
Most assertions seem to accept values from the pipeline (based on the examples in the Readme.md of this project).
Using Pester 5.5 and Assert 0.9.6 I tried to change the Assert-Equivalent example (which instead uses a parameter for the actual value) so that the actual value is passed from the pipeline:
Describe 'Assert-Equivalent' {
It 'should use the input from the pipeline' {
$expected = [PSCustomObject]@{
Name = 'Jakub'
Age = 28
Languages = 'Czech', 'English'
}
$actual = [PSCustomObject]@{
Name = 'Jkb'
Languages = 'Czech', 'English', 'German'
}
#$actual | Assert-Equivalent -Actual $actual -Expected $expected
$actual | Assert-Equivalent -Expected $expected
}
}
But instead of the differences in the expected and actual objects I get the following error:
Assert-Equivalent : The input object cannot be bound to any parameters for the command either because
the command does not take pipeline input or the input and its properties do not match any of the par
ameters that take pipeline input.
This also happens when I additionally pass the expected value as a positional parameter:
$actual | Assert-Equivalent $expected
As the example passes the expected value as a named parameter, it suggests it is not possible to pass the actual value from the pipeline. If so, would this be a feature you're willing to consider (preferably with a positional parameter as the expected value)?
—
Reply to this email directly, view it on GitHub<#51> or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABLYLYORSNKEOHOFZVTSSHLZHQITNBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJLJONZXKZNENZQW2ZNLORUHEZLBMRPXI6LQMWBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTLDTOVRGUZLDORPXI6LQMWSUS43TOVS2M5DPOBUWG44SQKSHI6LQMWVHEZLQN5ZWS5DPOJ42K5TBNR2WLKBXHEYDEMZRHA4IFJDUPFYGLJLJONZXKZNFOZQWY5LFVIZDGNJUG4ZDINJWGGTXI4TJM5TWK4VGMNZGKYLUMU>.
You are receiving this email because you are subscribed to this thread.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Although I'm more of an occasional user of PowerShell and don't know all the ins and outs (this would actually be my first PowerShell related PR) I will give it a try.... Looking at the source code of this repository and the should-beequivalent assertion in the Pester repository, will it be enough to change the parameter declaration of the Assert-Equivalent function to the following?
And then add a couple of tests to Assert-Equivalent.Tests.ps1? |
Yeah pretty much, I am not sure right now how we collect the stuff from pipeline and if the equivalency function is using the standard unified way, but shoot me a PR and I can help you fix it.
And dont worry, we all had to start somewhere :)
…________________________________
Od: Ronald Borman ***@***.***>
Odesláno: Saturday, June 15, 2024 1:29:31 PM
Komu: nohwnd/Assert ***@***.***>
Kopie: Comment ***@***.***>; Subscribed ***@***.***>
Předmět: Re: [nohwnd/Assert] Pass on values from the pipeline to Assert-Equivalent (Issue #51)
Although I'm more of an occasional user of PowerShell and don't know all the ins and outs (this would actually be my first PowerShell related PR) I will give it a try....
Looking at the source code of this repository and the should-beequivalent assertion in the Pester repository, will it be enough to change the parameter declaration of the Assert-Equivalent function to the following?
[CmdletBinding()]
param(
[Parameter(Position = 1, ValueFromPipeline = $true)]
$Actual,
[Parameter(Position = 0, Mandatory)]
$Expected,
$Options = (Get-EquivalencyOption),
[Switch] $StrictOrder
)
And then add a couple of tests to Assert-Equivalent.Tests.ps1?
—
Reply to this email directly, view it on GitHub<#51 (comment)> or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABLYLYJXZ3SFDU5P4Z7YTELZHQQRZBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVA3TSMBSGMYTQOECUR2HS4DFUVUXG43VMWSXMYLMOVS2UMRTGU2DOMRUGU3DDJ3UOJUWOZ3FOKTGG4TFMF2GK>.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I've made the PR, but the AppVeyor build seems to have failed. Not sure if I did something wrong. |
You did not, the build upgraded to Pester 6-alpha1 where I used the same names for assertions and so the tests were testing that rather than the assertions coming from Assert. |
PR merged, I will close this issue. Thanks for the learning opportunity. |
Thanks for you contribution :) |
Your further contributions would be welcome on Pester repo :) |
Most assertions seem to accept values from the pipeline (based on the examples in the Readme.md of this project).
Using Pester 5.5 and Assert 0.9.6 I tried to change the Assert-Equivalent example (which instead uses a parameter for the actual value) so that the actual value is passed from the pipeline:
But instead of the differences in the expected and actual objects I get the following error:
This also happens when I additionally pass the expected value as a positional parameter:
$actual | Assert-Equivalent $expected
As the example passes the expected value as a named parameter, it suggests it is not possible to pass the actual value from the pipeline. If so, would this be a feature you're willing to consider (preferably with a positional parameter as the expected value)?
The text was updated successfully, but these errors were encountered: