Skip to content

Commit

Permalink
fail with warning when calling private messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed May 30, 2013
1 parent bf15a4d commit 518f6a9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rspec/matchers/built_in/be.rb
Expand Up @@ -135,6 +135,12 @@ def initialize(*args, &block)

def matches?(actual)
@actual = actual

if actual.private_methods.include? predicate
@error_message = "but it's a private method"
return
end

begin
return @result = actual.__send__(predicate, *@args, &@block)
rescue NameError => predicate_missing_error
Expand All @@ -149,11 +155,11 @@ def matches?(actual)
end

def failure_message_for_should
"expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
"expected #{predicate}#{args_to_s} to return true, #{@error_message || "got #{@result.inspect}"}"
end

def failure_message_for_should_not
"expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
"expected #{predicate}#{args_to_s} to return false, #{@error_message || "got #{@result.inspect}"}"
end

def description
Expand Down

0 comments on commit 518f6a9

Please sign in to comment.