From 23c098385831043a7290c7fb8da2a53dddd1a5bb Mon Sep 17 00:00:00 2001 From: Leonardo Luarte G Date: Sat, 28 Mar 2026 00:40:22 -0300 Subject: [PATCH 1/2] feat: implement story_name and subject class methods - story_name sets/gets a human-readable description for the story - subject defines an instance method delegating to a named attribute, letting steps refer to the main actor via subject - Update README to use story_name (avoids overriding Module#name) - Add specs for both methods Co-Authored-By: Claude Sonnet 4.6 --- README.md | 6 +++--- lib/storyteller.rb | 8 ++++++++ spec/storyteller_spec.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f621112..1f2fd57 100644 --- a/README.md +++ b/README.md @@ -108,12 +108,12 @@ user, the `after_run`s may come in handy. Other methods are included to help define the story -**name** can be used to give the Story a more user story name +**story_name** can be used to give the Story a more user story name **subject** can be used to define which is the main user of a story, so any other method can refer to that user as subject - + class BookClosestToMe < Story - name 'As a user I want to make a reservation in a restaurant closest to me' + story_name 'As a user I want to make a reservation in a restaurant closest to me' subject :creator def creator = user diff --git a/lib/storyteller.rb b/lib/storyteller.rb index a9ecc7d..ec4c38e 100644 --- a/lib/storyteller.rb +++ b/lib/storyteller.rb @@ -118,6 +118,14 @@ def self.done_criteria(arg = nil, &block) verify(arg, &block) end + def self.story_name(value = nil) + value ? @story_name = value : @story_name + end + + def self.subject(method_name) + define_method(:subject) { send(method_name) } + end + def success? return true if @stage == :success diff --git a/spec/storyteller_spec.rb b/spec/storyteller_spec.rb index 35315f3..e395988 100644 --- a/spec/storyteller_spec.rb +++ b/spec/storyteller_spec.rb @@ -378,5 +378,34 @@ def second_check = spy2.call expect(spy1).to have_received(:call) expect(spy2).to have_received(:call) end + + it "supports story_name" do + class NamedStory < Storyteller::Story + story_name "As a user I want to do something" + step -> {} + end + + expect(NamedStory.story_name).to eq("As a user I want to do something") + end + + it "returns nil for story_name when not set" do + class UnnamedStory < Storyteller::Story + step -> {} + end + + expect(UnnamedStory.story_name).to be_nil + end + + it "supports subject" do + class StoryWithSubject < Storyteller::Story + initialize_with :user + subject :user + step -> {} + end + + user = double("User") # standard:disable RSpec/VerifiedDoubles + story = StoryWithSubject.new(user:) + expect(story.subject).to eq(user) + end end end From c410c67c304a73ae58ab53b48ea346252ca96a34 Mon Sep 17 00:00:00 2001 From: Leonardo Luarte G Date: Sat, 28 Mar 2026 00:41:26 -0300 Subject: [PATCH 2/2] chore: bump version to 0.5.0 Co-Authored-By: Claude Sonnet 4.6 --- Gemfile.lock | 2 +- lib/storyteller/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 67f678b..d63a8b0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - storyteller (0.4.4) + storyteller (0.5.0) activesupport ostruct smart_init diff --git a/lib/storyteller/version.rb b/lib/storyteller/version.rb index 9f8c396..70c9928 100644 --- a/lib/storyteller/version.rb +++ b/lib/storyteller/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Storyteller - VERSION = "0.4.4" + VERSION = "0.5.0" end