lib/caricature/rspec/integration.rb in caricature-0.7.1 vs lib/caricature/rspec/integration.rb in caricature-0.7.2
- old
+ new
@@ -1,76 +1,153 @@
+module Spec
+ module Adapters
+ module MockFramework
+
+ def setup_mocks_for_rspec
+ # No setup required
+ end
+
+ def verify_mocks_for_rspec
+ end
+
+ def teardown_mocks_for_rspec
+ end
+ end
+ end
+end
+
+module Caricature
+
+ module RSpecMatchers
+
+ class HaveReceived
+ def initialize(expected)
+ @expected = expected
+ @block_args, @error, @args = nil, "", [:any]
+ end
+
+ def matches?(target)
+ @target = target
+
+ veri = @target.did_receive?(@expected).with(*@args)
+ veri.with_block_args(*@block_args) if @block_args
+ result = veri.successful?
+
+ @error = "\n#{veri.error}" unless result
+
+ result
+ end
+
+ def failure_message_for_should
+ "expected #{@target.inspect} to have received #{@expected}" + @error
+ end
+
+ def failure_message_for_should_not
+ "expected #{@target.inspect} not to have received #{@expected}" + @error
+ end
+
+ # constrain this verification to the provided arguments
+ def with(*args)
+ ags = *args
+ @args = args
+ @args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
+ # @callback = b if b
+ self
+ end
+
+ def with_block_args(*args)
+ @block_args = args
+ self
+ end
+
+ # allow any arguments ignore the argument constraint
+ def allow_any_arguments
+ @args = :any
+ self
+ end
+ end
+
+ def have_received(method_name, *args)
+ HaveReceived.new(method_name).with(*args)
+ end
+ end
+end
+
+Spec::Runner.configure do |config|
+ config.include(Caricature::RSpecMatchers)
+end
\ No newline at end of file