Skip to content

Commit

Permalink
FEATURE : Rewrite given preconditions simple case.
Browse files Browse the repository at this point in the history
  • Loading branch information
crdoconnor committed Jan 8, 2024
1 parent afbc2b8 commit a2a3315
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions hitch/story/rewrite-given.story
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Story that rewrites given preconditions:
status: unimplemented
docs: engine/rewrite-given
about: |
These examples show how to build stories that rewrite themselves
from program output (in-test snapshot testing) but that rewrite
the given preconditions.
This is useful for changing
This is useful for auto-updating given preconditions when, for
example, a REST API service that is being mocked starts
returning different data.
```
self.current_step.rewrite("argument").to("new output")
Expand Down Expand Up @@ -41,7 +42,7 @@ Story that rewrites given preconditions:
def call_api(self):
if self._rewrite:
self.given.rewrite("Mock API", "response").to("""{"greeting": "bye"}""")
self.given.rewrite("Mock API", "response").to("""{"greeting": "bye"}\n""")
setup: |
from hitchstory import StoryCollection
Expand All @@ -66,4 +67,4 @@ Story that rewrites given preconditions:
response: |
{"greeting": "bye"}
steps:
- Call API
- Call API
7 changes: 6 additions & 1 deletion hitchstory/story_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ def to(self, text):
yaml_story = self.updated_yaml[self._story.name]

if isinstance(self._given_or_step, Given):
raise NotImplementedError
given_prop = yaml_story["given"]

for sub_prop in self._args[:-1]:
given_prop = given_prop[sub_prop]

given_prop[self._args[-1]] = text
else:
if "following_steps" in yaml_story:
step_to_update = yaml_story[_step_type(yaml_story)][
Expand Down

0 comments on commit a2a3315

Please sign in to comment.