-
Notifications
You must be signed in to change notification settings - Fork 11
Fixture templating: adds the ability to create fixtures from templates files using dynamic values #16
base: master
Are you sure you want to change the base?
Conversation
e936111
to
50e1718
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some nitpicks form myself but this LGTM.
README.md
Outdated
|
||
server.addTemplate("json_template.json") | ||
.withValueForKey("current_date", timestamp) | ||
.ifRequestMatches("/get_current_date"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method ifRequestMatches()
does not take arguments right?
@@ -0,0 +1,3 @@ | |||
{ | |||
"error_message": "${error}" | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a new line at the end of the file?
@@ -0,0 +1,3 @@ | |||
{ | |||
"current_date": "${current_date}" | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@@ -0,0 +1,3 @@ | |||
{ | |||
"error_message": "${error}" | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line here too please.
@@ -0,0 +1,3 @@ | |||
{ | |||
"current_date": "${current_date}" | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another new line :)
@@ -126,7 +126,7 @@ public MockWebServer getMockWebServer() { | |||
public String readFixture(final String fixturePath) { | |||
try { | |||
return IOReader.read(open(fixturesRootFolder + "/" + fixturePath)) + "\n"; | |||
} catch (IOException e) { | |||
} catch (IOException | IllegalArgumentException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What triggers dynamically IllegalArgument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOReader's read
throws IllegalArgumentException when it receives a null arg, so if someone tries to open a file that does not exist, IllegalArgumentException is thrown without much detail. If you catch it, the exception is rethrown as a RuntimeException and with a helpful message (stating the resolved path for the file).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to go around this is to throw a FileNotFoundException
when getResourceAsStream
returns null inside LocalTestRequestMatcherRule
's open. Let me know what you think is best!
Should’ve ran the quality suite 🧐 |
Friendly ping |
This PR adds a templating mechanism to
requestmatcher
. It works by replacing keys that are in the${KEY}
format by the values specified using the fluent API exposed to users of the library, like this:I believe no change is breaking! I chose to change the method name from
addFixture
toaddTemplate
in this case to make the intentions clearer. The delimiters ($,{,}
) are open for discussion!