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,
unless
   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
 end

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.

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


Code:
http://github.com/gnufied/troll



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

http://gnufied.org

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to