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::Entry
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::MemCacheStore
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::NullStore
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy
- ActiveSupport::Cache::Strategy::LocalCache
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- ActiveSupport::Callbacks
- ActiveSupport::Callbacks::ClassMethods
- ActiveSupport::Concern
- ActiveSupport::Configurable
- ActiveSupport::Configurable::ClassMethods
- ActiveSupport::Configurable::Configuration
- ActiveSupport::Dependencies
- ActiveSupport::Dependencies::ClassCache
- ActiveSupport::Dependencies::WatchStack
- ActiveSupport::Deprecation
- ActiveSupport::DescendantsTracker
- ActiveSupport::Duration
- ActiveSupport::FileUpdateChecker
- ActiveSupport::FileWatcher
- ActiveSupport::FileWatcher::Backend
- ActiveSupport::Gzip
- ActiveSupport::Gzip::Stream
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::Inflector
- ActiveSupport::Inflector::Inflections
- ActiveSupport::InheritableOptions
- ActiveSupport::JSON
- 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::OrderedHash
- ActiveSupport::OrderedOptions
- ActiveSupport::Railtie
- ActiveSupport::Rescuable
- ActiveSupport::Rescuable::ClassMethods
- ActiveSupport::SafeBuffer
- ActiveSupport::SafeBuffer::SafeConcatError
- ActiveSupport::StringInquirer
- ActiveSupport::TaggedLogging
- 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::ForClassicTestUnit
- ActiveSupport::Testing::Performance::ForMiniTest
- ActiveSupport::Testing::Performance::Metrics
- ActiveSupport::Testing::Performance::Metrics::Amount
- ActiveSupport::Testing::Performance::Metrics::Base
- ActiveSupport::Testing::Performance::Metrics::CpuTime
- ActiveSupport::Testing::Performance::Metrics::DigitalInformationUnit
- 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::UserTime
- 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
- Base64
- Benchmark
- BigDecimal
- Class
- Date
- DateTime
- Enumerable
- FalseClass
- File
- Float
- Hash
- Integer
- Kernel
- Module
- NameError
- NilClass
- Numeric
- Process
- QualifiedConstUtils
- Range
- Regexp
- String
- Symbol
- Time
- TrueClass
- URI

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 83
    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 lambda or a list of lambdas can be passed in and evaluated:

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

    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 47
    def assert_difference(expression, difference = 1, message = nil, &block)
      expressions = Array.wrap expression

      exps = expressions.map { |e|
        e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
      }
      before = exps.map { |e| e.call }

      yield

      expressions.zip(exps).each_with_index do |(code, e), i|
        error  = "#{code.inspect} didn't change by #{difference}"
        error  = "#{message}.\n#{error}" if message
        assert_equal(before[i] + difference, e.call, 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 created" do
      post :create, :article => invalid_attributes
    end

    # File lib/active_support/testing/assertions.rb, line 76
    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 91
    def assert_present(object, message=nil)
      message ||= "#{object.inspect} is blank"
      assert object.present?, message
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.