From 6ea671ff9fca7a22126f2348c63eb4ac471eecea Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Sep 2012 13:45:15 +0200 Subject: 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 --- test/test_helper.rb | 3 +++ test/unit/couch_changes_test.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/test_helper.rb create mode 100644 test/unit/couch_changes_test.rb (limited to 'test') 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 -- cgit v1.2.3