How to use create method of Mock Package

Best Active_mocker_ruby code snippet using Mock.create

fff_mock_header_generator_spec.rb

Source:fff_mock_header_generator_spec.rb Github

copy

Full Screen

1require 'stringio'2require 'fff_mock_generator.rb'3require 'header_generator.rb'4# Test the contents of the .h file created for the mock.5describe "FffMockGenerator.create_mock_header" do6 context "when there is nothing to mock," do7 let(:mock_header) {8 parsed_header = {}9 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)10 }11 it "then the generated header file starts with an opening include guard" do12 expect(mock_header).to start_with(13 "#ifndef mock_display_H\n" +14 "#define mock_display_H")15 end16 it "then the generated file ends with a closing include guard" do17 expect(mock_header).to end_with(18 "#endif // mock_display_H\n")19 end20 it "then the generated file includes the fff header" do21 expect(mock_header).to include(22 %{#include "fff.h"\n})23 end24 it "then the generated file has a prototype for the init function" do25 expect(mock_header).to include(26 "void mock_display_Init(void);")27 end28 it "then the generated file has a prototype for the verify function" do29 expect(mock_header).to include(30 "void mock_display_Verify(void);")31 end32 it "then the generated file has a prototype for the destroy function" do33 expect(mock_header).to include(34 "void mock_display_Destroy(void);")35 end36 end37 context "when there is a function with no args and a void return," do38 let(:mock_header) {39 parsed_header = create_cmock_style_parsed_header(40 [{:name => 'display_turnOffStatusLed', :return_type => 'void'}])41 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)42 }43 it "then the generated header file starts with an opening include guard" do44 expect(mock_header).to start_with(45 "#ifndef mock_display_H\n" +46 "#define mock_display_H")47 end48 it "then the generated header file contains a fake function declaration" do49 expect(mock_header).to include(50 "DECLARE_FAKE_VOID_FUNC0(display_turnOffStatusLed);"51 )52 end53 it "then the generated file ends with a closing include guard" do54 expect(mock_header).to end_with(55 "#endif // mock_display_H\n")56 end57 end58 context "when there is a function with no args and a bool return," do59 let(:mock_header) {60 parsed_header = create_cmock_style_parsed_header(61 [{:name => 'display_isError', :return_type => 'bool'}])62 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)63 }64 it "then the generated file contains the fake function declaration" do65 expect(mock_header).to include(66 "DECLARE_FAKE_VALUE_FUNC0(bool, display_isError);"67 )68 end69 end70 context "when there is a function with no args and an int return," do71 let(:mock_header) {72 parsed_header = create_cmock_style_parsed_header(73 [{:name => 'display_isError', :return_type => 'int'}])74 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)75 }76 it "then the generated file contains the fake function declaration" do77 expect(mock_header).to include(78 "DECLARE_FAKE_VALUE_FUNC0(int, display_isError);"79 )80 end81 end82 context "when there is a function with args and a void return," do83 let(:mock_header) {84 parsed_header = create_cmock_style_parsed_header(85 [{:name => 'display_setVolume', :return_type => 'void', :args => ['int']}])86 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)87 }88 it "then the generated file contains the fake function declaration" do89 expect(mock_header).to include(90 "DECLARE_FAKE_VOID_FUNC1(display_setVolume, int);"91 )92 end93 end94 context "when there is a function with args and a value return," do95 let(:mock_header) {96 parsed_header = create_cmock_style_parsed_header(97 [{:name => 'a_function', :return_type => 'int', :args => ['char *']}])98 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)99 }100 it "then the generated file contains the fake function declaration" do101 expect(mock_header).to include(102 "FAKE_VALUE_FUNC1(int, a_function, char *);"103 )104 end105 end106 context "when there is a function with many args and a void return," do107 let(:mock_header) {108 parsed_header = create_cmock_style_parsed_header(109 [{:name => 'a_function', :return_type => 'void',110 :args => ['int', 'char *', 'int', 'int', 'bool', 'applesauce']}])111 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)112 }113 it "then the generated file contains the fake function declaration" do114 expect(mock_header).to include(115 "DECLARE_FAKE_VOID_FUNC6(a_function, int, char *, int, int, bool, applesauce);"116 )117 end118 end119 context "when there are multiple functions," do120 let(:mock_header) {121 parsed_header = create_cmock_style_parsed_header(122 [ {:name => 'a_function', :return_type => 'int', :args => ['char *']},123 {:name => 'another_function', :return_type => 'void'},124 {:name => 'three', :return_type => 'bool', :args => ['float', 'int']}125 ])126 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)127 }128 it "then the generated file contains the first fake function declaration" do129 expect(mock_header).to include(130 "DECLARE_FAKE_VALUE_FUNC1(int, a_function, char *);"131 )132 end133 it "then the generated file contains the second fake function declaration" do134 expect(mock_header).to include(135 "DECLARE_FAKE_VOID_FUNC0(another_function);"136 )137 end138 it "then the generated file contains the third fake function declaration" do139 expect(mock_header).to include(140 "DECLARE_FAKE_VALUE_FUNC2(bool, three, float, int);"141 )142 end143 end144 context "when there is a typedef," do145 let(:mock_header) {146 parsed_header = create_cmock_style_parsed_header(147 nil, ["typedef void (*displayCompleteCallback) (void);"])148 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)149 }150 it "then the generated file contains the typedef" do151 expect(mock_header).to include(152 "typedef void (*displayCompleteCallback) (void);"153 )154 end155 end156 context "when there is a void function with variable arguments" do157 let(:mock_header){158 parsed_header = {}159 parsed_header[:functions] = [{160 :name => "function_with_var_args",161 :return => {:type => "void"},162 :var_arg => "...",163 :args => [{:type => 'char *'}]164 }]165 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)166 }167 it "then the generated file contains the vararg declaration" do168 expect(mock_header).to include(169 "DECLARE_FAKE_VOID_FUNC2_VARARG(function_with_var_args, char *, ...)"170 )171 end172 end173 context "when there is a function with a return value and variable arguments" do174 let(:mock_header){175 parsed_header = {}176 parsed_header[:functions] = [{177 :name => "function_with_var_args",178 :return => {:type => "int"},179 :var_arg => "...",180 :args => [{:type => 'char *'}]181 }]182 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)183 }184 it "then the generated file contains the vararg declaration" do185 expect(mock_header).to include(186 "DECLARE_FAKE_VALUE_FUNC2_VARARG(int, function_with_var_args, char *, ...)"187 )188 end189 end190 context "when there is a void function with variable arguments and " +191 "additional arguments" do192 let(:mock_header){193 parsed_header = {}194 parsed_header[:functions] = [{195 :name => "function_with_var_args",196 :return => {:type => "void"},197 :var_arg => "...",198 :args => [{:type => 'char *'}, {:type => 'int'}]199 }]200 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)201 }202 it "then the generated file contains the vararg declaration" do203 expect(mock_header).to include(204 "DECLARE_FAKE_VOID_FUNC3_VARARG(function_with_var_args, char *, int, ...)"205 )206 end207 end208 context "when there is a function with a pointer to a const value" do209 let(:mock_header){210 parsed_header = {}211 parsed_header[:functions] = [{212 :name => "const_test_function",213 :return => {:type => "void"},214 :args => [{:type => "char *", :name => "a", :ptr? => false, :const? => true},215 {:type => "char *", :name => "b", :ptr? => false, :const? => false}]216 }]217 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)218 }219 it "then the generated file contains the correct const argument in the declaration" do220 expect(mock_header).to include(221 "DECLARE_FAKE_VOID_FUNC2(const_test_function, const char *, char *)"222 )223 end224 end225 context "when there is a function that returns a const pointer" do226 let(:mock_header){227 parsed_header = {}228 parsed_header[:functions] = [{229 :name => "return_const_pointer_test_function",230 :modifier => "const",231 :return => {:type => "char *" },232 :args => [{:type => "int", :name => "a"}]233 }]234 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)235 }236 it "then the generated file contains the correct const return value in the declaration" do237 expect(mock_header).to include(238 "DECLARE_FAKE_VALUE_FUNC1(const char *, return_const_pointer_test_function, int)"239 )240 end241 end242 243 context "when there is a function that returns a const int" do244 let(:mock_header){245 parsed_header = {}246 parsed_header[:functions] = [{247 :name => "return_const_int_test_function",248 :modifier => "const",249 :return => {:type => "int" },250 :args => []251 }]252 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header)253 }254 it "then the generated file contains the correct const return value in the declaration" do255 expect(mock_header).to include(256 "DECLARE_FAKE_VALUE_FUNC0(const int, return_const_int_test_function)"257 )258 end259 end260 context "when there are pre-includes" do261 let(:mock_header) {262 parsed_header = {}263 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header,264 [%{"another_header.h"}])265 }266 it "then they are included before the other files" do267 expect(mock_header).to include(268 %{#include "another_header.h"\n} +269 %{#include "fff.h"}270 )271 end272 end273 context "when there are post-includes" do274 let(:mock_header) {275 parsed_header = {}276 FffMockGenerator.create_mock_header("display", "mock_display", parsed_header,277 nil, [%{"another_header.h"}])278 }279 it "then they are included after the other files" do280 expect(mock_header).to include(281 %{#include "display.h"\n} +282 %{#include "another_header.h"\n}283 )284 end285 end286end...

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1mock.create(1, 2, 3)2mock.create(1, 2, 3, 4)3mock.create(1, 2, 3, 4, 5)4mock.create(1, 2, 3)5mock.create(1, 2, 3, 4)6mock.create(1, 2, 3, 4, 5)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1mock.create(1, 2, 3)2mock.create(1, 2, 3, 4)3mock.create(1, 2, 3, 4, 5)4mock.create(1, 2, 3)5mock.create(1, 2, 3, 4)6mock.create(1, 2, 3, 4, 5)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Active_mocker_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful