module Given::Assertions

Constants

AssertError
PostconditionError
PreconditionError

Public Class Methods

asserts?() click to toggle source
   # File lib/given/assertions.rb
19 def self.asserts?
20   @enable_asserts
21 end
enable_all(enabled=true) click to toggle source
   # File lib/given/assertions.rb
31 def self.enable_all(enabled=true)
32   enable_asserts enabled
33   enable_preconditions enabled
34   enable_postconditions enabled
35 end
enable_asserts(enabled=true) click to toggle source
  # File lib/given/assertions.rb
7 def self.enable_asserts(enabled=true)
8   @enable_asserts = enabled
9 end
enable_postconditions(enabled=true) click to toggle source
   # File lib/given/assertions.rb
15 def self.enable_postconditions(enabled=true)
16   @enable_postconditions = enabled
17 end
enable_preconditions(enabled=true) click to toggle source
   # File lib/given/assertions.rb
11 def self.enable_preconditions(enabled=true)
12   @enable_preconditions = enabled
13 end
postconditions?() click to toggle source
   # File lib/given/assertions.rb
27 def self.postconditions?
28   @enable_postconditions
29 end
preconditions?() click to toggle source
   # File lib/given/assertions.rb
23 def self.preconditions?
24   @enable_preconditions
25 end

Public Instance Methods

Assert(&block) click to toggle source
   # File lib/given/assertions.rb
43 def Assert(&block)
44   return nil unless Given::Assertions.asserts?
45   unless block.call
46     na = Given::NaturalAssertion.new("Assert", block, self, Given::LineExtractor.new)
47     raise AssertError, na.message
48   end
49 end
Postcondition(&block) click to toggle source
   # File lib/given/assertions.rb
61 def Postcondition(&block)
62   return nil unless Given::Assertions.preconditions?
63   if block.call
64     true
65   else
66     na = Given::NaturalAssertion.new("Postcondition", block, self, Given::LineExtractor.new)
67     raise PostconditionError, na.message
68   end
69 end
Precondition(&block) click to toggle source
   # File lib/given/assertions.rb
51 def Precondition(&block)
52   return nil unless Given::Assertions.preconditions?
53   if block.call
54     true
55   else
56     na = Given::NaturalAssertion.new("Precondition", block, self, Given::LineExtractor.new)
57     raise PreconditionError, na.message
58   end
59 end