0
@@ -8,14 +8,6 @@ module ThoughtBot # :nodoc:
0
- # Loads all fixture files (<tt>test/fixtures/*.yml</tt>)
0
- all_fixtures = Dir.glob(File.join(Test::Unit::TestCase.fixture_path, "*.yml")).collect do |f|
0
- File.basename(f, '.yml').to_sym
0
- fixtures *all_fixtures
0
# Macro that creates a test asserting a change between the return value
0
# of an expression that is run before and after the current setup block
0
# is run. This is similar to Active Support's <tt>assert_difference</tt>
0
@@ -91,21 +83,6 @@ module ThoughtBot # :nodoc:
0
puts("#{caller.first}: #{msg}")
0
- # Asserts that the given object can be saved
0
- # assert_save User.new(params)
0
- assert obj.save, "Errors: #{pretty_error_messages obj}"
0
- # Asserts that the given object is valid
0
- # assert_valid User.new(params)
0
- assert obj.valid?, "Errors: #{pretty_error_messages obj}"
0
# Asserts that an email was delivered. Can take a block that can further
0
# narrow down the types of emails you're expecting.
0
@@ -137,68 +114,6 @@ module ThoughtBot # :nodoc:
0
ActionMailer::Base.deliveries.each { |m| msg << " '#{m.subject}' sent to #{m.to.to_sentence}\n" }
0
assert ActionMailer::Base.deliveries.empty?, msg
0
- # Asserts that an Active Record model validates with the passed
0
- # <tt>value</tt> by making sure the <tt>error_message_to_avoid</tt> is not
0
- # contained within the list of errors for that attribute.
0
- # assert_good_value(User.new, :email, "user@example.com")
0
- # assert_good_value(User.new, :ssn, "123456789", /length/)
0
- # If a class is passed as the first argument, a new object will be
0
- # instantiated before the assertion. If an instance variable exists with
0
- # the same name as the class (underscored), that object will be used
0
- # assert_good_value(User, :email, "user@example.com")
0
- # @product = Product.new(:tangible => false)
0
- # assert_good_value(Product, :price, "0")
0
- def assert_good_value(object_or_klass, attribute, value, error_message_to_avoid = //)
0
- object = get_instance_of(object_or_klass)
0
- object.send("#{attribute}=", value)
0
- assert_does_not_contain(object.errors.on(attribute), error_message_to_avoid, "when set to #{value.inspect}")
0
- # Asserts that an Active Record model invalidates the passed
0
- # <tt>value</tt> by making sure the <tt>error_message_to_expect</tt> is
0
- # contained within the list of errors for that attribute.
0
- # assert_bad_value(User.new, :email, "invalid")
0
- # assert_bad_value(User.new, :ssn, "123", /length/)
0
- # If a class is passed as the first argument, a new object will be
0
- # instantiated before the assertion. If an instance variable exists with
0
- # the same name as the class (underscored), that object will be used
0
- # assert_bad_value(User, :email, "invalid")
0
- # @product = Product.new(:tangible => true)
0
- # assert_bad_value(Product, :price, "0")
0
- def assert_bad_value(object_or_klass, attribute, value, error_message_to_expect = /invalid/)
0
- object = get_instance_of(object_or_klass)
0
- object.send("#{attribute}=", value)
0
- assert !object.valid?, "#{object.class} allowed #{value.inspect} as a value for #{attribute}"
0
- assert object.errors.on(attribute), "There are no errors on #{attribute} after being set to #{value.inspect}"
0
- assert_contains(object.errors.on(attribute), error_message_to_expect, "when set to #{value.inspect}")
0
- def pretty_error_messages(obj)
0
- obj.errors.map { |a, m| "#{a} #{m} (#{obj.send(a).inspect})" }
0
- def get_instance_of(object_or_klass)
0
- if object_or_klass.is_a?(Class)
0
- klass = object_or_klass
0
- instance_variable_get("@#{klass.to_s.underscore}") || klass.new
Comments
No one has commented yet.