mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-03 00:39:59 +00:00
Basic ruby testing environment (hardmock, behaviors, rake tasks).
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@6 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
|
||||
class Thing
|
||||
def initialize foo, bar
|
||||
@foo = foo
|
||||
@bar = bar
|
||||
end
|
||||
|
||||
def snafu
|
||||
return @foo.val + @bar.val
|
||||
end
|
||||
end
|
||||
|
||||
class ThingTest < Test::Unit::TestCase
|
||||
def setup
|
||||
create_mocks :foo, :bar
|
||||
@thing = Thing.new(@foo, @bar)
|
||||
end
|
||||
|
||||
def teardown
|
||||
end
|
||||
|
||||
should "perform a stupid simple test" do
|
||||
@foo.expect.val.returns(1)
|
||||
@bar.expect.val.returns(2)
|
||||
|
||||
assert_equal(3, @thing.snafu)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../config/environment"
|
||||
require 'test/unit'
|
||||
require 'behaviors'
|
||||
require 'hardmock'
|
||||
|
||||
class Test::Unit::TestCase
|
||||
extend Behaviors
|
||||
|
||||
end
|
||||
@@ -1,41 +0,0 @@
|
||||
$here = File.dirname(__FILE__)
|
||||
require "#{$here}/../../config/environment"
|
||||
require 'cmock'
|
||||
|
||||
describe CMock do
|
||||
|
||||
before(:each) do
|
||||
@interface_parser = mock('InterfaceParser')
|
||||
@cmock = CMock.new('mocks', [], @interface_parser)
|
||||
end
|
||||
|
||||
it "should default mocks path to 'mocks'" do
|
||||
@cmock.mocks_path.should == 'mocks'
|
||||
end
|
||||
|
||||
it "should allow mocks path to be specified in constructor" do
|
||||
@cmock = CMock.new('yoohoo')
|
||||
@cmock.mocks_path.should == 'yoohoo'
|
||||
end
|
||||
|
||||
it "should default includes to empty array" do
|
||||
@cmock.includes.should == []
|
||||
end
|
||||
|
||||
it "should allow includes to be specified in constructor" do
|
||||
includes = ['fun', 'stuff']
|
||||
@cmock = CMock.new('blah', includes)
|
||||
@cmock.includes.should == includes
|
||||
end
|
||||
|
||||
it "should generate a mock module" do
|
||||
@cmock.should respond_to(:generate)
|
||||
end
|
||||
|
||||
it "should delegate to parser to extract interface" do
|
||||
module_header = 'my_module.h'
|
||||
@interface_parser.should_receive(:extract_interface).with(module_header)
|
||||
@cmock.generate(module_header)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
|
||||
class Thing
|
||||
def initialize foo, bar
|
||||
@foo = foo
|
||||
@bar = bar
|
||||
end
|
||||
|
||||
def snafu
|
||||
return @foo.val + @bar.val
|
||||
end
|
||||
end
|
||||
|
||||
class ThingTest < Test::Unit::TestCase
|
||||
def setup
|
||||
create_mocks :foo, :bar
|
||||
@thing = Thing.new(@foo, @bar)
|
||||
end
|
||||
|
||||
def teardown
|
||||
end
|
||||
|
||||
should "perform a stupid simple test" do
|
||||
@foo.expect.val.returns(1)
|
||||
@bar.expect.val.returns(2)
|
||||
|
||||
assert_equal(3, @thing.snafu)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user