Class: Mustard::DefaultMatcher
- Inherits:
-
Object
- Object
- Mustard::DefaultMatcher
- Defined in:
- lib/mustard/matchers/default_matcher.rb
Class Method Summary collapse
-
.subclass_for(name, behavior) ⇒ Object
This will genereate a subclass of DefaultMatcher to act as the matcher class.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(subject, *args) ⇒ DefaultMatcher
constructor
A new instance of DefaultMatcher.
- #match? ⇒ Boolean
- #message_action ⇒ Object
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(subject, *args) ⇒ DefaultMatcher
Returns a new instance of DefaultMatcher.
16 17 18 19 |
# File 'lib/mustard/matchers/default_matcher.rb', line 16 def initialize(subject, *args) @subject = subject @args = *args end |
Class Method Details
.subclass_for(name, behavior) ⇒ Object
This will genereate a subclass of DefaultMatcher to act as the matcher class. This way we can persist the name of the matcher and the block of behavior.
6 7 8 9 10 11 12 13 14 |
# File 'lib/mustard/matchers/default_matcher.rb', line 6 def self.subclass_for(name, behavior) klass = Class.new(self) class << klass attr_accessor :name, :behavior end klass.name = name klass.behavior = behavior klass end |
Instance Method Details
#failure_message ⇒ Object
25 26 27 |
# File 'lib/mustard/matchers/default_matcher.rb', line 25 def "expected #{@subject.inspect} to #{}" end |
#match? ⇒ Boolean
21 22 23 |
# File 'lib/mustard/matchers/default_matcher.rb', line 21 def match? @subject.instance_exec(*@args, &self.class.behavior) end |
#message_action ⇒ Object
33 34 35 36 37 |
# File 'lib/mustard/matchers/default_matcher.rb', line 33 def = self.class.name.to_s.tr("_", " ") += " " + @args.map(&:inspect).join(", ") unless @args.empty? end |
#negative_failure_message ⇒ Object
29 30 31 |
# File 'lib/mustard/matchers/default_matcher.rb', line 29 def "expected #{@subject.inspect} to not #{}" end |