Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created September 15, 2010 18:16
Show Gist options
  • Save mitchellh/581174 to your computer and use it in GitHub Desktop.
Save mitchellh/581174 to your computer and use it in GitHub Desktop.
From 55977ea902c27c18ee0bcca94b0cf0bb8993b02f Mon Sep 17 00:00:00 2001
From: Mitchell Hashimoto <mitchell.hashimoto@gmail.com>
Date: Wed, 15 Sep 2010 12:14:59 -0600
Subject: [PATCH] Mocha integration example for mocking and stubbing
---
examples/mocha_integration.rb | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
create mode 100644 examples/mocha_integration.rb
diff --git a/examples/mocha_integration.rb b/examples/mocha_integration.rb
new file mode 100644
index 0000000..21a58fa
--- /dev/null
+++ b/examples/mocha_integration.rb
@@ -0,0 +1,31 @@
+require "protest"
+require "mocha"
+
+class Protest::TestCase
+ include Mocha::API
+
+ alias :original_run :run
+ def run(report)
+ original_run(report)
+ mocha_verify
+ ensure
+ mocha_teardown
+ end
+end
+
+Protest.describe("An expectation") do
+ setup do
+ @m = mock(:object)
+ end
+
+ # An example failure
+ it "should call the mock" do
+ @m.expects(:call).once
+ end
+
+ # An example success
+ it "should call the mock, really" do
+ @m.expects(:call).once
+ @m.call
+ end
+end
--
1.7.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment