Skip to content

Commit

Permalink
Fix where code blocks are missing their source code (renatoathaydes#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gleethos authored and Gleethos committed Nov 4, 2022
1 parent 0a92f4d commit b6a3ae6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>

private writeBlockRowsFromCode( MarkupBuilder builder, cssClass, blockKind,
BlockCode code, text, int failureLineNumber ) {
def statements = code.statements
def statements = ( blockKind == 'where' ? [] : code.statements )
def lineNumbers = code.lineNumbers

if ( text ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ class VividASTVisitor extends ClassCodeVisitorSupport {
}

codeCollector.add( statement )

if ( statement.statementLabel == 'where' ) {
waitForNextBlock = true
}
}
visitStatements = false
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templateReportCreator/spec-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Time: $totalTime
%>
* ${block.kind} ${block.text}
<%
if ( block.sourceCode ) {
if ( block.sourceCode && block.kind != 'Where:' ) {
out << "\n```\n"
block.sourceCode.each { codeLine ->
out << codeLine << '\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class VividAstInspectorSpec extends Specification {
blocks[ 1 ].statements.isEmpty()
blocks[ 2 ].statements.isEmpty()
blocks[ 3 ].statements == [ 'x == y' ]
blocks[ 4 ].statements.isEmpty() // where statements are not captured
blocks[ 4 ].statements == [ "x | y", "'a' | 'a'", "'b' | 'c'" ]

and: 'The blocks should have the expected label and text'
blocks[ 0 ].label == 'given'
Expand Down Expand Up @@ -282,8 +282,8 @@ class VividAstInspectorSpec extends Specification {
and: 'The inspector should be able to provide the source code for each block'
blocks[ 0 ].statements == [ 'x < y' ]

and: 'The where block is not captured'
blocks[ 1 ].statements.isEmpty()
and: 'The where block is captured'
blocks[ 1 ].statements == ['x | y', '20 | 30', '100 | 2000']

and: 'The cleanup block is captured'
blocks[ 2 ].statements == [ 'x = null' ]
Expand Down

0 comments on commit b6a3ae6

Please sign in to comment.