Skip to content

Commit

Permalink
Merge pull request #22 from takkanm/allow_hash_arguments
Browse files Browse the repository at this point in the history
allow hash arguments
  • Loading branch information
joker1007 committed Sep 17, 2015
2 parents 115e9d5 + 84cb4e8 commit 92344e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/rspec/parameterized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ def initialize(arg_names, table_format, &block)
# end
#
def where(*args, &b)
set_parameters(args, false, &b)

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

set_parameters(params.keys, false) {
rest_values = rest.map {|k| params[k] }
first.product(*rest)
}
else
set_parameters(args, false, &b)
end
end

# Set parameters to be bound in specs under this example group.
Expand Down
10 changes: 10 additions & 0 deletions spec/parametarized_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
end
end

describe "Hash arguments" do
where(a: [1, 3], b: [5, 7, 9], c: [2, 4])

with_them do
it "sums is even" do
expect(a + b + c).to be_even
end
end
end

describe "table separated with pipe" do
where_table(:a, :b, :answer) do
1 | 2 | 3
Expand Down

0 comments on commit 92344e1

Please sign in to comment.