-
-
Notifications
You must be signed in to change notification settings - Fork 909
Introduce Behavior<Context>
#701
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
Conversation
Sources/Quick/DSL/World+DSL.swift
Outdated
pendingFlags[Filter.pending] = true | ||
self.itBehavesLike(behavior, context: context, flags: pendingFlags, file: file, line: line) | ||
} | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Sources/Quick/DSL/World+DSL.swift
Outdated
let closure = behavior.spec | ||
let group = ExampleGroup(description: behavior.name, flags: flags) | ||
currentExampleGroup.appendExampleGroup(group) | ||
performWithCurrentExampleGroup(group) { |
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Sources/Quick/DSL/DSL.swift
Outdated
@@ -239,3 +251,5 @@ public func fitBehavesLike(_ name: String, flags: FilterFlags = [:], file: Strin | |||
public func fitBehavesLike(_ name: String, flags: FilterFlags = [:], file: String = #file, line: UInt = #line, sharedExampleContext: @escaping SharedExampleContext) { | |||
World.sharedWorld.fitBehavesLike(name, sharedExampleContext: sharedExampleContext, flags: flags, file: file, line: line) | |||
} | |||
|
|||
|
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.
Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
Sources/Quick/DSL/World+DSL.swift
Outdated
pendingFlags[Filter.pending] = true | ||
self.itBehavesLike(behavior, context: context, flags: pendingFlags, file: file, line: line) | ||
} | ||
|
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Sources/Quick/DSL/World+DSL.swift
Outdated
let closure = behavior.spec | ||
let group = ExampleGroup(description: behavior.name, flags: flags) | ||
currentExampleGroup.appendExampleGroup(group) | ||
performWithCurrentExampleGroup(group) { |
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.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
Sources/Quick/DSL/DSL.swift
Outdated
@@ -239,3 +251,5 @@ public func fitBehavesLike(_ name: String, flags: FilterFlags = [:], file: Strin | |||
public func fitBehavesLike(_ name: String, flags: FilterFlags = [:], file: String = #file, line: UInt = #line, sharedExampleContext: @escaping SharedExampleContext) { | |||
World.sharedWorld.fitBehavesLike(name, sharedExampleContext: sharedExampleContext, flags: flags, file: file, line: line) | |||
} | |||
|
|||
|
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.
Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
Generated by 🚫 danger |
Hey @mosamer, Thanks for opening a pull request. I do like the idea a lot. I'm just wondering how it compares to using plain old functions roughly like: func itIsEditible(sut: inout Editble) {
context('behaves like editble') {
it("makes dolphins happy") {
let dolphin = Dolphin(happy: false)
dolphin.eat(sut)
expect(dolphin.isHappy).to(beTruthy())
}
}
}
class MackerelSpec: QuickSpec {
override func spec() {
var mackerel: Mackerel!
beforeEach {
mackerel = Mackerel()
}
itIsEditible(&mackerel)
}
} But I digress, I think this is useful regardless. Although there needs to be tests and documentation before I can merge this PR. |
Add test cases for different versions of `itBehavesLike` func with `Behavior` and context parameters
Thanks @jeffh for your feedback, I think what plain functions are missing is the handling of call sites. Of course this can be added to the function arguments but will be impractical to scale and share same assertions across different files. I think this is probably the reason I have added unit tests and documentation, following those already available for shared examples, but please feel free to let me know if any additional work is needed. |
This is a really awesome improvement! Thanks, @mosamer! ❤️ |
// | ||
// Created by Mostafa Amer on 19.04.17. | ||
// Copyright © 2017 Brian Ivan Gesiak. All rights reserved. | ||
// |
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.
You can remove this header and the ones below. Most of the files in this project don't include header comments.
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.
done 👍
Thanks @mosamer & @modocache! |
This introduces a base generic behavior definition which can be extended with a specified context type.
Currently, shared assertions implementation using "shared examples" suffers from two drawbacks:
QuickConfiguration
subclass. A file that initially intended for configuration how Quick behaves, "shared examples" are added here to allow their discovery during setup time.[String: Any]
, which is string-typed and erase any type information of the context elements.The proposed solution is to introduce
Behavior<Context>
which will address these issues by allowing user to define subclasses for each "shared example" with a specific context type and a similar structure toQuickSpec
The example below demonstrates how it might be used:
Checklist - While not every PR needs it, new features should consider this list: