Module: Remarkable::DSL::Assertions

Defined in:
lib/remarkable/dsl/assertions.rb

Overview

This module is responsable to create a basic matcher structure using a DSL.

A matcher that checks if an element is included in an array can be done just with:

class IncludedMatcher < Remarkable::Base
  arguments :value
  assertion :is_included?

  protected
    def is_included?
      @subject.include?(@value)
    end
end

As you have noticed, the DSL also allows you to remove the messages from matcher. Since it will look for it on I18n yml file.

If you want to create a matcher that accepts multile values to be tested, you just need to do:

class IncludedMatcher < Remarkable::Base
  arguments :collection => :values, :as => :value
  collection_assertion :is_included?

  protected
    def is_included?
      @subject.include?(@value)
    end
end

Notice that the :is_included? logic didn’t have to change, because Remarkable handle this automatically for you.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



39
40
41
# File 'lib/remarkable/dsl/assertions.rb', line 39

def self.included(base) # :nodoc:
  base.extend ClassMethods
end

Instance Method Details

#matches?(subject) ⇒ Boolean

This method is responsable for connecting arguments, assertions and collection_assertions.

It’s the one that executes the assertions once, executes the collection assertions for each element in the collection and also responsable to set the I18n messages.

Returns:

  • (Boolean)


280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/remarkable/dsl/assertions.rb', line 280

def matches?(subject)
  @subject = subject

  run_before_assert_callbacks

  assertions = self.class.matcher_single_assertions
  unless assertions.empty?
    value = send_methods_and_generate_message(assertions)
    return negative? if positive? == !value
  end

  matches_collection_assertions?
end