Skip to content
Browse files

Removed 'calls_hook' custom matcher. Instead of it, Mock is used.

  • Loading branch information...
1 parent 5affde6 commit b728362f6ed0a8ae19dc93c03aa49f490afd71fe Kaoru Kobo committed
Showing with 24 additions and 63 deletions.
  1. +24 −22 spec/rhook_spec.rb
  2. +0 −41 spec/spec_helper.rb
View
46 spec/rhook_spec.rb
@@ -234,29 +234,31 @@ def invocation_object_target(*args, &block)
end
- lambda { |called|
- t = Target.new
- t._rhook.bind(:invocation_object_target) { |inv|
- # first hook
- called.yes
- inv.call()
- inv.returned.should == :returned_value
+ m = mock
+ m.should_receive(:second).once.ordered
+ m.should_receive(:first).once.ordered
+
+ t = Target.new
+ t._rhook.bind(:invocation_object_target) { |inv|
+ # first hook
+ m.first
+ inv.call()
+ inv.returned.should == :returned_value
:returned_value_hooked
- }
- t._rhook.bind(:invocation_object_target) { |inv|
- # second hook
- called.yes
- inv.args.should == args
- inv.block.should == block
- inv.hint[:hintkey].should == :hintval
- inv.receiver.should == t
- inv.target.should == t
- inv.returned.should be_nil
- inv.call()
- inv.returned.should == :returned_value_hooked
- }
- t.invocation_object(*args, &block)
- }.should calls_hook(:times => 2)
+ }
+ t._rhook.bind(:invocation_object_target) { |inv|
+ # second hook
+ m.second
+ inv.args.should == args
+ inv.block.should == block
+ inv.hint[:hintkey].should == :hintval
+ inv.receiver.should == t
+ inv.target.should == t
+ inv.returned.should be_nil
+ inv.call()
+ inv.returned.should == :returned_value_hooked
+ }
+ t.invocation_object(*args, &block)
end
end
# ========================================================================
View
41 spec/spec_helper.rb
@@ -11,44 +11,3 @@
end
-# ========================================================================
-# Defines custom matcher to test the hook was called.
-
-module ::Spec::Matchers
- class HookCalledMatcher
- def initialize(opt)
- @times = opt[:times]
- @count = 0
- end
-
- def yes
- @count += 1
- end
-
- def matches?(block)
- block.call(self)
- if @times
- begin
- @count.should == @times
- rescue
- @times_msg = " (Exactly called count: #{$!})"
- false
- end
- else
- @count > 0
- end
- end
-
- def failure_message
- "Expected the hook to be called.#{@times_msg}"
- end
-
- def negative_failure_message
- "Expected the hook not to be called.#{@times_msg}"
- end
- end
-
- def calls_hook(opt = {})
- HookCalledMatcher.new(opt)
- end
-end

0 comments on commit b728362

Please sign in to comment.
Something went wrong with that request. Please try again.