Hi,
I am currently doing some "research" on trying to bring Arquillian into the AsciidoctorJ tests.
I do this because:
- Currently every test class creates an own Asciidoctor instance that is shared among the test methods, so that the tests are not fully isolated
- Asciidoctor instances and their associated Ruby instances are not terminated at the end of the test
- The code to create the Asciidoctor instance is spread over all tests.
Therefore I have started work on an Arquillian JRuby container that allows to create Ruby or Scripting container instances per test class or per test method and inject them as ArquillianResources.
The current state is available at
https://github.com/robertpanzer/arquillian-container-jruby, the relevant branch is 'ArquillianResource':
https://github.com/robertpanzer/arquillian-container-jruby/tree/ArquillianResourceAn example looks like this:
@Test
@RubyScript("testscript.rb")
public void secondTest(@ArquillianResource ScriptingContainer scriptingContainer) {
assertEquals(1L, scriptingContainer.runScriptlet("@a"));
}
At the moment it depends on arquillian-core 1.1.8.Final-SNAPSHOT!
Then I started to integrate that into AsciidoctorJ.
The current state is available in my fork in the branch ArquillianJrubyContainer:
https://github.com/robertpanzer/asciidoctorj/tree/ArquillianJrubyContainerThere I added in the test-support subproject an Arquillian extension that plays together nicely with the JRuby container and knows how to inject Asciidoctor instances:
https://github.com/robertpanzer/asciidoctorj/blob/ArquillianJrubyContainer/asciidoctorj-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fasciidoctor%2FWhenAsciiDocIsRenderedToDocument.java#L65Every Asciidoctor & Ruby instance is terminated after a test.
@Test
public void should_return_if_it_is_block(@ArquillianResource Asciidoctor asciidoctor) {
DocumentRuby document = asciidoctor.load(DOCUMENT, new HashMap<String, Object>());
assertThat(document.isBlock(), is(true));
}
To make this possible I had to split asciidoctorj-core into an API and an Impl part.
Asciidoctor.Factory now uses a ServiceLoader implementation to initialize the implementation instead of directly calling JRubyAsciidoctor.
So with this mail I want to start a discussion:
- Whether this is useful
- If the split into an API part and an Impl part is useful.
I'd say yes because it also paves the way to support JavaScript or native Java implementations.
- What other ideas do you have in this area?
So it would be great to get some feedback on that.
Best regards,
Robert