Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Fix editor testing with bad parameters
Browse files Browse the repository at this point in the history
Pass the InvalidParameterException up through editor calls so they get
recorded and you do not hit `???` and blow up when checking if the
editor checks parameters.

Fixes #444
  • Loading branch information
David Dooling committed Mar 18, 2017
1 parent ff43fe5 commit 9b15080
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]: https://github.com/atomist/rug/compare/0.15.0...HEAD

### Fixed

- Testing editors no longer crashes when provided invalid
parameters [#444][444]

[444]: https://github.com/atomist/rug/issues/444

## [0.15.0] - 2017-03-17

[0.15.0]: https://github.com/atomist/rug/compare/0.14.0...0.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ProjectScenarioWorld(
case Right(_) =>
// We've already logged it. Do nothing
case Left(ipe: InvalidParametersException) =>
???
throw ipe
case Left(unknown) =>
throw unknown
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class AlpEditorWithParameters implements ProjectEditor {
name: string = "AlpEditorWithParameters"
description: string = "ALP history";

@Parameter({description: "Bold PM", pattern: "^.*$"})
@Parameter({description: "Bold PM", pattern: "^[A-Za-z]*$"})
heir: string;

edit(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Project } from "@atomist/rug/model/Core"
import { ProjectEditor } from "@atomist/rug/operations/ProjectEditor"
import { Given, When, Then, ProjectScenarioWorld } from "@atomist/rug/test/project/Core"

import { AlpEditor } from "../../editors/AlpEditors"

Given("a visionary leader", p => {
p.addFile("Gough", "Maintain the rage");
})
When("politics takes its course", (p, w) => {
let world = w as ProjectScenarioWorld;
world.editWith(world.editor("AlpEditorWithParameters"), {heir: "Malcolm0Fraser"});
});
Then("the rage has a name", p => {
let name = p.name();
return name != null && name != "" && name.length > 0;
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ class GherkinRunnerAgainstProjectTest extends FlatSpec with Matchers {
assert(el.scCount == 0)
}

it should "handle an editor test checking for an invalid parameter" in {
val el = new TestExecutionListener
val as = SimpleFileBasedArtifactSource(
alpEditorsFile,
EditorBadParameterFeatureFile,
EditorWithBadParametersStepsFile
)
val cas = TypeScriptBuilder.compileWithModel(as)
val grt = new GherkinRunner(new JavaScriptContext(cas), Option(RugArchiveReader.find(cas)), Seq(el))
val run = grt.execute()
assert(run.testCount > 0)
assert(run.result === Passed)
}

it should "test a reviewer" in {
val as =
SimpleFileBasedArtifactSource(
Expand Down Expand Up @@ -164,19 +178,8 @@ class GherkinRunnerAgainstProjectTest extends FlatSpec with Matchers {
val atomistStuff: ArtifactSource =
TestUtils.resourcesInPackage(this).filter(_ => true, f => f.name == "SimpleGeneratorWithParams.ts")
.withPathAbove(".atomist/editors") +
SimpleFileBasedArtifactSource(StringFileArtifact(
".atomist/tests/project/Simple.feature",
"""
|Feature: Generate a new project
| This is a test
| to see whether
| we can test project generators
|
| Scenario: New project should have content from template
| Given an empty project
| When run simple generator
| Then parameters were invalid
|""".stripMargin),
SimpleFileBasedArtifactSource(
GenerationBadParameterFeatureFile,
StringFileArtifact(".atomist/tests/project/GenerationSteps.ts",
generateWithInvalidParameters("SimpleGeneratorWithParams", projectName, Map("text" -> "`Anders Hjelsberg is 1God`")))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ object ProjectTestTargets {
val EditorWithParametersStepsFile = StringFileArtifact(".atomist/test/project/Simple_definitions.ts",
TestUtils.requiredFileInPackage(this, "EditorWithParametersSteps.ts").content)

val EditorWithBadParametersStepsFile = StringFileArtifact(".atomist/test/project/Simple_definitions.ts",
TestUtils.requiredFileInPackage(this, "EditorWithBadParametersSteps.ts").content)

val CorruptionFeature =
"""
|Feature: Look for corrupt politicians
Expand Down Expand Up @@ -81,6 +84,24 @@ object ProjectTestTargets {
|});
|""".stripMargin

val GenerationBadParameterFeature =
"""
|Feature: Generate a new project
| This is a test
| to see whether
| we can test project generators
|
| Scenario: New project should have content from template
| Given an empty project
| When run simple generator
| Then parameters were invalid
|""".stripMargin

val GenerationBadParameterFeatureFile = StringFileArtifact(
".atomist/tests/project/GenerationBadParam.feature",
GenerationBadParameterFeature
)

def generateWithInvalidParameters(gen: String, projectName: String, params: Map[String,String]): String =
s"""
|import { Project } from "@atomist/rug/model/Core"
Expand All @@ -94,4 +115,22 @@ object ProjectTestTargets {
|});
|""".stripMargin

val EditorBadParameterFeature =
"""
|Feature: Australian political history
| This is a test
| to demonstrate that the Gherkin DSL
| is a good fit for Rug BDD testing
|
| Scenario: Australian politics, 1972-1991
| Given an empty project
| Given a visionary leader
| When politics takes its course
| Then parameters were invalid
| Then the rage has a name
""".stripMargin

val EditorBadParameterFeatureFile =
StringFileArtifact(".atomist/tests/project/BadParameter.feature", EditorBadParameterFeature)

}

0 comments on commit 9b15080

Please sign in to comment.