If I have a step matcher defined as so: Given "a user named $username" do |username| .... end Is there a way to call it from another step? For example: Given "a user named $username with a blog post |username| given_a_user_named(username) # calls existing step code # create a blog post end Cheers, -- Bryan Helmkamp http://brynary.com -- My blog
Bryan Helmkamp wrote:> If I have a step matcher defined as so: > > Given "a user named $username" do |username| > .... > end > > Is there a way to call it from another step? For example: > > Given "a user named $username with a blog post |username| > given_a_user_named(username) # calls existing step code > # create a blog post > end > > Cheers, > >I''m not sure if you can call a step directly... I would be very interested in that if you can.. But AFAIK the only option is to extract it into a helper method an place it in Spec::Story::World. So you would have: Given "a user named $username" do |username| create_user_with_name(user_name) end Given "a user named $username with a blog post |username| create_user_with_name(user_name) # create a blog post end I typically do things with instance variables though. So the "Given a user named $username" step would set an instance variable named @username. Then I would have a step that reads "$username has a blog post" that would get the instance variable name and it would build a post off of that user. The story would the read like: Given a user named Joey And Joey has a blog post -Ben
On May 14, 2008, at 12:45 PM, Bryan Helmkamp wrote:> If I have a step matcher defined as so: > > Given "a user named $username" do |username| > .... > end > > Is there a way to call it from another step? For example: > > Given "a user named $username with a blog post |username| > given_a_user_named(username) # calls existing step code > # create a blog post > endI''m pretty sure you can do this: Given "a user named $username with a blog post |username| Given "a user named #{username}" # create a blog post end Cheers, David> > > Cheers, > > -- > Bryan Helmkamp > http://brynary.com -- My blog > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Wed, May 14, 2008 at 2:24 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> On May 14, 2008, at 12:45 PM, Bryan Helmkamp wrote: > > If I have a step matcher defined as so: >> >> Given "a user named $username" do |username| >> .... >> end >> >> Is there a way to call it from another step? For example: >> >> Given "a user named $username with a blog post |username| >> given_a_user_named(username) # calls existing step code >> # create a blog post >> end >> > > I''m pretty sure you can do this: > > Given "a user named $username with a blog post |username| > Given "a user named #{username}" > # create a blog post > end >Is this by intention or just a side effect of the current implementation? -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080514/2da2cdf4/attachment.html>
On May 14, 2008, at 3:07 PM, Zach Dennis wrote:> On Wed, May 14, 2008 at 2:24 PM, David Chelimsky > <dchelimsky at gmail.com> wrote: > On May 14, 2008, at 12:45 PM, Bryan Helmkamp wrote: > > If I have a step matcher defined as so: > > Given "a user named $username" do |username| > .... > end > > Is there a way to call it from another step? For example: > > Given "a user named $username with a blog post |username| > given_a_user_named(username) # calls existing step code > # create a blog post > end > > I''m pretty sure you can do this: > > > Given "a user named $username with a blog post |username| > Given "a user named #{username}" > # create a blog post > end > > Is this by intention or just a side effect of the current > implementation?You''ll have to ask Dan - Dan?> > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080514/7d45e5f3/attachment.html>