aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2009-12-04 02:14:31 +0000
committerFrancis Irving <francis@mysociety.org>2009-12-04 02:14:31 +0000
commit1a5da559986b874c2ddcd5bf9a1940e947d784bc (patch)
treeb39a86659e3ba298cba247db0f1f7dcd792195c2 /spec/lib
parent130d32b875b448e8f2aadfba9c0dcd2923f62fa7 (diff)
Make IO.popen mocking not break later calls to popen
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/sendmail_return_path_spec.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb
index d279c5a0b..644372256 100644
--- a/spec/lib/sendmail_return_path_spec.rb
+++ b/spec/lib/sendmail_return_path_spec.rb
@@ -57,13 +57,17 @@ describe "when sending email with an altered return path" do
end
# By default, we can't stub popen, presumably because it is a builtin written in C.
- # Replace it entirely with a dummy function that just returns nil, so we can stub it.
+ # Replace it entirely with a normal method that just calls the C one, so we can stub it -
+ # this leaves IO working afterwards (for other tests that run in the same instance).
def with_stub_popen()
- old_popen = IO.method(:popen).unbind
- IO.class_eval "def self.popen(a, b); nil; end"
- yield
- ensure
- old_popen.bind(IO)
+ IO.class_eval "@orig_popen = self.method(:popen); def self.popen(a, b, &c); @orig_popen.call(a, b, &c); end"
+ begin
+ yield
+ ensure
+ # in theory would undo the popen alterations and return IO to a pristine state, but
+ # don't know how to (much fiddling with alias bind and the like didn't help). It
+ # doesn't matter - the new popen should behave just the same.
+ end
end