lostisland / hurley

DEAD project, don't use
MIT License
177 stars 21 forks source link

add the concept of an expiring test stub #26

Closed technoweenie closed 9 years ago

technoweenie commented 9 years ago

Fixes #18. You can now define multiple stubs for a URL in your tests. Multiple calls to the stub will call each URL in succession. Any stubs defined just once never expire, unless specifically configured to do so.

client = Hurley::Client.new "https://example.com"
client.connection = Hurley::Test.new do |stubs|
  # this stub will return 1, 2, and then 3
  stubs.get("/next") do |req|
    [200, {}, "1"]
  end
  stubs.get("/next") do |req|
    [200, {}, "2"]
  end
  stubs.get("/next") do |req|
    [200, {}, "3"]
  end

  # this stub always returns status 405
  stubs.post("/next") do |req|
    [405, {}, "Method not Allowed"]
  end

  # this stub only works once
  stubs.delete("/a", expires: true) do |req|
    [200, {}, "ok"]
  end
end

This doesn't work on ruby < 2.0 yet.