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

Suggested fix for #1173 with suitable tests #1174

Merged
merged 13 commits into from
Jan 4, 2019
Merged

Conversation

gnuechtel
Copy link
Contributor

Fixes issue #1173 and adds tests for expected step results

Functions/Assertions/Set-TestInconclusive.ps1 Outdated Show resolved Hide resolved
for ($i = 0; $i -lt $gherkin.Results.TestResult.Count; $i++) {
$expectedResult = (Get-ExpectedResult $i)
$result = $gherkin.Results.TestResult[$i]
It "Test result $($i + 1) ('$($result.Name)') should be '$expectedResult'" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike code that generates tests -- it's extremely hard to tell what these tests prove, if anything...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we forgot to add test exclusions to the appveyor build. The style/help/whitespace checks should run only when I try releasing. Can’t check right now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reacting to the other comment :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike code that generates tests -- it's extremely hard to tell what these tests prove, if anything...

You are right.
That code is a little bit too dynamic.
The test logic must be simpler.
I will replace the function by simple hash tables later...

My goal was to create a data-driven test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jaykul I changed test code and think now it is more readable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that looks fine now. Honestly, you could probably shorten it to just count the PassedScenarios, the way the tests at the top of the file do, but I don't mind either way. This is clear and looks correct to me.

@nohwnd
Copy link
Member

nohwnd commented Dec 20, 2018

@cgnuechtel I upgraded your branch to the latest master because I changed how builds are done. It failed on PowerShell 2 because PowerShell 2 does not automatically expand properties on arrays. Calling .Result on an array fails because array does not have a property called Result (unlike in PowerShell 3+, where it looks for .Result on all items in the array). (There is now fail on using PSJob after it was disposed, it happens occasionally, I will be fixing that in a different branch and update this to current master when I am done.)

@gnuechtel
Copy link
Contributor Author

@nohwnd Thanks, but Set-ItResult does not yet have a File parameter!?

- Use failure message of pester result instead of exception message on $Pester.AddTestResult invocation in Invoke-GherkinStep
- Add parameters file, line and line text to Set-ItResult
@nohwnd
Copy link
Member

nohwnd commented Dec 24, 2018

@cgnuechtel I see it builds now, is this still work in progress or done?

@gnuechtel
Copy link
Contributor Author

@nohwnd I am ready here, but please look at Set-ItResult.ps1 as I added some parameters. However, it should be a non-breaking change.

@nohwnd
Copy link
Member

nohwnd commented Dec 28, 2018

@cgnuechtel thanks for the heads up, I think using the Set-ItResult directly was not a good idea (I know I changed your code to do that, so it's my bad.) I will refactor to make it call an internal function that creates the error. The public Set-ItResult should not be able to define anything except for status and reason.

@nohwnd nohwnd self-assigned this Dec 28, 2018
nohwnd and others added 4 commits January 3, 2019 19:04
Conflicts resolved: Functions/Gherkin.ps1
- use $details.Message again
- add some extended tests for Gherkin output
@gnuechtel
Copy link
Contributor Author

@nohwnd Please look on this code. I am not sure, if this change is correct.

I am also not sure if there are missing tests here. The Gherkin tests I have been added check the NUnit XML output and the inconclusive message, but also some error stuff. If this is too confusing, feel free to remove these tests.

@nohwnd
Copy link
Member

nohwnd commented Jan 4, 2019

@cgnuechtel it was the correct change to make I think, but not for the Set-ItResult there when the failure has a known type I want to show a custom message build from the because string. There are no tests for it because it's very close to the output I guess. Now it should be working as expected.

PS C:\projects\pester_main> get-module pester | remove-module ; import-module .\Pester.psd1; describe "a"{ it "b" { set-itresult -inconclusive  }}

Describing a

Hit Line breakpoint on 'C:\projects\pester_main\Functions\Output.ps1:286'

[DBG]: PS C:\projects\pester_main>
  [?] b, is inconclusive 67ms
PS C:\projects\pester_main> get-module pester | remove-module ; import-module .\Pester.psd1; describe "a"{ it "b" { set-itresult -inconclusive -Because "abc" }}

Describing a

[DBG]: PS C:\projects\pester_main>
  [?] b, is inconclusive, because abc 73ms

Hope I did not break anything else.

@nohwnd
Copy link
Member

nohwnd commented Jan 4, 2019

All tests pass, merging, if it does not work we should prove it wrong with broken tests.

@nohwnd nohwnd merged commit e066e07 into pester:master Jan 4, 2019
@gnuechtel gnuechtel deleted the fix-1173 branch January 5, 2019 00:34
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.

3 participants