Perryn Fowler
2008-Apr-22 13:36 UTC
[rspec-users] how do i remove duplication from my steps in story runner?
OK, I''m probably being incredibly dense here
I have some steps defined something like this (extremely contrived) example
steps_for(:foo) do
#snip Given and When steps
Then("two nested divs and a image will be displayed") do
response.should have_tag("div") do
with_tag("div")
end
response.should have_tag("img")
end
Then("two nested divs and a table will be displayed") do
response.should have_tag("div") do
with_tag("div")
end
response.should have_tag("table")
end
end
with_steps_for :foo do
run ''stories/foo_story'', :type => RailsStory
end
Now, I''d like to remove the duplication in there by extracting out a
''two_nested_divs_should_be_displayed'' method so that my steps
can read
more like
steps_for(:foo) do
#snip Given and When steps
Then("two nested divs and a image will be displayed") do
two_nested_divs_should_be_displayed
response.should have_tag("img")
end
Then("two nested divs and a table will be displayed") do
two_nested_divs_should_be_displayed
response.should have_tag("table")
end
end
with_steps_for :foo do
run ''stories/foo_story'', :type => RailsStory
end
but the ruby magic going on is proving hard for me to untangle and I
can''t for the life of me get it to work. I either get method_missing
looking for my method, or the method complains that ''with_tag''
is
undefined.
any ideas?
Rick DeNatale
2008-Apr-22 19:00 UTC
[rspec-users] how do i remove duplication from my steps in story runner?
On Tue, Apr 22, 2008 at 9:36 AM, Perryn Fowler <pezlists at gmail.com> wrote:> OK, I''m probably being incredibly dense here > > I have some steps defined something like this (extremely contrived) example > > > steps_for(:foo) do > > #snip Given and When steps > > Then("two nested divs and a image will be displayed") do > response.should have_tag("div") do > with_tag("div") > end > response.should have_tag("img") > end > > Then("two nested divs and a table will be displayed") do > response.should have_tag("div") do > with_tag("div") > end > response.should have_tag("table") > end > end > > with_steps_for :foo do > run ''stories/foo_story'', :type => RailsStory > end > > > Now, I''d like to remove the duplication in there by extracting out a > ''two_nested_divs_should_be_displayed'' method so that my steps can read > more like > > > > steps_for(:foo) do > > #snip Given and When steps > > Then("two nested divs and a image will be displayed") do > two_nested_divs_should_be_displayed > response.should have_tag("img") > end > > Then("two nested divs and a table will be displayed") do > two_nested_divs_should_be_displayed > response.should have_tag("table") > end > end > > with_steps_for :foo do > run ''stories/foo_story'', :type => RailsStory > end > > but the ruby magic going on is proving hard for me to untangle and I > can''t for the life of me get it to work. I either get method_missing > looking for my method, or the method complains that ''with_tag'' is > undefined. > > any ideas? > _______________________________________________Another attack. Then("two nested divs and an? $type will be displayed") do | type | response.should have_tag("div") do with_tag("div") end response.should have_tag(type == ''image'' ? ''img'' : type) end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
Perryn Fowler
2008-Apr-23 02:30 UTC
[rspec-users] how do i remove duplication from my steps in story runner?
> Another attack. > > Then("two nested divs and an? $type will be displayed") do | type | > > response.should have_tag("div") do > with_tag("div") > end > response.should have_tag(type == ''image'' ? ''img'' : type) > end >Thanks for the cool idea Rick, but unfortunately that only helps with my contrived little example - for my real app I really do need to be able to factor out some helper methods...
Zach Dennis
2008-Apr-23 17:20 UTC
[rspec-users] how do i remove duplication from my steps in story runner?
You should be able to make your own module of helpers and include it into
Spec::Story::World
module Spec::Story::World
def your_helper_method
# i should have access to everything I need
end
end
Zach
On Tue, Apr 22, 2008 at 10:30 PM, Perryn Fowler <pezlists at gmail.com>
wrote:
> > Another attack.
> >
> > Then("two nested divs and an? $type will be displayed") do
| type |
> >
> > response.should have_tag("div") do
> > with_tag("div")
> > end
> > response.should have_tag(type == ''image'' ?
''img'' : type)
> > end
> >
>
> Thanks for the cool idea Rick, but unfortunately that only helps with
> my contrived little example -
> for my real app I really do need to be able to factor out some helper
> methods...
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
--
Zach Dennis
http://www.continuousthinking.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/rspec-users/attachments/20080423/7d9475cb/attachment-0001.html
Perryn Fowler
2008-Apr-24 04:32 UTC
[rspec-users] how do i remove duplication from my steps in story runner?
> You should be able to make your own module of helpers and include it into > Spec::Story::World > > module Spec::Story::World > def your_helper_method > # i should have access to everything I need > end >endbrilliant, worked like a charm thanks :) If you will indulge a ruby newb question for a moment - how could I have worked this out for myself?
Matthias Hennemeyer
2008-Apr-24 12:41 UTC
[rspec-users] how do i remove duplication from my steps in story runner?
Hi Perryn, maybe you''ll find this interesting: http://www.workunitgroup.com/2008/4/23/crafting-rspec-steps-with- step_eval-and-drying-them-with-a-helper The DRYing thing begins at the middle of the second part of this series. matthias