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/