Created
July 21, 2009 19:19
-
-
Save mattscilipoti/151534 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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