Skip to content

Instantly share code, notes, and snippets.

@robyurkowski
Created November 23, 2014 13:12
Show Gist options
  • Save robyurkowski/56202e8e1806e6f89272 to your computer and use it in GitHub Desktop.
Save robyurkowski/56202e8e1806e6f89272 to your computer and use it in GitHub Desktop.
private def confirm_failure(error)
self.error = error
run_failure_callbacks
end
private def run_failure_callbacks
# This line fails because on_failure responds_to #call ?!
on_failure.call(self) if on_failure.respond_to?(:call)
end
context "when on_failure is callable" do
it "calls the on_failure callback with itself" do
expect(on_failure).to receive(:call).with(command)
command.call
end
end
context "when on_failure is not callable" do
let(:nil_callback) { double("nil_callback") }
let(:command) { Command.new(on_failure: nil_callback) }
it "does not call on_failure" do
expect(nil_callback).not_to receive(:call)
command.call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment