Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created May 1, 2014 21:56
Show Gist options
  • Save apeckham/0a3a84d0c9c8fd5d06b8 to your computer and use it in GitHub Desktop.
Save apeckham/0a3a84d0c9c8fd5d06b8 to your computer and use it in GitHub Desktop.
passing callables to shared examples in rspec
require 'spec_helper'
shared_examples_for 'shared examples with proc' do |param1, param2|
it do
expect(param1).to eq param2.call
end
end
def true_method
true
end
describe 'test' do
it_behaves_like 'shared examples with proc', true, (-> { true })
it_behaves_like 'shared examples with proc', true, (lambda { true })
it_behaves_like 'shared examples with proc', true, (Proc.new { true })
it_behaves_like 'shared examples with proc', true, method(:true_method)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment