Class Remarkable::Base
In: lib/remarkable/base.rb
Parent: Object

This class holds the basic structure for Remarkable matchers. All matchers must inherit from it.

Methods

Included Modules

Remarkable::Messages

Public Instance methods

[Source]

    # File lib/remarkable/base.rb, line 18
18:     def negative?
19:       false
20:     end

[Source]

    # File lib/remarkable/base.rb, line 14
14:     def positive?
15:       !negative?
16:     end

Optional to provide spec binding to matchers.

[Source]

    # File lib/remarkable/base.rb, line 9
 9:     def spec(binding)
10:       @spec = binding
11:       self
12:     end

Protected Instance methods

Asserts that the given collection contains item x. If x is a regular expression, ensure that at least one element from the collection matches x.

  assert_contains(['a', '1'], /\d/) => passes
  assert_contains(['a', '1'], 'a') => passes
  assert_contains(['a', '1'], /not there/) => fails

[Source]

    # File lib/remarkable/base.rb, line 62
62:       def assert_contains(collection, x)
63:         collection = [collection] unless collection.is_a?(Array)
64: 
65:         case x
66:           when Regexp
67:             collection.detect { |e| e =~ x }
68:           else
69:             collection.include?(x)
70:         end
71:       end

Returns the subject class unless it‘s a class object.

[Source]

    # File lib/remarkable/base.rb, line 25
25:       def subject_class
26:         nil unless @subject
27:         @subject.is_a?(Class) ? @subject : @subject.class
28:       end

Returns the subject name based on its class. If the class respond to human_name (which is usually localized) returns it.

[Source]

    # File lib/remarkable/base.rb, line 32
32:       def subject_name
33:         nil unless @subject
34:         subject_class.respond_to?(:human_name) ? subject_class.human_name : subject_class.name
35:       end

[Validate]