psyho / bogus

Fake library for Ruby
Other
359 stars 14 forks source link

Fake class and classes in namespace #25

Closed LTe closed 11 years ago

LTe commented 11 years ago

I have a problem with the library DCell. DCell provide DCell class where you can execute methods like start or setup. I would like to fake this class. I can do this by:

fake_class(DCell)

But after that I'm not able to use DCell::Node class.

How to reproduce:

require 'dcell'

require 'rspec'
require 'bogus/rspec'

describe DCell do
  fake_class(DCell)

  it "should have access to DCell subclass" d
    DCell::Node.new.should be_kind_of(Object)   
  end
end

And execute:

Failures:

  1) DCell should have access to DCell subclass
     Failure/Error: DCell::Node.new.should be_kind_of(Object)
     NameError:
       uninitialized constant DCell::Node
     # ./dcell_spec.rb:10:in `block (2 levels) in <top (required)>'

Finished in 0.01282 seconds
1 example, 1 failure
psyho commented 11 years ago

Thanks for reporting this. Do you think that the classes inside faked class should be faked recursively, or should they just be accessible?

LTe commented 11 years ago

Do you think that the classes inside faked class should be faked recursively, or should they just be accessible?

I think Bogus should stub all class methods of this class. But we should still have access to class inside namespace. I think there is many usecases where you will fake only "top level class" and do not touch other classes. Because in some cases it will cause stub the entire project/namespace.