Sha256: 95c1a2b6a49a51508feae9d03fec77cb008f1d054974fbf1a59888935fb7858a
Contents?: true
Size: 1.39 KB
Versions: 3
Compression:
Stored size: 1.39 KB
Contents
module CouchPotato::RSpec module StubView class ViewStub def initialize(clazz, view, db) @clazz = clazz @view = view @db = db end def with(*args, &block) @args = args and_return(block.call) if block 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) if return_value.respond_to?(:first) @db.stub(:first).with(view_stub).and_return(return_value.first) if return_value.first @db.stub(:first!).with(view_stub).and_return(return_value.first) else @db.stub(:first!).with(view_stub).and_raise(CouchPotato::NotFound) end end end end def stub_view(clazz, view, &block) stub = ViewStub.new clazz, view, self stub.and_return(block.call) if block stub end end module StubDb def stub_db(options = {}) db = double('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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
couch_potato-1.4.0 | lib/couch_potato/rspec/stub_db.rb |
couch_potato-1.3.0 | lib/couch_potato/rspec/stub_db.rb |
couch_potato-1.2.0 | lib/couch_potato/rspec/stub_db.rb |