Sha256: 55dc04be73eae62d958e5fa5b0f04747d83b28d03ca3400d74e584253db47a26

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

# = Og Mocking Example 
#
# A simple example to demonstrate how to mock Og.
# Very useful in test units.
#
# code: 
# * George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id: run.rb 185 2004-12-10 13:29:09Z gmosx $

$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')

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

4 entries across 4 versions & 2 rubygems

Version Path
nitro-0.8.0 examples/og/mock_example.rb
nitro-0.9.3 examples/og/mock_example.rb
og-0.8.0 examples/og/mock_example.rb
og-0.9.3 examples/og/mock_example.rb