Method: Hardmock#create_mocks
- Defined in:
- lib/hardmock.rb
#create_mocks(*mock_names) ⇒ Object Also known as: create_mock
Create one or more new Mock instances in your test suite. Once created, the Mocks are accessible as instance variables in your test. Newly built Mocks are added to the full set of Mocks for this test, which will be verified when you call verify_mocks.
create_mocks :donkey, :cat # Your test now has @donkey and @cat
create_mock :dog # Test now has @donkey, @cat and @dog
The first call returned a hash { :donkey => @donkey, :cat => @cat } and the second call returned { :dog => @dog }
For more info on how to use your mocks, see Mock and Expectation
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hardmock.rb', line 27 def create_mocks(*mock_names) prepare_hardmock_control unless @main_mock_control mocks = {} mock_names.each do |mock_name| raise ArgumentError, "'nil' is not a valid name for a mock" if mock_name.nil? mock_name = mock_name.to_s mock_object = Mock.new(mock_name, @main_mock_control) mocks[mock_name.to_sym] = mock_object self.instance_variable_set "@#{mock_name}", mock_object end @all_mocks ||= {} @all_mocks.merge! mocks return mocks.clone end |