Module: RSpec::Given::Extensions
- Defined in:
- lib/rspec/given/extensions.rb
Instance Method Summary collapse
-
#Given(*args, &block) ⇒ Object
Declare a “given” of the current specification.
-
#Given!(name, &block) ⇒ Object
Declare a named given of the current specification.
-
#Scenario(description, &block) ⇒ Object
Declare a scenario to contain Given/When/Then declarations.
-
#When(*args, &block) ⇒ Object
Declare the code that is under test.
Instance Method Details
#Given(*args, &block) ⇒ Object
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.
:call-seq:
Given(:name, &block)
Given(&block)
29 30 31 32 33 34 35 |
# File 'lib/rspec/given/extensions.rb', line 29 def Given(*args,&block) if args.first.is_a?(Symbol) let(args.first, &block) else before(&block) end end |
#Given!(name, &block) ⇒ Object
Declare a named given of the current specification. Similar to the named version of the “Given” command, except that the block is always evaluated.
:call-seq:
Given!(:name) { ... code ... }
43 44 45 |
# File 'lib/rspec/given/extensions.rb', line 43 def Given!(name, &block) let!(name, &block) end |
#Scenario(description, &block) ⇒ Object
Declare a scenario to contain Given/When/Then declarations. A Scenario is essentially an RSpec context, with the additional expectations:
-
There is a single When declaration in a Scenario.
-
Scenarios do not nest.
:call-seq:
Scenario "a scenario description" do ... end
15 16 17 |
# File 'lib/rspec/given/extensions.rb', line 15 def Scenario(description, &block) context(description, &block) end |
#When(*args, &block) ⇒ Object
Declare the code that is under test.
:call-seq:
When(:named_result, &block)
When(&block)
53 54 55 56 57 58 59 |
# File 'lib/rspec/given/extensions.rb', line 53 def When(*args, &block) if args.first.is_a?(Symbol) let!(args.first, &block) else before(&block) end end |