Replicant is a Rack-based http-endpoint Gem I use in tests along with automation frameworks such as Watir, Selenium, or any framework which does not rely on Net:HTTP, and therefore cannot be mock’d using normal methods. It acts as a real http endpoint that can assert specific requests occurred with the expected post data. It’s not close to being “done”, but go ahead and take a look anyway.

Sample Usage:

require ‘replicant’

before do

@mock_website = Replicant.new
@mock_website.response( :login_page, "/login",
                      %q{ <form name='login' action='/session' method='post'>

<input type=‘text’ name=‘username’/> <input type=‘password’ name=‘password’/> <input type=‘submit’ value=‘Login’ /></form> } )

@mock_website.response( :session_page, "/session", "" )

@mock_website.start

end

after do

@mock_website.stop

end

context “when logging in” do

before do
  # Your code which runs Watir/Selenium/or anything else that doesn't use Net::HTTP here
end

it "accesses the login page" do
  @mock_website.should receive_request_for( :login_page )
end

it "posts to the session page" do
  @mock_website.should receive_post_for( :session_page ).with_data( "user" => "sample_user", "password" => "password" )
end

end