@api private Provides the implementation of `be_<predicate>`. Not intended to be instantiated directly.
# File lib/rspec/matchers/built_in/be.rb, line 182 def initialize(*args, &block) @expected = parse_expected(args.shift) @args = args @block = block end
@api private @return [String]
# File lib/rspec/matchers/built_in/be.rb, line 214 def description "#{prefix_to_sentence}#{expected_to_sentence}#{args_to_sentence}" end
# File lib/rspec/matchers/built_in/be.rb, line 194 def does_not_match?(actual, &block) @actual = actual @block ||= block predicate_accessible? && !predicate_matches? end
@api private @return [String]
# File lib/rspec/matchers/built_in/be.rb, line 202 def failure_message failure_message_expecting(true) end
@api private @return [String]
# File lib/rspec/matchers/built_in/be.rb, line 208 def failure_message_when_negated failure_message_expecting(false) end
# File lib/rspec/matchers/built_in/be.rb, line 188 def matches?(actual, &block) @actual = actual @block ||= block predicate_accessible? && predicate_matches? end
# File lib/rspec/matchers/built_in/be.rb, line 265 def failure_message_expecting(value) validity_message || "expected `#{@actual.inspect}.#{predicate}#{args_to_s}` to return #{value}, got #{@predicate_matches.inspect}" end
# File lib/rspec/matchers/built_in/be.rb, line 252 def parse_expected(expected) @prefix, expected = prefix_and_expected(expected) expected end
# File lib/rspec/matchers/built_in/be.rb, line 244 def predicate :"#{@expected}?" end
# File lib/rspec/matchers/built_in/be.rb, line 220 def predicate_accessible? !private_predicate? && predicate_exists? end
# File lib/rspec/matchers/built_in/be.rb, line 235 def predicate_exists? actual.respond_to?(predicate) || actual.respond_to?(present_tense_predicate) end
# File lib/rspec/matchers/built_in/be.rb, line 239 def predicate_matches? method_name = actual.respond_to?(predicate) ? predicate : present_tense_predicate @predicate_matches = actual.__send__(method_name, *@args, &@block) end
# File lib/rspec/matchers/built_in/be.rb, line 257 def prefix_and_expected(symbol) Matchers::BE_PREDICATE_REGEX.match(symbol.to_s).captures.compact end
# File lib/rspec/matchers/built_in/be.rb, line 261 def prefix_to_sentence split_words(@prefix) end
# File lib/rspec/matchers/built_in/be.rb, line 248 def present_tense_predicate :"#{@expected}s?" end
# File lib/rspec/matchers/built_in/be.rb, line 226 def private_predicate? @actual.private_methods.include? predicate.to_s end
# File lib/rspec/matchers/built_in/be.rb, line 270 def validity_message if private_predicate? "expected #{@actual} to respond to `#{predicate}` but `#{predicate}` is a private method" elsif !predicate_exists? "expected #{@actual} to respond to `#{predicate}`" end end