[rspec-users] Can you explain this code to me?
David Chelimsky
dchelimsky at gmail.com
Thu Feb 7 18:37:15 EST 2008
On Feb 7, 2008 5:26 PM, Pito Salas <rps at salas.com> wrote:
> I am experimenting with the restful-authentication plug in and I see
> that it has generated an rspec encantation which I had not seen
> before:
>
> it 'allows signup' do
> lambda do
> create_user
> response.should be_redirect
> end.should change(User, :count).by(1)
> end
>
> What does the combination of a lambda and a .should mean?
This should answer your question:
http://rspec.info/rdoc/classes/Spec/Matchers.html#M000386
HTH,
David
>
> Similarly but a little different:
>
> describe 'being created' do
> before do
> @user = nil
> @creating_user = lambda do
> @user = create_user
> violated "#{@user.errors.full_messages.to_sentence}" if
> @user.new_record?
> end
> end
>
> it 'increments User#count' do
> @creating_user.should change(User, :count).by(1)
> end
> end
>
> Thanks for any pointers or clarifications!
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
More information about the rspec-users
mailing list