Created
June 9, 2011 01:35
-
-
Save nelsonenzo/1015857 to your computer and use it in GitHub Desktop.
Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test definition can be written as such | |
test "that a new user has a valid name" do | |
#some test stuff | |
end | |
You would use ActiveSupport::TestCase as the parent class of any of your Rails tests. | |
Inside a Test, you are generally trying to do 4 things: | |
1) Set up the data. | |
2) Perform the action that triggers the behavior being tested (i.e. - call to a controller method or call to a model method). | |
3) Perform one or more assertions to verify that the behavior triggered in the previous step had the expected results. | |
4) Tear down any data structures that need to be removed before the next test runs. (often handled by Rails). | |
Test::Unit defines ~20 different methods that assert the presence or absence of a particular state | |
assert_equal "the expected value", @theActualValue | |
assert_in_delta(expected, actual, delta) | |
assert_instance_of(klass, object) | |
assert_kind_of(klass, object) | |
assert_match(pattern,string) | |
assert_no_match(pattern,string) | |
assert_operator(left,operator,right) | |
assert_nil(object) | |
assert_not_nil(object) | |
assert_raise(*args,&block) | |
assert_nothing_raised(*args,&block) | |
assert_same(expected, actual) - checks actual object equality | |
assert_not_same(expected, actual) | |
assert_respond_to(object,method) | |
assert_send(array) | |
assert_throws(symbol,&block) | |
assert_nothing_thrown(&block) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment