Module: Given::Assertions
- Defined in:
- lib/given/assertions.rb
Constant Summary collapse
- AssertError =
Class.new(StandardError)
- PreconditionError =
Class.new(AssertError)
- PostconditionError =
Class.new(AssertError)
Class Method Summary collapse
- .asserts? ⇒ Boolean
- .enable_all(enabled = true) ⇒ Object
- .enable_asserts(enabled = true) ⇒ Object
- .enable_postconditions(enabled = true) ⇒ Object
- .enable_preconditions(enabled = true) ⇒ Object
- .postconditions? ⇒ Boolean
- .preconditions? ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.asserts? ⇒ Boolean
19 20 21 |
# File 'lib/given/assertions.rb', line 19 def self.asserts? @enable_asserts end |
.enable_all(enabled = true) ⇒ Object
31 32 33 34 35 |
# File 'lib/given/assertions.rb', line 31 def self.enable_all(enabled=true) enable_asserts enabled enable_preconditions enabled enable_postconditions enabled end |
.enable_asserts(enabled = true) ⇒ Object
7 8 9 |
# File 'lib/given/assertions.rb', line 7 def self.enable_asserts(enabled=true) @enable_asserts = enabled end |
.enable_postconditions(enabled = true) ⇒ Object
15 16 17 |
# File 'lib/given/assertions.rb', line 15 def self.enable_postconditions(enabled=true) @enable_postconditions = enabled end |
.enable_preconditions(enabled = true) ⇒ Object
11 12 13 |
# File 'lib/given/assertions.rb', line 11 def self.enable_preconditions(enabled=true) @enable_preconditions = enabled end |
.postconditions? ⇒ Boolean
27 28 29 |
# File 'lib/given/assertions.rb', line 27 def self.postconditions? @enable_postconditions end |
.preconditions? ⇒ Boolean
23 24 25 |
# File 'lib/given/assertions.rb', line 23 def self.preconditions? @enable_preconditions end |
Instance Method Details
#Assert(&block) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/given/assertions.rb', line 43 def Assert(&block) return nil unless Given::Assertions.asserts? unless block.call na = Given::NaturalAssertion.new("Assert", block, self, Given::LineExtractor.new) raise AssertError, na. end end |
#Postcondition(&block) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/given/assertions.rb', line 61 def Postcondition(&block) return nil unless Given::Assertions.preconditions? if block.call true else na = Given::NaturalAssertion.new("Postcondition", block, self, Given::LineExtractor.new) raise PostconditionError, na. end end |
#Precondition(&block) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/given/assertions.rb', line 51 def Precondition(&block) return nil unless Given::Assertions.preconditions? if block.call true else na = Given::NaturalAssertion.new("Precondition", block, self, Given::LineExtractor.new) raise PreconditionError, na. end end |