[mocha-developer] Expectations on portions of arguments called.

Duncan Beevers duncanbeevers at gmail.com
Tue Sep 11 16:21:51 EDT 2007


I'd like to create expectations on just portions of the arguments a
function takes.

For example, I want to verify that the a certain ActiveRecord
association extension adds an order clause to the find options hash.

Currently I simply check the entire argument structure, something like this

def test_referring_journals_should_order_by_citation_count
article = articles(:highly_cited_article)
Journal.expects(:find).with(
:all,
{
:order => 'citations_count DESC',
:joins => nil,
:select => nil,
:offset => nil,
:conditions => 'article_id = 1'
}
)
article.referring_journals
end

The example is fabricated, but what I'd like to do is something perhaps like:
def test_referring_journals_should_order_by_citation_count
article = articles(:highly_cited_article)
args = []
Journal.expects(:find, args)
article.referring_journals
assert_equal :all, args.shift
options = args.unshift
assert_equal 'citations_count DESC', options[:order]
end

Just kicking the idea around.


More information about the mocha-developer mailing list