Sha256: d2387e5d991fc948a98a7d3ad1e8ea2c49b026bf92a126f8ceefb01efad96ecc

Contents?: true

Size: 965 Bytes

Versions: 3

Compression:

Stored size: 965 Bytes

Contents

# = Og Mocking Example 
#
# A simple example to demonstrate how to mock Og.
# Very useful in test units.
#
# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id: mock_example.rb 280 2005-03-10 11:39:23Z gmosx $

require 'rubygems'
require 'flexmock'
require 'og'
require 'og/mock'

class Article
	prop_accessor :body, String

	def initialize(body = nil)
		@body = body
	end
end

class SimpleTest < Test::Unit::TestCase

	def setup
		@og = Og::MockDatabase.new
	end

	def teardown
		@og = nil
	end

	def test_me
		mocks = [
			Article.new('body1'),
			Article.new('body2'),
			Article.new('body3')
		]
		@og.mock_handle(:load_all) { |klass, extrasql| mocks }

		# differnt ways to call the mocked method...
		puts 'Here are the articles:', Article.all
		puts 'Here are the articles:', Article.load_all
		puts 'Here are the articles:', @og.load_all(Article)

		# 3 times called
		assert_equal(3, @og.mock_count(:load_all))
	end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
og-0.13.0 examples/mock_example.rb
og-0.14.0 examples/mock_example.rb
og-0.15.0 examples/mock_example.rb