Module: RSpec::Arguments::ExampleGroup

Defined in:
lib/rspec/arguments/example_group.rb

Instance Method Summary collapse

Instance Method Details

#arg(name, position = nil, &block) ⇒ Object

TODO support anonymous positional: arg(0) { ‘0’ }

Examples:


describe Thing do
  arg(:first, 0) { '0' }
  arg(:second, 1) { '1' }
  arg(:kw_arg) { 3 }
  arg_block(:blk) { proc { 'body' } }

  # `subject` is now: Thing.new('0', '1', kw_arg: 3, &blk)

  it { is_expect(subject).to be_a(Thing) }
  it { is_expect(subject.perform).to be_nil }
end

Parameters:

  • name (Symbol)

    binds this parameter to the named method ‘name`, implemented by calling `let(name)`.

  • position (Integer, Symbol) (defaults to: nil)

    if an Integer is provided, binds this argument to a the positional argument at position ‘position`, 0 indexed. If Symbol is provided, binds thi argument to the keyword argument `position`.

  • block (Proc)

    value to be used for this argument



28
29
30
# File 'lib/rspec/arguments/example_group.rb', line 28

def arg(name, position = nil, &block)
  _arg(POSITIONAL_ARG, KEYWORD_ARG, name, position, &block)
end

#arg_block(name = '', &block) ⇒ Object

Similar to ‘arg(name, position, &block)`, but binds this argument as the &block argument provided to the instance initializer.



37
38
39
# File 'lib/rspec/arguments/example_group.rb', line 37

def arg_block(name = '', &block)
  _arg_block(BLOCK_ARG, name, &block)
end

#method_arg(name, position = nil, &block) ⇒ Object

Similar to ‘arg(name, position, &block)`, but binds this argument to the described method, instead of described class.



46
47
48
# File 'lib/rspec/arguments/example_group.rb', line 46

def method_arg(name, position = nil, &block)
  _arg(METHOD_POSITIONAL_ARG, METHOD_KEYWORD_ARG, name, position, &block)
end

#method_arg_block(name = '', &block) ⇒ Object

Similar to ‘arg_block(name, &block)`, but binds this argument to the described method, instead of described class.



55
56
57
# File 'lib/rspec/arguments/example_group.rb', line 55

def method_arg_block(name = '', &block)
  _arg_block(METHOD_BLOCK_ARG, name, &block)
end