summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-09-04 13:45:15 +0200
committerAzul <azul@leap.se>2012-09-04 13:45:15 +0200
commit6ea671ff9fca7a22126f2348c63eb4ac471eecea (patch)
tree6ac518ba9cfbaa0f0019e2bcc38e4ff31b927380
parent0b5b9faea05493b68c6f571b74344a3ddaee1a0c (diff)
added first test - requires mocha
We're using mocha because minitest currently does not allow to yield from mocks. See https://github.com/seattlerb/minitest/issues/160
-rw-r--r--test/test_helper.rb3
-rw-r--r--test/unit/couch_changes_test.rb32
2 files changed, 35 insertions, 0 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000..742e462
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'mocha'
diff --git a/test/unit/couch_changes_test.rb b/test/unit/couch_changes_test.rb
new file mode 100644
index 0000000..2ef5de3
--- /dev/null
+++ b/test/unit/couch_changes_test.rb
@@ -0,0 +1,32 @@
+require 'test_helper'
+require 'lib/couch_changes'
+
+class CouchChangesTest < MiniTest::Unit::TestCase
+
+ LAST_SEQ = 12
+
+ def setup
+ @stream = mock()
+ @changes = CouchChanges.new(@stream)
+ end
+
+ def test_last_seq
+ @stream.expects(:get).
+ with('_changes', {:limit => 1, :descending => true}).
+ yields(:last_seq => LAST_SEQ)
+ assert_equal LAST_SEQ, @changes.last_seq
+ end
+
+ def test_follow
+ stub_entry = {:new => :result}
+ @stream.expects(:get).
+ with('_changes', {:limit => 1, :descending => true}).
+ yields(:last_seq => LAST_SEQ)
+ @stream.expects(:get).
+ with('_changes', {:feed => :continuous, :since => LAST_SEQ}).
+ yields(stub_entry)
+ @changes.follow do |hash|
+ assert_equal stub_entry, hash
+ end
+ end
+end