0
require 'active_record_helpers'
0
config_file = "tb_test_helpers.conf"
0
@@ -14,7 +14,7 @@ module Test # :nodoc:
0
include TBTestHelpers::Should
0
- # Loads all fixture files
0
+ # Loads all fixture files
(<tt>test/fixtures/*.yml</tt>)0
all_fixtures = Dir.glob(File.join(RAILS_ROOT, "test", "fixtures", "*.yml")).collect do |f|
0
File.basename(f, '.yml').to_sym
0
@@ -24,12 +24,16 @@ module Test # :nodoc:
0
- #
Logs a message, tagged with TESTING: and the name of the calling method.
0
+ #
Prints a message to stdout, tagged with the name of the calling method.
0
puts("#{caller.first}: #{msg}")
0
# Ensures that the number of items in the collection changes
0
+ # assert_difference(User, :count, 1) { User.create }
0
+ # assert_difference(User.packages, :size, 3, true) { User.add_three_packages }
0
+ # Setting reload to true will call <tt>object.reload</tt> after the block (for ActiveRecord associations)
0
def assert_difference(object, method, difference, reload = false, msg = nil)
0
initial_value = object.send(method)
0
@@ -37,12 +41,13 @@ module Test # :nodoc:
0
assert_equal initial_value + difference, object.send(method), (msg || "#{object}##{method} after block")
0
- # Ensures that object.method does not change
0
+ # Ensures that object.method does not change
. See assert_difference for usage.0
def assert_no_difference(object, method, reload = false, msg = nil, &block)
0
assert_difference(object, method, 0, reload, msg, &block)
0
- # asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
0
+ # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
0
+ # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes
0
def assert_same_elements(a1, a2, msg = nil)
0
[:select, :inject, :size].each do |m|
0
[a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
0
@@ -54,27 +59,26 @@ module Test # :nodoc:
0
assert_equal(a1h, a2h, msg)
0
+ # Asserts that the given collection contains item x. If x is a regular expression, ensure that
0
+ # at least one element from the collection matches x.
0
+ # assert_contains(['a', '1'], /\d/) => passes
0
def assert_contains(collection, x, extra_msg = "")
0
collection = [collection] unless collection.is_a?(Array)
0
msg = "#{x} not found in #{collection.to_a.inspect} " + extra_msg
0
when Regexp: assert(collection.detect { |e| e =~ x }, msg)
0
- when String: assert(collection.include?(x), msg)
0
- when Fixnum: assert(collection.include?(x), msg)
0
- raise ArgumentError, "Don't know what to do with #{x}"
0
+ else assert(collection.include?(x), msg)
0
+ # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
0
+ # none of the elements from the collection match x.
0
def assert_does_not_contain(collection, x, extra_msg = "")
0
collection = [collection] unless collection.is_a?(Array)
0
msg = "#{x} found in #{collection.to_a.inspect} " + extra_msg
0
when Regexp: assert(!collection.detect { |e| e =~ x }, msg)
0
- when String: assert(!collection.include?(x), msg)
0
- when Fixnum: assert(!collection.include?(x), msg)
0
- raise ArgumentError, "Don't know what to do with #{x}"
0
+ else assert(!collection.include?(x), msg)
Comments
No one has commented yet.