Sha256: ae77d67e46f65bedfe948d4d5ac0f183c782bb86025ead3ef2e8ea8c5625f9f7
Contents?: true
Size: 1.15 KB
Versions: 263
Compression:
Stored size: 1.15 KB
Contents
# RSpec matcher to spec delegations. # # Usage: # # describe Post do # it { should delegate(:name).to(:author).with_prefix } # post.author_name # it { should delegate(:month).to(:created_at) } # it { should delegate(:year).to(:created_at) } # end RSpec::Matchers.define :delegate do |method| match do |delegator| @method = @prefix ? :"#{@to}_#{method}" : method @delegator = delegator begin @delegator.send(@to) rescue NoMethodError raise "#{@delegator} does not respond to #{@to}!" end @delegator.stub(@to => double('receiver')) @delegator.send(@to).stub(method => :called) @delegator.send(@method) == :called end description do "delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}" end failure_message_for_should do |text| "expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}" end failure_message_for_should_not do |text| "expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}" end chain(:to) { |receiver| @to = receiver } chain(:with_prefix) { @prefix = true } end
Version data entries
263 entries across 263 versions & 1 rubygems