Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow hash arguments #22

Merged
merged 3 commits into from
Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first, *rest = params.values
first.product(*rest)

I think this is better.
How do you feel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

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