Sha256: d10ad04a5b7be961057a4a9b71c7412d6c137fa289e687d70bf6b0f13805ca9b

Contents?: true

Size: 953 Bytes

Versions: 11

Compression:

Stored size: 953 Bytes

Contents

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 = Spec::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 Spec
  module Mocks
    module ExampleMethods
      include CouchPotato::RSpec::StubDb
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
davber_couch_potato-0.4.0 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.4.0 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.3.2 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.3.1 lib/couch_potato/rspec/stub_db.rb
davber_couch_potato-0.3.0 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.3.0 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.2.32 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.2.31 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.2.30 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.2.29 lib/couch_potato/rspec/stub_db.rb
couch_potato-0.2.28 lib/couch_potato/rspec/stub_db.rb