module Given::ClassExtensions
Provide run-time class methods to support Given
infrastructure. Methods that begin with Gvn are considered private and implementation specific, and should not be directly called by appliation code. Other methods without the Gvn prefix are public and intended for use by the application developer.
(Note that private class methods are prefixed with Gvn and private instance methods are prefixed with gvn).
Public Instance Methods
Provide an assertion that shares setup with a peer Then
command.
# File lib/given/extensions.rb 268 def And(&block) 269 fail "And defined without a Then" unless _Gvn_context_info[:then_defined] 270 _Gvn_and_blocks << block 271 end
Declare a “given” of the current specification. If the given is named, the block will be lazily evaluated the first time the given is mentioned by name in the specification. If the given is unnamed, the block is evaluated for side effects every time the specification is executed.
# File lib/given/extensions.rb 187 def Given(*args, &block) 188 if args.first.is_a?(Symbol) 189 let(args.first, &block) 190 else 191 _Gvn_givens << block 192 end 193 end
Declare a named given of the current specification. Similar to the named version of the “Given” command, except that the block is always evaluated.
# File lib/given/extensions.rb 202 def Given!(name, &block) 203 let(name, &block) 204 _Gvn_givens << _Gvn_trigger_given(name) 205 end
Establish an invariant that must be true for all Then
blocks in the current (and nested) scopes.
# File lib/given/extensions.rb 263 def Invariant(&block) 264 _Gvn_invariants << block 265 end
Provide an assertion about the specification.
Then
supplies an assertion that should be true after all the Given
and When
blocks have been run. All invariants in scope will be checked before the Then
block is run.
# File lib/given/extensions.rb 250 def Then(*metadata, &block) 251 opts = metadata.last 252 opts = {} unless opts.is_a? Hash 253 on_eval = opts.delete(:on_eval) || "_gvn_then" 254 file, line = Given.location_of(block) 255 description = _Gvn_lines.line(file, line) unless Given.source_caching_disabled 256 cmd = description ? "it(description, *metadata)" : "specify(*metadata)" 257 eval %{#{cmd} do #{on_eval}(&block) end}, binding, file, line 258 _Gvn_context_info[:then_defined] = true 259 end
Declare the code that is under test.
# File lib/given/extensions.rb 213 def When(*args, &block) 214 if args.first.is_a?(Symbol) 215 _Gvn_when_actions_with_capture(args.first, block) 216 else 217 _Gvn_when_actions(block) 218 end 219 end
Configure the use of natural assertions in this context.
# File lib/given/extensions.rb 274 def use_natural_assertions(enabled=true) 275 _Gvn_context_info[:natural_assertions_enabled] = enabled 276 end