Skip to content

Commit

Permalink
Imported stubs should be kept even when Mimic is cleared.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Redpath committed Jan 18, 2011
1 parent 23c5047 commit bf8d0cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions features/stubbing_requests_from_a_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ Feature: Stubbing requests from a file
"""
When I make an HTTP GET request to "http://localhost:11988/ping"
Then I should receive an HTTP 200 response with a body matching "pong"

Scenario: Stubbed requests from a file persist even when Mimic is cleared
Given the file "/tmp/test.mimic" exists with the contents:
"""
get("/ping") { "pong" }
"""
And I have a mimic specification with:
"""
Mimic.mimic(:port => 11988) do
import "/tmp/test.mimic"
end
Mimic.reset_all!
"""
When I make an HTTP GET request to "http://localhost:11988/ping"
Then I should receive an HTTP 200 response with a body matching "pong"

5 changes: 4 additions & 1 deletion lib/mimic/fake_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FakeHost
def initialize(hostname, remote_configuration_path = nil)
@hostname = hostname
@remote_configuration_path = remote_configuration_path
@imports = []
clear
build_url_map!
end
Expand All @@ -32,8 +33,9 @@ def head(path, &block)
request("HEAD", path, &block)
end

def import(path)
def import(path, replay = false)
if File.exists?(path)
@imports << path unless replay
instance_eval(File.read(path))
end
end
Expand All @@ -49,6 +51,7 @@ def clear
@app.not_found do
[404, {}, ""]
end
@imports.each { |file| import(file, true) }
end

def inspect
Expand Down

0 comments on commit bf8d0cb

Please sign in to comment.