[rspec-users] Testing methods that yields a block

Myron Marston myron.marston at gmail.com
Tue Oct 12 17:02:12 EDT 2010


> class Cat
>   class << self
>      def start
>            id = get_uuid
>            begin
>               yield if block_given?
>            ensure
>                set_some_other_state
>            end
>      end
>    end
>    #...
> end

In spite of the fact that you have an #id= method, `id = get_uuid` is
setting a local variable, not invoking the #id= method.  Use `self.id
= get_uuid` to invoke the method and set the attribute.

Myron


More information about the rspec-users mailing list