Skip to content

Instantly share code, notes, and snippets.

@mattscilipoti
Created July 21, 2009 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattscilipoti/151534 to your computer and use it in GitHub Desktop.
Save mattscilipoti/151534 to your computer and use it in GitHub Desktop.
#usage: Incident.new.should delegate(:batch_code, :to => :incident_batch)
Spec::Matchers.define :delegate do |method_name, options|
match do |delegator|
associated_receiver = options[:to]
expected_value = 'TEST'
receiver = Spec::Mocks::Mock.new(associated_receiver, method_name => expected_value)
##retrieval
delegator.stub!(associated_receiver => receiver)
delegator.send(method_name) == expected_value
# ##assignment
# unless options[:readonly]
# new_value = 'TEST'
# delegator.receiver.should_receive("#{method_name}=").with(new_value)
# delegator.send("#{method_name}=")
# end
end
if __FILE__ == $0
#TODO: why doesn't this work?
puts "Running specs..."
# class Integer
# delegate :to_s, :to => :class
# end
puts "TODO: This should fail since we haven't added the delegate code yet.."
describe 9 do
it {should delegate(:to_s, :to => :class)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment