File: central.rb

package info (click to toggle)
ruby-mocha 0.11.3-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,300 kB
  • sloc: ruby: 9,935; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 579 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Mocha

  class Central

    attr_accessor :stubba_methods

    def initialize
      self.stubba_methods = []
    end

    def stub(method)
      unless stubba_methods.detect { |m| m.matches?(method) }
        method.stub
        stubba_methods.push(method)
      end
    end

    def unstub(method)
      if existing = stubba_methods.detect { |m| m.matches?(method) }
        existing.unstub
        stubba_methods.delete(existing)
      end
    end

    def unstub_all
      while stubba_methods.any? do
        unstub(stubba_methods.first)
      end
    end

  end

end