Module: HttpDecoy
- Defined in:
- lib/http_decoy.rb,
lib/http_decoy/route.rb,
lib/http_decoy/rspec.rb,
lib/http_decoy/router.rb,
lib/http_decoy/server.rb,
lib/http_decoy/version.rb,
lib/http_decoy/minitest.rb,
lib/http_decoy/route_map.rb,
lib/http_decoy/definition.rb,
lib/http_decoy/request_log.rb,
lib/http_decoy/body_matcher.rb,
lib/http_decoy/configuration.rb,
lib/http_decoy/handler_context.rb,
lib/http_decoy/webmock_integration.rb
Defined Under Namespace
Modules: BodyMatcher, Minitest, RSpec, WebMockIntegration Classes: Configuration, Definition, HandlerContext, RequestLog, Route, RouteMap, Router, Server
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Global configuration.
-
.define(name = :default) ⇒ Object
Define a named fake service, reusable across RSpec and Minitest.
Class Method Details
.configuration ⇒ Object
25 26 27 |
# File 'lib/http_decoy.rb', line 25 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Global configuration.
HttpDecoy.configure do |c|
c.auto_intercept = false # opt out of WebMock auto-interception
end
21 22 23 |
# File 'lib/http_decoy.rb', line 21 def configure yield configuration end |
.define(name = :default) ⇒ Object
Define a named fake service, reusable across RSpec and Minitest.
FakeStripe = HttpDecoy.define(:stripe) do
base_url "https://api.stripe.com"
post "/v1/charges" do
requires_body :amount, :currency, :payment_method
respond 200, json: { id: -> { "ch_#{SecureRandom.hex(8)}" } }
end
end
RSpec.configure { |c| c.include FakeStripe.rspec_helpers }
# or, in a Minitest::Test subclass:
include FakeStripe.minitest_helpers
#rspec_helpers requires "http_decoy/rspec" to be loaded; #minitest_helpers requires "http_decoy/minitest" — this method itself pulls in neither, so a Minitest-only project never loads RSpec (and vice versa).
47 48 49 50 51 |
# File 'lib/http_decoy.rb', line 47 def define(name = :default, &) route_map = RouteMap.new route_map.instance_eval(&) Definition.new(name, route_map) end |