From ebb2b6e969a9483c1b06e08155ed0d74479f2622 Mon Sep 17 00:00:00 2001 From: greg-williams Date: Sun, 1 Jun 2008 13:58:18 +0000 Subject: [PATCH] git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@2 bf332499-1b4d-0410-844d-d2d48d5cc64c --- config/environment.rb | 8 ++++++++ lib/cmock.rb | 15 +++++++++++++++ rakefile.rb | 9 +++++++++ test/cmock_spec.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 config/environment.rb create mode 100644 lib/cmock.rb create mode 100644 rakefile.rb create mode 100644 test/cmock_spec.rb diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..33bbae8 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,8 @@ +ROOT_PATH = File.expand_path(File.dirname(__FILE__) + "/../") + +# Setup our load path: +[ + 'lib', +].each do |dir| + $LOAD_PATH.unshift(File.join(ROOT_PATH, dir)) +end diff --git a/lib/cmock.rb b/lib/cmock.rb new file mode 100644 index 0000000..eb77c4c --- /dev/null +++ b/lib/cmock.rb @@ -0,0 +1,15 @@ + +class CMock + attr_accessor :mocks_path, :includes, :interface_parser + + def initialize(mocks_path='mocks', includes=[], interface_parser=nil) + @mocks_path = mocks_path + @includes = includes + @interface_parser = interface_parser + end + + def generate(module_header) + @interface_parser.extract_interface(module_header) + end + +end \ No newline at end of file diff --git a/rakefile.rb b/rakefile.rb new file mode 100644 index 0000000..cd9be27 --- /dev/null +++ b/rakefile.rb @@ -0,0 +1,9 @@ +$here = File.dirname(__FILE__) + +require 'rake' +require 'rake/clean' +require 'rake/testtask' + +task :default do + sh 'spec test' +end \ No newline at end of file diff --git a/test/cmock_spec.rb b/test/cmock_spec.rb new file mode 100644 index 0000000..2eea127 --- /dev/null +++ b/test/cmock_spec.rb @@ -0,0 +1,41 @@ +$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