-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Spec: add expectations starts_with, ends_with #5881
Conversation
Didn't make my mind up generally but it should be |
src/spec/expectations.cr
Outdated
@@ -200,6 +200,42 @@ module Spec | |||
end | |||
end | |||
|
|||
# :nodoc: | |||
struct StartsWithExpectation(T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StartsWithExpectation
-> StartWithExpectation
src/spec/expectations.cr
Outdated
end | ||
|
||
def failure_message(actual_value) | ||
"Expected: #{actual_value.inspect}\nto start_with: #{@expected_value.inspect}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_with
-> start with
6aafa2a
to
458bf8b
Compare
src/spec/expectations.cr
Outdated
@@ -266,6 +302,18 @@ module Spec | |||
Spec::ContainExpectation.new(expected) | |||
end | |||
|
|||
# Creates an `Expectation` that passes if actual start_with *expected* (`.starts_with?`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"starts with expected (.starts_with?
)"
src/spec/expectations.cr
Outdated
Spec::StartWithExpectation.new(expected) | ||
end | ||
|
||
# Creates an `Expectation` that passes if actual end_with *expected* (`.ends_with?`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
I'm a bit wary about having a "slippery slope" towards duplicating all collection/string methods as spec expectations, we shouldn't have too many. |
there is not so many, for strings useful only contain, start_with, end_with and match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @kostya here, starts_with?
, ends_with?
and match
(for which we already have a matcher) are very common operations in tests. It's not that bad to add just this one spec matcher.
@kostya By the way, |
i not found in string_spec where to replace it. |
@asterite These are specs explicitly for |
Okay... I don't see it as that terrible, but it's also not strictly necessary. |
So we just need the approval of @RX14 |
* Spec: add expectations starts_with, ends_with * fix
i need this many times.