[rspec-users] How do you mock a local variable ?

MathLef mlefrancois19 at gmail.com
Thu Feb 26 15:43:11 EST 2009


I need some help to spec' a function I am developping. Note that the
function is still not complete, cause I am trying to spec' it while
working on it, as it should be ! Basically, this is what my function
should look like :

def obtain_criterias(hash_params)
  crits = {}
  hash_params.each {
   |key, val|
    crits[key.to_sym] = StringUtils.sanitize(val).upcase if not (key
== "controller" || key == "action")
  return crits

 - hash_params is a hash table of some parameters received by a
 - StringUtils.sanitize removes all kind of accents from the string
passed in parameters
 - it is encapsulated in a controller

The problem is with the local variable "crits" on which I can not seem
to have any kind of control in my rspec. Now, I am wandering, is this
(still) a good way to code from a spec point of view ?! Can you give
me ideas on ways to spec this ?

Many thanks in advance !

More information about the rspec-users mailing list