Class: RSpec::Matchers::BuiltIn::StartAndEndWith
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Matchers::BuiltIn::StartAndEndWith
- Defined in:
- lib/rspec/matchers/built_in/start_and_end_with.rb
Constant Summary
Constant Summary
Constants inherited from BaseMatcher
Instance Attribute Summary
Attributes inherited from BaseMatcher
#actual, #expected, #rescued_exception
Instance Method Summary (collapse)
- - (Object) failure_message_for_should
- - (Object) failure_message_for_should_not
-
- (StartAndEndWith) initialize(*expected)
constructor
A new instance of StartAndEndWith.
- - (Boolean) matches?(actual)
Methods inherited from BaseMatcher
#description, #diffable?, #match_unless_raises, #supports_block_expectations?
Methods included from MatchAliases
Methods included from Pretty
#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #to_word, #underscore
Constructor Details
- (StartAndEndWith) initialize(*expected)
A new instance of StartAndEndWith
5 6 7 |
# File 'lib/rspec/matchers/built_in/start_and_end_with.rb', line 5 def initialize(*expected) @expected = expected.length == 1 ? expected.first : expected end |
Instance Method Details
- (Object) failure_message_for_should
18 19 20 |
# File 'lib/rspec/matchers/built_in/start_and_end_with.rb', line 18 def "expected #{@actual.inspect} to #{self.class.name.split('::').last.sub(/With/,'').downcase} with #{@expected.inspect}" end |
- (Object) failure_message_for_should_not
22 23 24 |
# File 'lib/rspec/matchers/built_in/start_and_end_with.rb', line 22 def "expected #{@actual.inspect} not to #{self.class.name.split('::').last.sub(/With/,'').downcase} with #{@expected.inspect}" end |
- (Boolean) matches?(actual)
9 10 11 12 13 14 15 16 |
# File 'lib/rspec/matchers/built_in/start_and_end_with.rb', line 9 def matches?(actual) @actual = actual.respond_to?(:[]) ? actual : (raise ArgumentError.new("#{actual.inspect} does not respond to :[]")) begin @expected.respond_to?(:length) ? subset_matches?(@expected, @actual) : element_matches?(@expected, @actual) rescue ArgumentError raise ArgumentError.new("#{actual.inspect} does not have ordered elements") end end |