Skip to content

gnufied/troll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Troll
=====

Troll is yet another ActiveResource mocking library. I created troll with following goals:

1. Don't need to mock calls at Net::HTTP level (which webmock,fakeweb do).
2. Matches based on body should be supported.
3. How many times a particular mock can be matched should be supported. If supplying '-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.
5. The most recent mock should be applied first.



Example
=======
    class ActiveSupport::TestCase
      include Troll::TestUnitStuff
    end

    require File.dirname(__FILE__) + '/../test_helper'

    class ArticleTest < ActiveSupport::TestCase
      def setup
        # Use this mock forever
        http_mock(:get,'/articles/new.xml', {:times => -1 }, {:body => fixture_file('new_article.xml'),:status => 201})
      end
      context "Save valid article" do
        setup do
          # Use this mock 1 time if body and url matches
          http_mock(:post, "/articles.xml",{:times => 1,:body => /hemant/},{:body => fixture_file('article_1.xml'), :status => 201})
	  # Use this mock 1 time if body and url matches
          http_mock(:post,"/articles.xml",{:times => 1, :body => /foo/},{:status => 422})
    
          @article = Article.new(:title => "hemant", :content => "Kumar")
          @article.save
          @invalid_article = Article.new(:title => "foo")
          @invalid_article.save
        end
    
        should "save the article" do
          assert @article.id
          assert 'hemant', @article.title
          assert !@invalid_article.id
        end
      end
    
      context "should get single article" do
        setup do
          http_mock(:get,"/articles/1.xml",{:times => 1},{:status => 200, :body => fixture_file('article_1.xml')})
          @article = Article.find(1)
        end
        should "not be nil" do
          assert @article
        end
      end
    
    end
    
    

About

Tiny ActiveResource mocking plugin and library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages