Sha256: e6cdee23936b659f61f2e83fbccf87d766c6b98bbef6ee3294e7b1cf84f01dea

Contents?: true

Size: 956 Bytes

Versions: 6

Compression:

Stored size: 956 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: run.rb 185 2004-12-10 13:29:09Z 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

6 entries across 6 versions & 2 rubygems

Version Path
nitro-0.10.0 examples/og/mock_example.rb
nitro-0.11.0 examples/og/mock_example.rb
nitro-0.12.0 examples/og/mock_example.rb
og-0.10.0 examples/og/mock_example.rb
og-0.11.0 examples/og/mock_example.rb
og-0.12.0 examples/og/mock_example.rb