Sha256: d77e716f837bc4538208a81b846018e4ba1bb07fb94fbbc1f37d205be40376f9

Contents?: true

Size: 1.11 KB

Versions: 41

Compression:

Stored size: 1.11 KB

Contents

module Thoughtbot
  module Shoulda
    class << self
      attr_accessor :expected_exceptions
    end

    # 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_require_attributes :comments
    #     should_protect_attributes :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

    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
end

Version data entries

41 entries across 41 versions & 11 rubygems

Version Path
emschwar-shoulda-2.0.6.1 test/fail_macros.rb
francois-shoulda-2.0.5.1 test/fail_macros.rb
francois-shoulda-2.0.5.2 test/fail_macros.rb
gsterndale-warrant-0.2.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.6/test/fail_macros.rb
gsterndale-warrant-0.3.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.6/test/fail_macros.rb
hashrocket-clearance-0.4.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/fail_macros.rb
hashrocket-clearance-0.4.1 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/fail_macros.rb
hashrocket-clearance-0.4.2 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/fail_macros.rb
hashrocket-clearance-0.4.3 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/fail_macros.rb
mattknox-goaloc-0.3.0 lib/goaloc/generators/resources/shoulda/test/fail_macros.rb
mattknox-goaloc-0.4.0 lib/goaloc/generators/resources/shoulda/test/fail_macros.rb
mjankowski-shoulda-2.0.4 test/fail_macros.rb
mjankowski-shoulda-2.0.5 test/fail_macros.rb
rmm5t-shoulda-2.0.2 test/fail_macros.rb
rmm5t-shoulda-2.0.5 test/fail_macros.rb
rmm5t-shoulda-2.0.6 test/fail_macros.rb
technicalpickles-shoulda-2.0.2 test/fail_macros.rb
technicalpickles-shoulda-2.0.6 test/fail_macros.rb
thoughtbot-clearance-0.2.2 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/fail_macros.rb
thoughtbot-clearance-0.2.3 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/fail_macros.rb