[rspec-users] Problems with array mock

David Chelimsky dchelimsky at gmail.com
Mon Aug 6 12:52:28 EDT 2007


On 8/6/07, Gaston Ramos <gramos at rectorado.unl.edu.ar> wrote:
>
> Hi everyone,
>
> I'm trying this in my helper spec and it didn't work:
>
> @curr_odontogram.should_receive('photos[1]').and_return(@photo)
>
> and the error is:
>
> SyntaxError in 'PersonHelper Deberia devolverme un link para eliminar una foto'
> compile error
> /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/lib/spec/mocks/proxy.rb:99:
> syntax error, unexpected '[', expecting '\n' or ';'
>           def photos[1](*args, &block)
>
> does anyone have a good solution for this?
>
> the complete code of the helper:
>
> http://pastie.caboo.se/85287
>
> the complete code of the spec helper:
>
> http://pastie.caboo.se/85289

This is ruby magic causing confusion. When you call foo.photos[1],
you're actually calling foo.photos[](1) (though that won't work) - so
I *think* the expectation should read:

@curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo)

Give that a try.

>
>
> See you.
> --
> Gastón Ramos
>
> GNU/Linux Counter user #450312
> http://gastonramos.wordpress.com/
>
> No a la Matricula Obligatoria
> http://noalamatricula.wordpress.com/about/
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list