Be careful with stub! in RSpec

First of all, you should be careful with any call to stub.

You probably want to use stub just to simulate a behavior, one that you don’t want to test in your current test.

For example: You may want to use stub with a remote service, an API call.

Also, the method is stub not stub! (at least in RSpec 2.6.0)

 
This will not work but will not fail.

  # This won't work
  DineroMailIpn::Client.any_instance.stub!(
    :consulta_pago).and_return(@response_with_pays)

This is what you are looking for.

  # This will work
  DineroMailIpn::Client.any_instance.stub(
    :consulta_pago).and_return(@response_with_pays)

I don’t know exactly why stub! doesn’t fail, but it wasn’t doing what I was expecting (to actually stub that method and return the mock object I wanted)

Posted in developer tools, Ruby programming, web programming | Tagged , , , | Leave a comment

The best solution to this warning: Giving a path to render :action is deprecated.

I for one welcome this change and deprecation warning. It means that you should stop using this:

render :action => :index

And, if necessary, you should start using this:

render :index

The code is simpler and prettier. Don’t use render :template, unless you really need to.

If you use vim, you can use this search and replace string:

:%s/render :action => /render /g
Posted in open source, programming, Ruby programming, web programming | Tagged , , , , , , | Leave a comment

Por qué deberías usar `git pull –rebase` en vez de `git pull` solo

Al usar

  "git pull --rebase"

Git utiliza git-rebase en vez de git-merge.

git-merge nos genera un commit con todos los cambios entre el branch local y el branch que estamos bajando.

git-rebase va hacia atrás, hasta donde los branches divergieron, hace un reset y empieza a aplicar los cambios progresivamente, hasta llegar al último commit. Esto nos deja un log mucho más fácil de leer que con el commit generado por git-merge.

Así vamos a dejar de ver tantos:

  "Merge branch 'master' of github.com:etagwerker/whuffiebank"

Para más información: http://progit.org/book/es/ch3-6.html

Posted in developer tools, open source, programming | Tagged , , , , | Leave a comment