Class: Mock5::Api
- Inherits:
-
Object
- Object
- Mock5::Api
- Defined in:
- lib/mock5/api.rb
Overview
A class representing an API mock
Instance Attribute Summary collapse
-
#app ⇒ Sinatra::Base
readonly
A Sinatra app mocking the API.
-
#endpoint ⇒ Regexp
readonly
A regexp to match the API request urls.
Instance Method Summary collapse
-
#initialize(endpoint = nil) { ... } ⇒ Mock5::Api
constructor
Returns an instance of
Mock5::Api
. -
#request_stub ⇒ WebMock::RequestStub
Returns webmock request stub built with Sinatra app and enpoint url.
Constructor Details
#initialize(endpoint = nil) { ... } ⇒ Mock5::Api
Returns an instance of Mock5::Api
38 39 40 41 |
# File 'lib/mock5/api.rb', line 38 def initialize(endpoint=nil, &block) @app = Sinatra.new(&block) @endpoint = normalize_endpoint(endpoint) end |
Instance Attribute Details
#app ⇒ Sinatra::Base (readonly)
Returns a Sinatra app mocking the API.
10 11 12 |
# File 'lib/mock5/api.rb', line 10 def app @app end |
#endpoint ⇒ Regexp (readonly)
Returns a regexp to match the API request urls.
13 14 15 |
# File 'lib/mock5/api.rb', line 13 def endpoint @endpoint end |
Instance Method Details
#request_stub ⇒ WebMock::RequestStub
Returns webmock request stub built with Sinatra app and enpoint url
46 47 48 |
# File 'lib/mock5/api.rb', line 46 def request_stub @request_stub ||= WebMock::RequestStub.new(:any, endpoint).tap{ |s| s.to_rack(app) } end |