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

"Should Be" should regard casing when comparing strings #107

Closed
pullrich opened this issue Feb 12, 2014 · 5 comments
Closed

"Should Be" should regard casing when comparing strings #107

pullrich opened this issue Feb 12, 2014 · 5 comments

Comments

@pullrich
Copy link
Contributor

Describe "Wrong behavoir of Should Be" {
  Context 'given a string "t"' {
    It 'should only succeed if the case matches' {
      't' | Should Be 't' # only this should succeed
      't' | Should Be 'T' # this should fail
    }
  }
}

Right now they both succeed.

@nohwnd
Copy link
Member

nohwnd commented Feb 12, 2014

I can see why this bothers you, but I am afraid making this change would brake a lot of tests for a lot of people. String comparisons in PowerShell are case insensitive, unless you use the -c* operators (like -ceq, -cmatch etc.). So assuming the same behaviour for Pester tests seems valid. That said having an option to make the assertion case sensitive is definitely missing. It can see this implemented as another Pester "keyword", the best fit is probably Exactly.

't' | Should Be 't' # pass
'T' | Should Be 't' # pass
't' | Should Be Exactly 'T' # fail
't' | Should Be Exactly 't' # pass

This would work great for string comparisons, but could be a bit confusing when used with another types of input:

1.0 | Should Be 1 # pass
1.0 | Should Be Exactly 1 # pass 

Both tests pass, but the first value doesn't look exactly the same, what is going on?

What do you think?
I also created a discussion thread in the Pester Google discussion group

@nohwnd nohwnd closed this as completed Feb 12, 2014
@nohwnd nohwnd reopened this Feb 12, 2014
@pullrich
Copy link
Contributor Author

I see you point. That was one alternative I was initially searching for in Pester when I first encountered this bahavoir. I emailed Scott about this and he thought it was a regression bug.
A workaround I used was:
't' -ceq 'T' | Should Be $true
But that would mean fighting the test report messages which would become more unclear in regard of what is truly expected.

@nohwnd
Copy link
Member

nohwnd commented Feb 12, 2014

To be frank I am surprised how little the change actually brakes. Only one of the Pester tests failed. But that is of course irrelevant, because the tests other people could have created is what matters here.

@nohwnd
Copy link
Member

nohwnd commented Feb 13, 2014

PR #112 to add this feature for Be, Match and Contain

@nohwnd
Copy link
Member

nohwnd commented Feb 20, 2014

Implemented for Be, Match and Contain. Enjoy!

@nohwnd nohwnd closed this as completed Feb 20, 2014
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