Mosquito, for Bug-Free Camping
=============================

A testing helper for those times when you go Camping.

Apply on the face, neck, and any exposed areas such as your Models and Controllers.

== Usage

Make a few files and directories like this:

public/
blog.rb
test/
test_blog.rb
fixtures/
blog_comments.yml
blog_posts.yml
blog_users.yml

Setup +test_blog.rb+ like this:

require 'rubygems'
require 'mosquito'
require File.dirname(__FILE__) + "/../public/blog"

Blog.create
include Blog::Models

class TestBlog < Camping::FunctionalTest

fixtures :blog_posts, :blog_users, :blog_comments

def setup
super
# Do other stuff here
end

def test_index
get
assert_response :success
assert_match_body %r!>blog<!
end

def test_view
get '/view/1'
assert_response :success
assert_match_body %r!The quick fox jumped over the lazy dog!
end

end

# A unit test
class TestPost < Camping::UnitTest

fixtures :blog_posts, :blog_users, :blog_comments

def test_create
post = Post.create( :user_id => 1,
:title => "Title",
:body => "Body")
assert post.valid?
end

def test_assoc
post = Post.find :first
assert_kind_of User, post.user
assert_equal 1, post.user.id
end

end


== Details

Inherit from +Camping::FunctionalTest+ or +Camping::UnitTest+. If you define +setup+, be sure to call +super+ so the parent class can do its thing.

You should also call the +MyApp.create+ method if you have one. You will also need to +include MyApp::Models+ at the top of your test file if you want to use Models in your assertions.

Make fixtures in +test/fixtures+. Remember that Camping models use the name of the mount plus the model name: +blog_posts+ for the +Post+ model.

See +blog_test.rb+ for an example of both Functional and Unit tests.

== Warning: You are Camping, not Rail-riding

Test files start with +test_+ (test_blog.rb). Test classes start with +Test+ (TestBlog).

Model and Controller test classes can both go in the same file.

A Sqlite3 :memory: database is automatically used for tests that require a database.

You can run your tests by executing the test file with Ruby or by running the autotest command with no arguments (from the ZenTest gem).

ruby test/test_blog.rb

or

autotest


== Author

Geoffrey Grosenbach http://nubyonrails.com