spec/support/delegate_matcher.rb in liquid-rails-0.1.0 vs spec/support/delegate_matcher.rb in liquid-rails-0.1.1
- old
+ new
@@ -1,9 +1,9 @@
# RSpec matcher to spec delegations.
-# Forked from https://gist.github.com/ssimeonov/5942729 with fixes
-# for arity + custom prefix.
+# Gist Version https://gist.github.com/joeytheman/0fe021821e4c62f552ce
#
+#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:name).to(:author).with_prefix(:any) } # post.any_name
@@ -28,33 +28,33 @@
end
elsif @delegator.respond_to?(@to, true)
unless [0,-1].include?(@delegator.method(@to).arity)
raise "#{@delegator}'s' #{@to} method does not have zero or -1 arity (it expects parameters)"
end
- @delegator.stub(@to).and_return receiver_double(method)
+ allow(@delegator).to receive(@to).and_return(receiver_double(method))
@delegator.send(@method) == :called
else
raise "#{@delegator} does not respond to #{@to}"
end
end
description do
"delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
end
- failure_message_for_should do |text|
+ failure_message do |text|
"expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
end
- failure_message_for_should_not do |text|
+ failure_message_when_negated do |text|
"expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
end
chain(:to) { |receiver| @to = receiver }
- chain(:with_prefix) { |prefix| @prefix = prefix || @to }
+ chain(:with_prefix) { |*prefix| @prefix = prefix.first || @to }
def receiver_double(method)
double('receiver').tap do |receiver|
- receiver.stub(method).and_return :called
+ allow(receiver).to receive(method).and_return(:called)
end
end
end
\ No newline at end of file