File: stubbing_existing_methods_on_fakes_spec.rb

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 (50 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 require 'spec_helper'

 describe "Stubbing existing methods on fakes" do
   include Bogus::MockingDSL

   before do
     Bogus.clear
   end

   it "should be possible to stub to_s" do
     foo = fake(:foo) { Samples::Foo }

     stub(foo).to_s { "I'm a foo" }

     expect(foo.to_s).to eq("I'm a foo")
   end

   it "should be possible to mock to_s" do
     foo = fake(:foo) { Samples::Foo }

     mock(foo).to_s { "I'm a foo" }

     expect {
       Bogus.after_each_test
     }.to raise_exception(Bogus::NotAllExpectationsSatisfied)
   end


   it "should be possible to stub to_s on anonymous fake" do
     foo = fake(to_s: "I'm a foo")

     expect(foo.to_s).to eq("I'm a foo")
   end

   class Object
     def sample_method_for_stubbing_existing_methods
     end
   end

   class SampleForStubbingExistingMethods
   end

   it "should be possible to stub arbitrary methods that were defined on Object" do
     foo = fake(:foo) { SampleForStubbingExistingMethods }

     stub(foo).sample_method_for_stubbing_existing_methods { :bar }

     expect(foo.sample_method_for_stubbing_existing_methods).to eq(:bar)
   end
 end