This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| f4984945 » | rmm5t | 2008-09-03 | 1 | module Thoughtbot | |
| 2 | module Shoulda | ||||
| 3 | class << self | ||||
| 4 | attr_accessor :expected_exceptions | ||||
| 5 | end | ||||
| 6 | |||||
| 7 | # Enables the core shoulda test suite to test for failure scenarios. For | ||||
| 8 | # example, to ensure that a set of test macros should fail, do this: | ||||
| 9 | # | ||||
| 10 | # should_fail do | ||||
| 11 | # should_require_attributes :comments | ||||
| 12 | # should_protect_attributes :name | ||||
| 13 | # end | ||||
| 14 | def should_fail(&block) | ||||
| 15 | context "should fail when trying to run:" do | ||||
| 16 | Shoulda.expected_exceptions = [Test::Unit::AssertionFailedError] | ||||
| 17 | yield block | ||||
| 18 | Shoulda.expected_exceptions = nil | ||||
| 19 | end | ||||
| 20 | end | ||||
| 21 | |||||
| 22 | class Context | ||||
| 23 | # alias_method_chain hack to allow the should_fail macro to work | ||||
| 24 | def should_with_failure_scenario(name, options = {}, &block) | ||||
| 25 | if Shoulda.expected_exceptions | ||||
| 26 | expected_exceptions = Shoulda.expected_exceptions | ||||
| 27 | failure_block = lambda { assert_raise(*expected_exceptions, &block.bind(self)) } | ||||
| 28 | end | ||||
| 29 | should_without_failure_scenario(name, options, &(failure_block || block)) | ||||
| 30 | end | ||||
| 31 | alias_method_chain :should, :failure_scenario | ||||
| 32 | end | ||||
| 33 | end | ||||
| 34 | end | ||||







