samedi 19 novembre 2016

Why is this not the same code

In my test I assure that two controller methods are called in a seperate helper class:

controller.expects(:sign_in).with(user).returns(:ok)
controller.expects(:redirect_to).returns(:ok)

When my write my helper class like, that, the tests work as aspected and succeed:

  def call
    @controller = context.controller

    controller.sign_in user
    controller.redirect_to remove_from_url(url)
  end

But when I change it to:

  def call
    @controller = context.controller

    controller do
      sign_in user
      redirect_to remove_from_url(url)
    end
  end

Then the tests fail, as message I get:

expected exactly once, not yet invoked ...

Why does this code not do the same?Thanks

1)  controller.sign_in user
    controller.redirect_to remove_from_url(url)

2)  controller do
      sign_in user
      redirect_to remove_from_url(url)
    end

Aucun commentaire:

Enregistrer un commentaire