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

Would be awesome to use proc as a message #120

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rspec/expectations/fail_with.rb
Expand Up @@ -19,6 +19,10 @@ def fail_with(message, expected=nil, actual=nil)
"appropriate failure_message_for_* method to return a string?"
end

if message.is_a? Proc
message = message.call
end

if actual && expected
if all_strings?(actual, expected)
if any_multiline_strings?(actual, expected)
Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/expectations/fail_with_spec.rb
Expand Up @@ -66,5 +66,11 @@
RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
}.should fail_with("the message")
end

it "accept message as Proc" do
lambda {
RSpec::Expectations.fail_with lambda { "the message"}
}.should fail_with("the message")
end
end