Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (40 sloc) 0.955 kb
module CouchPotato::RSpec
module StubView
class ViewStub
def initialize(clazz, view, db)
@clazz = clazz
@view = view
@db = db
end
def with(*args)
@args = args
self
end
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
end
def stub_view(clazz, view)
ViewStub.new clazz, view, self
end
end
module StubDb
def stub_db(options = {})
db = stub('db', options)
db.extend CouchPotato::RSpec::StubView
CouchPotato.stub(:database => db)
db
end
end
end
module RSpec
module Mocks
module ExampleMethods
include CouchPotato::RSpec::StubDb
end
end
end
Jump to Line
Something went wrong with that request. Please try again.