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

fix params.inspect for document format. use Hash and Proc soucify. #3

Merged
merged 3 commits into from
May 24, 2012
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
12 changes: 11 additions & 1 deletion lib/rspec/parameterized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def ruby2ruby

def define_cases(arg_names, param_sets, *args, &block)
param_sets.each do |params|
describe(params.inspect, *args) do
pretty_params = [arg_names, params].transpose.map {|t| "#{t[0]}: #{params_inspect(t[1])}"}.join(", ")
describe(pretty_params, *args) do
[arg_names, params].transpose.each do |n|
let(n[0]) { n[1] }
end
Expand All @@ -101,6 +102,15 @@ def define_cases(arg_names, param_sets, *args, &block)
end
end
end

def params_inspect(obj)
begin
obj.class == Proc ? obj.to_raw_source : obj.inspect
rescue Sourcify::NoMatchingProcError
puts "Don't use ->(x) {} format."
return obj.inspect
end
end
end
end

Expand Down
18 changes: 18 additions & 0 deletions spec/parametarized_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
end
end

describe "lambda parameter" do
where(:a, :b, :answer) do
[
[1 , 2 , -> {should == 3}],
[5 , 8 , -> {should == 13}],
[0 , 0 , -> {should == 0}]
]
end

with_them do
subject {a + b}
it "should do additions" do
self.instance_exec(&answer)
end
end
end


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