[rspec-users] Confused about square bracket usage.

Steve Eley steve at deepsalt.com
Mon Aug 11 02:32:18 EDT 2008

On Mon, Aug 11, 2008 at 12:59 AM, Teedub <twscannell at gmail.com> wrote:
> To my best understanding,
> [mock_page] would be an array containing mock_page. That almost makes
> sense, buy why wouldn't the variable mock_page simply be an array like
> @pages.

What you say is completely correct.  In the code you give, mock_page
is defined as singular.  It represents a single mock instance of a
Page model.  It isn't an array because it isn't defined that way.  But
you can (and do) *put* it in an array to represent a collection of
instances of the Page model.

> You wouldn't say [@pages].

No, you usually wouldn't (though you could).  But if you had a @page
variable that represented just one Page, it would be quite sensible
and common to say @pages == [@page].

That's really all that mock_page is doing.

Have Fun,
Steve Eley
Deep Salt Team

More information about the rspec-users mailing list