Module: RSpec::Parameterized::ExampleGroupMethods

Included in:
Core::ExampleGroup
Defined in:
lib/rspec/parameterized.rb

Defined Under Namespace

Classes: Parameter

Instance Method Summary collapse

Instance Method Details

#where(*args, &b) ⇒ Object

Set parameters to be bound in specs under this example group.

## Example1

where(:a, :b, :answer) do
  [
    [1 , 2 , 3],
    [5 , 8 , 13],
    [0 , 0 , 0]
  ]
end

## Example2

using RSpec::Parameterized::TableSyntax
where(:a, :b, :answer) do
  1 | 2 | 3 >
  5 | 8 | 13 >
  0 | 0 | 0
end


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rspec/parameterized.rb', line 40

def where(*args, &b)

  if args.size == 1 && args[0].instance_of?(Hash)
    params = args[0]
    first, *rest = params.values

    set_parameters(params.keys, false) {
      first.product(*rest)
    }
  else
    set_parameters(args, false, &b)
  end
end

#where_table(*args, &b) ⇒ Object

Set parameters to be bound in specs under this example group. You can separate fields with | like a cucumber table.

## Example

where_table(:a, :b, :answer) do
  1 | 2 | 3
  5 | 8 | 13
  0 | 0 | 0
end


65
66
67
68
69
# File 'lib/rspec/parameterized.rb', line 65

def where_table(*args, &b)
  warn "deprecated: `where_table` method is deprecated. Please use `using RSpec::Parameterized::TableSyntax`"
  warn caller.first
  set_parameters(args, true, &b)
end

#with_them(*args, &b) ⇒ Object

Use parameters to execute the block. The given block is converted into describes for each parameter set.

## Example

with_them do
  it "should do additions" do
    (a + b).should == answer
  end
end


81
82
83
84
85
86
87
88
# File 'lib/rspec/parameterized.rb', line 81

def with_them(*args, &b)
  if @parameter.nil?
    @parameterized_pending_cases ||= []
    @parameterized_pending_cases << [args, b]
  else
    define_cases(@parameter, *args, &b)
  end
end