diff --git a/hitch/story/rewrite-given.story b/hitch/story/rewrite-given.story index 8b8be4c..da0e5f1 100644 --- a/hitch/story/rewrite-given.story +++ b/hitch/story/rewrite-given.story @@ -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") @@ -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 @@ -66,4 +67,4 @@ Story that rewrites given preconditions: response: | {"greeting": "bye"} steps: - - Call API + - Call API diff --git a/hitchstory/story_file.py b/hitchstory/story_file.py index 77826a1..02f10e2 100644 --- a/hitchstory/story_file.py +++ b/hitchstory/story_file.py @@ -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)][