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

small fix to match stencil context type #19

Merged
merged 4 commits into from
Feb 16, 2017
Merged

Conversation

djbe
Copy link
Member

@djbe djbe commented Feb 15, 2017

No description provided.

@AliSoftware
Copy link
Contributor

Hello Travis my old friend?! 😒

@@ -8,7 +8,7 @@

import Foundation

public func enrich(context: [AnyHashable: Any], parameters: [String]) throws -> [AnyHashable: Any] {
public func enrich(context: [String: Any], parameters: [String]) throws -> [String: Any] {
var context = context

context["env"] = ProcessInfo().environment
Copy link
Contributor

Choose a reason for hiding this comment

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

Make "env" and "param" constants instead of using magic strings

@@ -8,7 +8,7 @@

import Foundation

public func enrich(context: [AnyHashable: Any], parameters: [String]) throws -> [AnyHashable: Any] {
public func enrich(context: [String: Any], parameters: [String]) throws -> [String: Any] {
Copy link
Contributor

Choose a reason for hiding this comment

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

add env as a parameter to enrich, with default value ProcessInfo().environment, both for testability and in case other apps/clients of the framework want to alter the env before enriching (to hide some sensible env vars for example)

@@ -16,9 +16,9 @@ class ContextTests: XCTestCase {
let result = try! enrich(context: context, parameters: [])
XCTAssertEqual(result.count, 2, "2 items have been added")

guard let env = result["env"] as? [AnyHashable: Any] else { XCTFail("`env` should be a dictionary"); return }
guard let env = result["env"] as? [String: Any] else { XCTFail("`env` should be a dictionary"); return }
Copy link
Contributor

@AliSoftware AliSoftware Feb 15, 2017

Choose a reason for hiding this comment

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

use the new StencilContext.environment constant there (and of course in all the other tests below too)

XCTAssertNotNil(env["PATH"] as? String)
guard let params = result["param"] as? [AnyHashable: Any] else { XCTFail("`param` should be a dictionary"); return }
guard let params = result["param"] as? [String: Any] else { XCTFail("`param` should be a dictionary"); return }
Copy link
Contributor

@AliSoftware AliSoftware Feb 15, 2017

Choose a reason for hiding this comment

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

use the new StencilContext.parameters constant there (and of course in all the other tests below too)

- Parameter parameters: List of strings, will be parsed using the `Parameters.parse(items:)` method
- Parameter environment: Environment variables, defaults to `ProcessInfo().environment`
*/
public func enrich(context: [String: Any], parameters: [String], environment: [String: String] = ProcessInfo().environment) throws -> [String: Any] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have an enum, and because I'm not a fan of top-level functions, maybe it would be nice to move the enrich func as a static func inside enum StencilContext?

@@ -13,38 +13,38 @@ class ContextTests: XCTestCase {
func testEmpty() {
let context = [String: Any]()

let result = try! enrich(context: context, parameters: [])
let result = try! StencilContext.enrich(context: context, parameters: [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we explicitly pass a ["PATH": "foo:bar:baz"] value there for the environment: parameter, so that the unit test is deterministic and not dependent on the shell environment used by the test process? (even if PATH is really likely to be present in any shell environment, at least there it's explicit)?

@AliSoftware AliSoftware added this to the 1.0.0 milestone Feb 15, 2017
@djbe djbe merged commit 5f557d3 into master Feb 16, 2017
@djbe djbe deleted the feature/fix-stupid-mistake branch February 16, 2017 08:33
AliSoftware added a commit that referenced this pull request Feb 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants