File: readme.md

package info (click to toggle)
ruby-bogus 0.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 828 kB
  • ctags: 628
  • sloc: ruby: 4,124; makefile: 6; sh: 2
file content (35 lines) | stat: -rw-r--r-- 1,084 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
34
35
Bogus let's you stub methods on any object, not just fakes, which makes this feature usable even in scenarios when you don't follow the Inversion of Control Principle.

When you stub/mock a method in Bogus, it will automatically ensure that:

1. The method actually exists
2. It can take the number of arguments you passed

Those of you familiar with RR stubbing syntax, will feel right at home with Bogus:

    stub(object).method_name(*arguments) { return_value }

One key difference is for when you want to stub a method for any arguments:

    # RR syntax
    stub(object).method_name { return_value }

    # Bogus syntax
    stub(object).method_name(any_args) { return_value }

One other, quite important thing, is that Bogus does not erase the method signature when stubbing:

    class Library
      def self.checkout(book)
      end
    end

The following would be OK in RR:

    stub(Library).checkout { "foo" }
    Library.checkout("a", "b") # returns "foo"

But not in Bogus:

    stub(Library).checkout(any_args) { "foo" }
    Library.checkout("a", "b") # raises an error