Module: RSpec::Matchers::DSL
- Included in:
- Diff::LCS::SpecHelper::Matchers, RSpec::Matchers
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/dsl.rb
Overview
Defines the custom matcher DSL.
Defined Under Namespace
Modules: DefaultImplementations, Macros Classes: Matcher
Instance Method Summary collapse
-
#alias_matcher(new_name, old_name, options = {}) {|String| ... } ⇒ Object
Defines a matcher alias.
-
#define(name) {|Object| ... } ⇒ Object
(also: #matcher)
Defines a custom matcher.
-
#define_negated_matcher(negated_name, base_name) {|String| ... } ⇒ Object
Defines a negated matcher.
Instance Method Details
#alias_matcher(new_name, old_name, options = {}) {|String| ... } ⇒ Object
Defines a matcher alias. The returned matcher’s ‘description` will be overridden to reflect the phrasing of the new name, which will be used in failure messages when passed as an argument to another matcher in a composed matcher expression.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/dsl.rb', line 32 def alias_matcher(new_name, old_name, ={}, &description_override) description_override ||= lambda do |old_desc| old_desc.gsub(EnglishPhrasing.split_words(old_name), EnglishPhrasing.split_words(new_name)) end klass = .fetch(:klass) { AliasedMatcher } define_method(new_name) do |*args, &block| matcher = __send__(old_name, *args, &block) matcher.matcher_name = new_name if matcher.respond_to?(:matcher_name=) klass.new(matcher, description_override) end ruby2_keywords new_name if respond_to?(:ruby2_keywords, true) end |
#define(name) {|Object| ... } ⇒ Object Also known as: matcher
Defines a custom matcher.
73 74 75 76 77 78 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/dsl.rb', line 73 def define(name, &declarations) warn_about_block_args(name, declarations) define_method name do |*expected, &block_arg| RSpec::Matchers::DSL::Matcher.new(name, declarations, self, *expected, &block_arg) end end |
#define_negated_matcher(negated_name, base_name) {|String| ... } ⇒ Object
Defines a negated matcher. The returned matcher’s ‘description` and `failure_message` will be overridden to reflect the phrasing of the new name, and the match logic will be based on the original matcher but negated.
61 62 63 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/dsl.rb', line 61 def define_negated_matcher(negated_name, base_name, &description_override) alias_matcher(negated_name, base_name, :klass => AliasedNegatedMatcher, &description_override) end |