Sha256: c64ef7ad7fa635d3b73128bea6d8387b2f34e25d2b5e7acc6999ba184ab9d501

Contents?: true

Size: 1.1 KB

Versions: 19

Compression:

Stored size: 1.1 KB

Contents

module Shoulda
  class << self
    attr_accessor :expected_exceptions
  end

  module ClassMethods
    # Enables the core shoulda test suite to test for failure scenarios.  For
    # example, to ensure that a set of test macros should fail, do this:
    #
    #   should_fail do
    #     should_validate_presence_of :comments
    #     should_not_allow_mass_assignment_of :name
    #   end
    def should_fail(&block)
      context "should fail when trying to run:" do
        Shoulda.expected_exceptions = [Test::Unit::AssertionFailedError]
        yield block
        Shoulda.expected_exceptions = nil
      end
    end
  end

  class Context
    # alias_method_chain hack to allow the should_fail macro to work
    def should_with_failure_scenario(name, options = {}, &block)
      if Shoulda.expected_exceptions
        expected_exceptions = Shoulda.expected_exceptions
        failure_block = lambda { assert_raise(*expected_exceptions, &block.bind(self)) }
      end
      should_without_failure_scenario(name, options, &(failure_block || block))
    end
    alias_method_chain :should, :failure_scenario
  end
end

Version data entries

19 entries across 19 versions & 7 rubygems

Version Path
Flamefork-shoulda-2.10.1 test/fail_macros.rb
Flamefork-shoulda-2.10.2 test/fail_macros.rb
francois-shoulda-2.10.1 test/fail_macros.rb
ratnikov-shoulda-2.9.0.1 test/fail_macros.rb
ratnikov-shoulda-2.9.0.2 test/fail_macros.rb
ratnikov-shoulda-2.9.0.3 test/fail_macros.rb
ratnikov-shoulda-2.9.0 test/fail_macros.rb
rmm5t-shoulda-2.9.1 test/fail_macros.rb
technicalpickles-shoulda-2.10.0 test/fail_macros.rb
thoughtbot-shoulda-2.10.0 test/fail_macros.rb
thoughtbot-shoulda-2.10.1 test/fail_macros.rb
thoughtbot-shoulda-2.9.0 test/fail_macros.rb
thoughtbot-shoulda-2.9.1 test/fail_macros.rb
thoughtbot-shoulda-2.9.2 test/fail_macros.rb
shoulda-2.9.0 test/fail_macros.rb
shoulda-2.9.1 test/fail_macros.rb
shoulda-2.9.2 test/fail_macros.rb
shoulda-2.10.0 test/fail_macros.rb
shoulda-2.10.1 test/fail_macros.rb