First, you should usually use $stderr, not STDERR.
module Utils
extend self
def blather(msg)
msg = "=== " + msg
$stderr.puts(msg)
Rails.logger.debug(msg)
end
end
To answer your question, you can do the following in RSpec:
describe Utils do
context "blather" do
it "should print to stderr" do
$stderr.should_receive(:puts).with("=== zoo")
Utils.blather("zoo")
end
end
end
$stderr.should_receive. $stderr , , .