Module: ServiceMock
- Defined in:
- lib/service_mock.rb,
lib/service_mock/server.rb,
lib/service_mock/version.rb,
lib/service_mock/erb_methods.rb,
lib/service_mock/stub_creator.rb,
lib/service_mock/rake/base_task.rb,
lib/service_mock/command_line_options.rb,
lib/service_mock/rake/stop_server_task.rb,
lib/service_mock/rake/start_server_task.rb
Overview
ServiceMock::StubCreator is a class that can stub a set of services by reading a yaml file.
It is often necessary to stub multiple service calls in order to complete a test. ServiceMock has created a simple way to do this. It is implemented in a class named ‘ServiceMock::StubCreator`. This class has a single public method `create_stubs_with` which takes the name of the name of a file that has the data for all of the stubs you wish to create and optional data to merge with that file. Also, when you create an instance of the class it requires you to pass an instance of `ServiceMock::Server`.
At this time you need to setup everything in a specific directory structure. The directory it looks for is ‘config/mocks/stubs`. Inside that directory it looks for two additional directories - `data` and `templates`. The data file needed by the call needs be located in the `data` directory and the `ERB` files (templates) that it references needs to be in the `templates` directory.
The structure of the data file drives the stubbing. Let’s start with an example.
“‘yml service1.erb:
first_name: Mickey
last_name: Mouse
service2.erb:
username: mmouse
password: secret
“‘
With the above file the method call will mock to services. It will first of all read the file ‘service1.erb` from the `templates` directory and stub it passing the data that is associated. Next it will read the next template file, etc.
Defined Under Namespace
Modules: CommandLineOptions, ErbMethods, Rake Classes: Server, StubCreator
Constant Summary collapse
- VERSION =
"0.9"
Class Method Summary collapse
- .disable_stubs ⇒ Object
- .disable_stubs=(value) ⇒ Object
- .working_directory ⇒ Object
- .working_directory=(value) ⇒ Object
Class Method Details
.disable_stubs ⇒ Object
35 36 37 |
# File 'lib/service_mock.rb', line 35 def self.disable_stubs @disable_stubs ||= false end |
.disable_stubs=(value) ⇒ Object
39 40 41 |
# File 'lib/service_mock.rb', line 39 def self.disable_stubs=(value) @disable_stubs = value end |
.working_directory ⇒ Object
27 28 29 |
# File 'lib/service_mock.rb', line 27 def self.working_directory @working_directory ||= 'config/mocks' end |
.working_directory=(value) ⇒ Object
31 32 33 |
# File 'lib/service_mock.rb', line 31 def self.working_directory=(value) @working_directory = value end |