Module: RSpec::Parameterized::ExampleGroupMethods
- Included in:
- Core::ExampleGroup
- Defined in:
- lib/rspec/parameterized.rb
Defined Under Namespace
Classes: Parameter
Instance Method Summary collapse
-
#where(*args, &b) ⇒ Object
Set parameters to be bound in specs under this example group.
-
#with_them(*args, &b) ⇒ Object
Use parameters to execute the block.
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) { first.product(*rest) } else set_parameters(args, &b) end 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
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rspec/parameterized.rb', line 64 def with_them(*args, &b) opts = args.last.is_a?(Hash) ? args.pop : {} opts[:caller] = caller unless opts[:caller] args.push(opts) if @parameter.nil? @parameterized_pending_cases ||= [] @parameterized_pending_cases << [args, b] else define_cases(@parameter, *args, &b) end end |