tests for controller functionality
test data
tests for helper methods
tests for multiple controller interaction
tests for mailers
tests for models
tests for controller functionality
tests for models
default configuration to run all tests
test data
<% 100.times do |n| %>
book_<%= n %>:
id: <%= n %>
title: <%= "Book #{n}" %>
author: <%= "Author #{n % 10}" %>
<% end %>
test "should have same title" do
assert_equal "Book 3", books(:book_3).title, "Title wrong!"
end
test "should load 100 books" do
assert_equal(100, Book.count, "Didn't load 100 books")
end
# Running:
F.
Finished in 0.031153s, 64.1993 runs/s, 64.1993 assertions/s.
1) Failure:
BookTest#test_should_have_same_title [/PATH_TO_APP/test_app/test/models/book_test.rb:5]:
Title wrong!.
Expected: "Harry Potter"
Actual: "Book 3"
2 runs, 2 assertions, 1 failures, 0 errors, 0 skips
2 tests
require 'test_helper'
class BooksControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:books)
end
end
Simulates GET request on action "index"
Makes sure request worked
Checks that @books was assigned