[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

what does the 'it' do?

timr

9/28/2008 6:19:00 AM

I came across the following code (see below). As President Clinton
famously said, "It depends on what the definition of 'it' is." I am
hoping someone can explain how 'it' is being used. I have come across
this 'it...string...do' construct before, but I didn't understand it
then either.

describe IowaRubyBrigade do
before do
@irb = Array.new
end

it "should be a user group" do
@irb.should be_a_kind_of(UserGroup)
end

it "should meet monthly" do
@irb.meeting_time.should ==
'second Thursday of every month'
end

it "should be fun" do
@irb.should be_fun
end
end

When you ri it, you get:

----------------------------------
Spec::Example::ExampleGroupMethods#it
it(description=nil, &implementation)
------------------------------------------------------------------------
Creates an instance of Spec::Example::Example and adds it to a
collection of examples of the current example group.


(also known as specify)


But the documentation on Spec is difficult to find. Please educate me.
Thanks,
Tim
3 Answers

Robert Klemme

9/28/2008 8:51:00 AM

0

On 28.09.2008 08:18, timr wrote:
> I came across the following code (see below). As President Clinton
> famously said, "It depends on what the definition of 'it' is." I am
> hoping someone can explain how 'it' is being used. I have come across
> this 'it...string...do' construct before, but I didn't understand it
> then either.
>
> describe IowaRubyBrigade do
> before do
> @irb = Array.new
> end
>
> it "should be a user group" do
> @irb.should be_a_kind_of(UserGroup)
> end
>
> it "should meet monthly" do
> @irb.meeting_time.should ==
> 'second Thursday of every month'
> end
>
> it "should be fun" do
> @irb.should be_fun
> end
> end
>
> When you ri it, you get:
>
> ----------------------------------
> Spec::Example::ExampleGroupMethods#it
> it(description=nil, &implementation)
> ------------------------------------------------------------------------
> Creates an instance of Spec::Example::Example and adds it to a
> collection of examples of the current example group.
>
>
> (also known as specify)
>
>
> But the documentation on Spec is difficult to find. Please educate me.
> Thanks,
> Tim

"it" is a method which apparently does what your RI doc says. Most
likely it saves the block somewhere for later execution (i.e. in order
to perform the test).

Fur further information you probably want to look at RSpec
documentation, e.g. http://rspec.info/docu...

Kind regards

robert

Corey Haines

9/28/2008 11:59:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Last winter, I wrote a series of blog posts dissecting the rspec code to see
what describe/it do, as well as what happens when the examples are run. It
is from the perspective of a fairly new ruby person (as I was at the time,
and, I guess, still am), but here's links. I can't say whether they will
help you, or not, since I mostly wrote them for myself:
describe
Part I -
http://www.corey.../coreysramblings/2007/12/15/ARubyNewbieLooksThroughRSpecPartIIDes...
Part II -
http://www.corey.../coreysramblings/2007/12/22/ARubyNewbieLooksThroughRSpecPartIIIDescribe...

it
http://www.corey.../coreysramblings/2007/12/27/ARubyNewbieLooksThroughRSpecPar...

run
http://www.corey.../coreysramblings/2007/12/27/ARubyNewbieLooksThroughRSpecPartI...

Hope they can help explain it a bit.
-Corey

On Sun, Sep 28, 2008 at 4:54 AM, Robert Klemme
<shortcutter@googlemail.com>wrote:

> On 28.09.2008 08:18, timr wrote:
>
>> I came across the following code (see below). As President Clinton
>> famously said, "It depends on what the definition of 'it' is." I am
>> hoping someone can explain how 'it' is being used. I have come across
>> this 'it...string...do' construct before, but I didn't understand it
>> then either.
>>
>> describe IowaRubyBrigade do
>> before do
>> @irb = Array.new
>> end
>>
>> it "should be a user group" do
>> @irb.should be_a_kind_of(UserGroup)
>> end
>>
>> it "should meet monthly" do
>> @irb.meeting_time.should ==
>> 'second Thursday of every month'
>> end
>>
>> it "should be fun" do
>> @irb.should be_fun
>> end
>> end
>>
>> When you ri it, you get:
>>
>> ----------------------------------
>> Spec::Example::ExampleGroupMethods#it
>> it(description=nil, &implementation)
>> ------------------------------------------------------------------------
>> Creates an instance of Spec::Example::Example and adds it to a
>> collection of examples of the current example group.
>>
>>
>> (also known as specify)
>>
>>
>> But the documentation on Spec is difficult to find. Please educate me.
>> Thanks,
>> Tim
>>
>
> "it" is a method which apparently does what your RI doc says. Most likely
> it saves the block somewhere for later execution (i.e. in order to perform
> the test).
>
> Fur further information you probably want to look at RSpec documentation,
> e.g. http://rspec.info/docu...
>
> Kind regards
>
> robert
>
>


--
http://www.corey...
The Internet's Premiere source of information about Corey Haines

Corey Haines

9/28/2008 12:07:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Just a follow-up; I started reading through them, and the Part I of describe
is for an older version, so it can be skipped.

On Sun, Sep 28, 2008 at 7:59 AM, Corey Haines <coreyhaines@gmail.com> wrote:

> Last winter, I wrote a series of blog posts dissecting the rspec code to
> see
> what describe/it do, as well as what happens when the examples are run. It
> is from the perspective of a fairly new ruby person (as I was at the time,
> and, I guess, still am), but here's links. I can't say whether they will
> help you, or not, since I mostly wrote them for myself:
> describe
> Part I -
>
> http://www.corey.../coreysramblings/2007/12/15/ARubyNewbieLooksThroughRSpecPartIIDes...
> Part II -
>
> http://www.corey.../coreysramblings/2007/12/22/ARubyNewbieLooksThroughRSpecPartIIIDescribe...
>
> it
>
> http://www.corey.../coreysramblings/2007/12/27/ARubyNewbieLooksThroughRSpecPar...
>
> run
>
> http://www.corey.../coreysramblings/2007/12/27/ARubyNewbieLooksThroughRSpecPartI...
>
> Hope they can help explain it a bit.
> -Corey
>
> On Sun, Sep 28, 2008 at 4:54 AM, Robert Klemme
> <shortcutter@googlemail.com>wrote:
>
> > On 28.09.2008 08:18, timr wrote:
> >
> >> I came across the following code (see below). As President Clinton
> >> famously said, "It depends on what the definition of 'it' is." I am
> >> hoping someone can explain how 'it' is being used. I have come across
> >> this 'it...string...do' construct before, but I didn't understand it
> >> then either.
> >>
> >> describe IowaRubyBrigade do
> >> before do
> >> @irb = Array.new
> >> end
> >>
> >> it "should be a user group" do
> >> @irb.should be_a_kind_of(UserGroup)
> >> end
> >>
> >> it "should meet monthly" do
> >> @irb.meeting_time.should ==
> >> 'second Thursday of every month'
> >> end
> >>
> >> it "should be fun" do
> >> @irb.should be_fun
> >> end
> >> end
> >>
> >> When you ri it, you get:
> >>
> >> ----------------------------------
> >> Spec::Example::ExampleGroupMethods#it
> >> it(description=nil, &implementation)
> >> ------------------------------------------------------------------------
> >> Creates an instance of Spec::Example::Example and adds it to a
> >> collection of examples of the current example group.
> >>
> >>
> >> (also known as specify)
> >>
> >>
> >> But the documentation on Spec is difficult to find. Please educate me.
> >> Thanks,
> >> Tim
> >>
> >
> > "it" is a method which apparently does what your RI doc says. Most
> likely
> > it saves the block somewhere for later execution (i.e. in order to
> perform
> > the test).
> >
> > Fur further information you probably want to look at RSpec documentation,
> > e.g. http://rspec.info/docu...
> >
> > Kind regards
> >
> > robert
> >
> >
>
>
> --
> http://www.corey...
> The Internet's Premiere source of information about Corey Haines
>



--
http://www.corey...
The Internet's Premiere source of information about Corey Haines