Created
December 4, 2008 07:02
-
-
Save janmejay/31865 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ActionView::Base.class_eval do | |
$render_expectation_matcher_loaded = true | |
def set_render_expectation options_map | |
options_map.reverse_merge!(:with => [], :times => 1, :return => nil) | |
_get_expectation_map[options_map[:with]] = options_map.except(:with).merge(:expected_times => options_map[:times]) | |
end | |
def _get_expectation_map | |
self.instance_variable_get('@render_expectations') || self.instance_variable_set('@render_expectations', {}) | |
end | |
def render_with_expectation_matcher *args | |
expectation = _get_expectation_map[_get_expectation_map.keys.find {|key| key == args }] #hashcode of identical hashes is differnet. Comparision by identity is not allowed... if we upgrade to 1.9... someone delete this.... -jj | |
return render_without_expectation_matcher(*args) unless expectation | |
expectation[:times] -= 1 | |
return expectation[:return] | |
end | |
def assert_render_expectation_satisfied! | |
_get_expectation_map.each do |with, expectation| | |
(expectation[:times] == 0) && next | |
raise "Render expectation with arguments='#{with.inspect}' didn't pass." + | |
"It was supposed to be called #{expectation[:expected_times]} time(s), but was called #{expectation[:expected_times] - expectation[:times]} time(s)." | |
end | |
end | |
alias_method_chain :render, :expectation_matcher | |
end unless $render_expectation_matcher_loaded |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment