Module: ActiveSupport::Testing::Assertions

### Home Classes Methods

### In Files

- lib/active_support/testing/assertions.rb

### Methods

- #assert_blank
- #assert_difference
- #assert_no_difference
- #assert_present

### Class/Module Index

Quicksearch

- ActiveSupport
- ActiveSupport::Autoload
- ActiveSupport::BacktraceCleaner
- ActiveSupport::Base64
- ActiveSupport::BasicObject
- ActiveSupport::Benchmarkable
- ActiveSupport::BufferedLogger
- ActiveSupport::BufferedLogger::Severity
- ActiveSupport::Cache
- ActiveSupport::Cache::CompressedMemCacheStore
- ActiveSupport::Cache::Entry
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::MemCacheStore
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy
- ActiveSupport::Cache::Strategy::LocalCache
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- ActiveSupport::Cache::SynchronizedMemoryStore
- ActiveSupport::Callbacks
- ActiveSupport::Callbacks::Callback
- ActiveSupport::Callbacks::CallbackChain
- ActiveSupport::Callbacks::ClassMethods
- ActiveSupport::Concern
- ActiveSupport::Configurable
- ActiveSupport::Configurable::ClassMethods
- ActiveSupport::Dependencies
- ActiveSupport::Dependencies::Reference
- ActiveSupport::Dependencies::WatchStack
- ActiveSupport::Deprecation
- ActiveSupport::DescendantsTracker
- ActiveSupport::Duration
- ActiveSupport::FileUpdateChecker
- ActiveSupport::Gzip
- ActiveSupport::Gzip::Stream
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::Inflector
- ActiveSupport::Inflector::Inflections
- ActiveSupport::InheritableOptions
- ActiveSupport::JSON
- ActiveSupport::JSON::Backends
- ActiveSupport::JSON::Backends::JSONGem
- ActiveSupport::JSON::Backends::Yajl
- ActiveSupport::JSON::Backends::Yaml
- ActiveSupport::JSON::Encoding
- ActiveSupport::JSON::Encoding::CircularReferenceError
- ActiveSupport::JSON::Encoding::Encoder
- ActiveSupport::JSON::Variable
- ActiveSupport::LogSubscriber
- ActiveSupport::LogSubscriber::TestHelper
- ActiveSupport::LogSubscriber::TestHelper::MockLogger
- ActiveSupport::Memoizable
- ActiveSupport::Memoizable::InstanceMethods
- ActiveSupport::MessageEncryptor
- ActiveSupport::MessageEncryptor::InvalidMessage
- ActiveSupport::MessageVerifier
- ActiveSupport::MessageVerifier::InvalidSignature
- ActiveSupport::Multibyte
- ActiveSupport::Multibyte::Chars
- ActiveSupport::Multibyte::EncodingError
- ActiveSupport::Multibyte::Unicode
- ActiveSupport::Multibyte::Unicode::Codepoint
- ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- ActiveSupport::Notifications
- ActiveSupport::Notifications::Event
- ActiveSupport::Notifications::Fanout
- ActiveSupport::Notifications::Instrumenter
- ActiveSupport::OrderedOptions
- ActiveSupport::Railtie
- ActiveSupport::Rescuable
- ActiveSupport::Rescuable::ClassMethods
- ActiveSupport::SafeBuffer
- ActiveSupport::SecureRandom
- ActiveSupport::StringInquirer
- ActiveSupport::TestCase
- ActiveSupport::Testing
- ActiveSupport::Testing::Assertions
- ActiveSupport::Testing::Declarative
- ActiveSupport::Testing::Isolation
- ActiveSupport::Testing::Isolation::Forking
- ActiveSupport::Testing::Isolation::MiniTest
- ActiveSupport::Testing::Isolation::Subprocess
- ActiveSupport::Testing::Isolation::TestUnit
- ActiveSupport::Testing::Pending
- ActiveSupport::Testing::Performance
- ActiveSupport::Testing::Performance::Benchmarker
- ActiveSupport::Testing::Performance::Metrics
- ActiveSupport::Testing::Performance::Metrics::Base
- ActiveSupport::Testing::Performance::Metrics::CpuTime
- ActiveSupport::Testing::Performance::Metrics::GcRuns
- ActiveSupport::Testing::Performance::Metrics::GcTime
- ActiveSupport::Testing::Performance::Metrics::Memory
- ActiveSupport::Testing::Performance::Metrics::Objects
- ActiveSupport::Testing::Performance::Metrics::ProcessTime
- ActiveSupport::Testing::Performance::Metrics::Time
- ActiveSupport::Testing::Performance::Metrics::WallTime
- ActiveSupport::Testing::Performance::Performer
- ActiveSupport::Testing::Performance::Profiler
- ActiveSupport::Testing::ProxyTestResult
- ActiveSupport::Testing::RemoteError
- ActiveSupport::Testing::SetupAndTeardown
- ActiveSupport::Testing::SetupAndTeardown::ClassMethods
- ActiveSupport::Testing::SetupAndTeardown::ForClassicTestUnit
- ActiveSupport::Testing::SetupAndTeardown::ForMiniTest
- ActiveSupport::TimeWithZone
- ActiveSupport::TimeZone
- ActiveSupport::XmlMini
- ActiveSupport::XmlMini_LibXMLSAX
- ActiveSupport::XmlMini_LibXMLSAX::HashBuilder
- ActiveSupport::XmlMini_NokogiriSAX
- ActiveSupport::XmlMini_NokogiriSAX::HashBuilder
- Test
- Test::Unit
- Test::Unit::Collector
- Test::Unit::Collector::ObjectSpace
- Object
- Object::HashWithIndifferentAccess
- Object::MissingSourceFile
- ERB
- ERB::Util
- I18n
- I18n::Railtie
- LoadError
- LoadError
- Logger
- Logger::SimpleFormatter
- Array
- Benchmark
- BigDecimal
- Class
- Date
- DateTime
- Enumerable
- FalseClass
- File
- Fixnum
- Float
- Hash
- Integer
- Kernel
- Module
- NameError
- NilClass
- Numeric
- Process
- Range
- Regexp
- String
- Symbol
- Time
- TrueClass

No matching classes.

# ActiveSupport::Testing::Assertions

### Public Instance Methods

assert_blank(object, message=nil) click to toggle source

Test if an expression is blank. Passes if object.blank? is true.

    assert_blank [] # => true

    # File lib/active_support/testing/assertions.rb, line 70
    def assert_blank(object, message=nil)
      message ||= "#{object.inspect} is not blank"
      assert object.blank?, message
    end

assert_difference(expression, difference = 1, message = nil, &block) click to toggle source

Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.

    assert_difference 'Article.count' do
      post :create, :article => {...}
    end

An arbitrary expression is passed in and evaluated.

    assert_difference 'assigns(:article).comments(:reload).size' do
      post :create, :comment => {...}
    end

An arbitrary positive or negative difference can be specified. The default is +1.

    assert_difference 'Article.count', -1 do
      post :delete, :id => ...
    end

An array of expressions can also be passed in and evaluated.

    assert_difference [ 'Article.count', 'Post.count' ], +2 do
      post :create, :article => {...}
    end

A error message can be specified.

    assert_difference 'Article.count', -1, "An Article should be destroyed" do
      post :delete, :id => ...
    end

    # File lib/active_support/testing/assertions.rb, line 37
    def assert_difference(expression, difference = 1, message = nil, &block)
      b = block.send(:binding)
      exps = Array.wrap(expression)
      before = exps.map { |e| eval(e, b) }

      yield

      exps.each_with_index do |e, i|
        error = "#{e.inspect} didn't change by #{difference}"
        error = "#{message}.\n#{error}" if message
        assert_equal(before[i] + difference, eval(e, b), error)
      end
    end

assert_no_difference(expression, message = nil, &block) click to toggle source

Assertion that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.

    assert_no_difference 'Article.count' do
      post :create, :article => invalid_attributes
    end

A error message can be specified.

    assert_no_difference 'Article.count', "An Article should not be destroyed" do
      post :create, :article => invalid_attributes
    end

    # File lib/active_support/testing/assertions.rb, line 63
    def assert_no_difference(expression, message = nil, &block)
      assert_difference expression, 0, message, &block
    end

assert_present(object, message=nil) click to toggle source

Test if an expression is not blank. Passes if object.present? is true.

    assert_present {:data => 'x' } # => true

    # File lib/active_support/testing/assertions.rb, line 78
    def assert_present(object, message=nil)
      message ||= "#{object.inspect} is blank"
      assert object.present?, message
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.