[ANN] Troll - A Rails plugin for making webservice mocking easier

Hi Folks,

Troll trumps your existing ActiveResource mocking libraries like
inbuilt HttpMock,Fakeweb or Webmock out of water. With Troll,
ActiveResource mocking just works, some of its features:

  1. Don’t need to mock calls at Net::HTTP level (which webmock,fakeweb
    do). Really, we don’t care what HTTP library ActiveResource uses,
    fakeweb and webmock bring additional complexity because of plumbing at
    that level.

  2. Matches based on body should be supported and work (I am talking to
    you fakeweb).

  3. How many times a particular mock can be matched should be
    supported. Specifying ‘-1’ as times will match the mock forevever,
    another mock is inserted after this one.

  4. If no match is found or if number of times the mock should be used
    has exceeded the predefined count,actual webservice call should be
    made. This has been my pet peeve with WebMock and inbuilt httpmock,
    they insist on taking over entire stack. Give us a break, at times we
    WANT an actual webservice call made, that makes debugging easier.

  5. The most recent mock should be applied first.

An example to make things clearer:

Including the Module in ActiveSupport::TestCase (test_helper.rb),

class ActiveSupport::TestCase
include Troll::TestUnitStuff

and setup block of your tests:

http_mock(:post, “/articles.xml”,{:times => 1,:body => /frodo/},{:body
=> fixture_file(‘article_1.xml’), :status => 201})

More can be found in test directory of plugin and README.


  1. Works only with Test/Unit currently. Patches welcome for RSpec
  2. Works with Rails 2.3.x only currently, work is underway for Rails3


Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.