Class: CouchPotato::RSpec::StubView::ViewStub

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_potato/rspec/stub_db.rb

Instance Method Summary collapse

Constructor Details

#initialize(clazz, view, db) ⇒ ViewStub

Returns a new instance of ViewStub.



5
6
7
8
9
# File 'lib/couch_potato/rspec/stub_db.rb', line 5

def initialize(clazz, view, db)
  @clazz = clazz
  @view = view
  @db = db
end

Instance Method Details

#and_return(return_value) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/couch_potato/rspec/stub_db.rb', line 16

def and_return(return_value)
  view_stub = RSpec::Mocks::Mock.new("#{@clazz}.#{@view}(#{@args.try(:join, ', ')}) view")
  _stub = @clazz.stub(@view)
  _stub.with(*@args) if @args
  _stub.and_return(view_stub)
  @db.stub(:view).with(view_stub).and_return(return_value)
end

#with(*args) ⇒ Object



11
12
13
14
# File 'lib/couch_potato/rspec/stub_db.rb', line 11

def with(*args)
  @args = args
  self
end