diff --git a/spec/webmock_spec.cr b/spec/webmock_spec.cr index 12f4182..dec468d 100644 --- a/spec/webmock_spec.cr +++ b/spec/webmock_spec.cr @@ -216,6 +216,15 @@ describe WebMock do end end + it "uses the most recently called stub of the same url" do + WebMock.wrap do + WebMock.stub(:get, "www.example.com").to_return(body: "unu") + WebMock.stub(:get, "www.example.com").to_return(body: "du") + + HTTP::Client.get("http://www.example.com").body.should eq("du") + end + end + it "stubs indefinitely" do WebMock.wrap do WebMock.stub(:get, "www.example.com").to_return(body: "unu") diff --git a/src/webmock/stub_registry.cr b/src/webmock/stub_registry.cr index 789660c..b56cd1d 100644 --- a/src/webmock/stub_registry.cr +++ b/src/webmock/stub_registry.cr @@ -5,7 +5,7 @@ struct WebMock::StubRegistry def stub(method, uri) stub = Stub.new(method, uri) - @stubs << stub + @stubs.unshift(stub) stub end