Hi, How can I have a common set of steps that all my stories share? i.e. My stories often start out looking like this: Given a user Joe Given a user Jordan then: Given("a user $username") do |username| @users ||= {} @user_sessions ||= {} @users[username] = create_user(:username => username) @user_sessions[username] = login_as(@users[username]) end I want to share that Given with all my stories. Or is there a better way to do it? Joe
On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk <joe at pinkpucker.net> wrote:> Hi, > > How can I have a common set of steps that all my stories share? > > i.e. My stories often start out looking like this: > > Given a user Joe > Given a user Jordan > > then:put this in steps/users.rb: steps_for(:user) do> Given("a user $username") do |username| > @users ||= {} > @user_sessions ||= {} > @users[username] = create_user(:username => username) > @user_sessions[username] = login_as(@users[username]) > endend Now, in your file running stories: with_steps_for(:user, :project, :comment) do ... end> > I want to share that Given with all my stories. Or is there a better > way to do it? >At one of our current projects in BEKK we have come up with a convention for naming and grouping steps. It simply follows the same convention as the controllers for file names, and in each file we put all steps that are relevant to a given controller. In the run file we simply run stories with_steps_for all of them. Try it out, I think you''ll like it. Aslak> Joe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Thu, Mar 20, 2008 at 2:05 AM, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk <joe at pinkpucker.net> wrote: > > Hi, > > > > How can I have a common set of steps that all my stories share? > > > > i.e. My stories often start out looking like this: > > > > Given a user Joe > > Given a user Jordan > > > > then: > > put this in steps/users.rb:rails_proj/stories/steps or just rails_proj/steps?> steps_for(:user) do > > > Given("a user $username") do |username| > > @users ||= {} > > @user_sessions ||= {} > > @users[username] = create_user(:username => username) > > @user_sessions[username] = login_as(@users[username]) > > end > > end > > Now, in your file running stories: > > with_steps_for(:user, :project, :comment) do > ... > > end > > > > > I want to share that Given with all my stories. Or is there a better > > way to do it? > > > > At one of our current projects in BEKK we have come up with a > convention for naming and grouping steps. It simply follows the same > convention as the controllers for file names, and in each file we put > all steps that are relevant to a given controller.Makes sense.> In the run file we simply run stories with_steps_for all of them. > > Try it out, I think you''ll like it.Thanks, I will.
On 21. mars. 2008, at 07.32, "Joe Van Dyk" <joe at pinkpucker.net> wrote:> On Thu, Mar 20, 2008 at 2:05 AM, aslak hellesoy > <aslak.hellesoy at gmail.com> wrote: >> On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk <joe at pinkpucker.net> >> wrote: >>> Hi, >>> >>> How can I have a common set of steps that all my stories share? >>> >>> i.e. My stories often start out looking like this: >>> >>> Given a user Joe >>> Given a user Jordan >>> >>> then: >> >> put this in steps/users.rb: > > rails_proj/stories/steps or just rails_proj/steps?Whichever you like. I prefer the first one. Aslak> > >> steps_for(:user) do >> >>> Given("a user $username") do |username| >>> @users ||= {} >>> @user_sessions ||= {} >>> @users[username] = create_user(:username => username) >>> @user_sessions[username] = login_as(@users[username]) >>> end >> >> end >> >> Now, in your file running stories: >> >> with_steps_for(:user, :project, :comment) do >> ... >> >> end >> >>> >>> I want to share that Given with all my stories. Or is there a >>> better >>> way to do it? >>> >> >> At one of our current projects in BEKK we have come up with a >> convention for naming and grouping steps. It simply follows the same >> convention as the controllers for file names, and in each file we put >> all steps that are relevant to a given controller. > > Makes sense. > >> In the run file we simply run stories with_steps_for all of them. >> >> Try it out, I think you''ll like it. > > Thanks, I will. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Fri, Mar 21, 2008 at 10:35 AM, Aslak Helles?y <aslak.hellesoy at gmail.com> wrote:> > > On 21. mars. 2008, at 07.32, "Joe Van Dyk" <joe at pinkpucker.net> wrote: > > > On Thu, Mar 20, 2008 at 2:05 AM, aslak hellesoy > > <aslak.hellesoy at gmail.com> wrote: > >> On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk <joe at pinkpucker.net> > >> wrote: > >>> Hi, > >>> > >>> How can I have a common set of steps that all my stories share? > >>> > >>> i.e. My stories often start out looking like this: > >>> > >>> Given a user Joe > >>> Given a user Jordan > >>> > >>> then: > >> > >> put this in steps/users.rb: > > > > rails_proj/stories/steps or just rails_proj/steps? > > Whichever you like. I prefer the first one.I prefer the first one as well, -- Zach Dennis http://www.continuousthinking.com
On Mar 21, 2008, at 2:35 pm, Aslak Helles?y wrote:>> rails_proj/stories/steps or just rails_proj/steps? > > Whichever you like. I prefer the first one.I ended up creating RAILS_ROOT/stories/stories and RAILS_ROOT/stories/ steps I don''t like the duplication of "stories" but I prefer it to (apparently) having a group of stories called "steps". I also have a folder called RAILS_ROOT/stories/story_support where I''ve dumped selenium extensions etc. But arguably I should pull that out into vendor/gems or something. Ashley