+
Skip to content

Pass fixture instance into example listeners #264

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

Merged
merged 34 commits into from
Jul 13, 2018
Merged

Conversation

nigelcharman
Copy link
Member

@nigelcharman nigelcharman commented Mar 18, 2018

Please don't merge this PR yet while we look at the impact on existing extensions.

This will impact at least the ScreenshotExtension (which implements Command) and the ParallelRunExtension (which has an outer example listener).

To ensure that the correct fixture instance is utilised in methods annotated with @BeforeExample and @AfterExample, pass the Fixture object into ExampleEvents, which necessitates passing it through ExampleCommands.

Fixes #246 and #262.

@@ -78,7 +78,7 @@ public void override(Resource resource) throws IOException {
public ResultSummary process(Fixture fixture) throws IOException {
SummarizingResultRecorder resultRecorder = new SummarizingResultRecorder();
resultRecorder.setSpecificationDescription(fixture.getSpecificationDescription());
getSpecification(fixture).process(evaluatorFactory.createEvaluator(fixture.getFixtureObject()), resultRecorder);
getSpecification(fixture).process(evaluatorFactory.createEvaluator(fixture.getFixtureObject()), resultRecorder, fixture);
Copy link

Choose a reason for hiding this comment

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

It seems odd having to pass the fixture to two calls here on the same line.

Copy link
Member Author

@nigelcharman nigelcharman Mar 20, 2018

Choose a reason for hiding this comment

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

Good spot, SpecificationByExample holds the fixture, so I'll remove it from the process method.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've modified the handling so getSpecification() no longer requires a fixture

@@ -11,26 +11,26 @@ public AbstractCommandDecorator(Command command) {
this.command = command;
}

public void setUp(final CommandCall commandCall, final Evaluator evaluator, final ResultRecorder resultRecorder) {
public void setUp(final CommandCall commandCall, final Evaluator evaluator, final ResultRecorder resultRecorder, final Fixture fixture) {
process(commandCall, evaluator, resultRecorder, new Runnable() {
public void run() {
Copy link

Choose a reason for hiding this comment

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

Have we moved to the version of Java that has Lambdas yet? If so, the whole 'new Runnable' thing isn't needed anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not yet, still supporting JDK 7 currently (and checking with openjdk7 on Travis). Moving up can't be far away though.

@crstim
Copy link

crstim commented Mar 20, 2018

The PR looks OK. However, 3/4ths of it (or more) is just adding a new parameter to lots of existing methods. This is a code smell to me - and indicates we have need of a Data object of some type to encapsulate all the arguments - and mostly they are "CommandCell, Evaluator, ResultRecorder, and Fixture". This indicates some sort of "RuntimeContext" argument. It might be sensible to do this refactor now because we're breaking the API anyway - then we can add new things to the RuntimeContext object later and not break the API as badly.

(RuntimeContext is a bad name - but it's a starting point)

* origin/master:
  Prevent calls to @BeforeExample and @AfterExample annotated methods for ignored examples
  Fixed (jdk6 related) bug
  Introduced abstraction to the underlying example element to reduce coupling with DOM API
  Removed dependency to JUnit @ignore annotation
  Update .travis.yml
  [Gradle Release Plugin] - new version commit:  '2.1.4'.
  Updated old task in build.gradle
  Updated gradle wrapper distributionUrl for Java 7 on Travis
  Updated gradlew and git-publish plugin
  Changed ExampleFilter to ImplementationStatusModifier and changed SKIPPED to IGNORED
  Provide an extension point to allow filtering/skipping specification examples
  Added JDK10 to Travis
* master:
  Added extra properties to MANIFEST.MF
  Updated website URL to use https
  Updated Travis to use oraclejdk10
@nigelcharman nigelcharman added this to the 2.2.0 milestone Jul 1, 2018
@nigelcharman nigelcharman merged commit db3cb08 into master Jul 13, 2018
@nigelcharman nigelcharman deleted the before-examples branch July 13, 2018 22:24
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

Successfully merging this pull request may close these issues.

@AfterExample triggered for wrong example
2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载