[rspec-users] Confused about square bracket usage.

Teedub twscannell at gmail.com
Mon Aug 11 00:59:25 EDT 2008

I ran script/generate rspec_scaffold page title:string body:text and
have been reading on the generated code in my spare time in an attempt
to fully understand rspec. It mostly makes a lot of sense except for
the square brackets in the snippet below. 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. You wouldn't say [@pages].

I can't get my head wrapped around the syntax.

Thanks in advance.


def mock_page(stubs={})
    @mock_page ||= mock_model(Page, stubs)

  describe "responding to GET index" do

    it "should expose all pages as @pages" do
      get :index
      assigns[:pages].should == [mock_page]

More information about the rspec-users mailing list