Class: RSpecApi::Matchers::Filter::Matcher

Inherits:
Collection::Matcher show all
Defined in:
lib/rspec-api/matchers/filter/matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Response::Matcher

#response

Instance Method Summary collapse

Methods inherited from Response::Matcher

#failure_message_for_should, #failure_message_for_should_not

Constructor Details

#initialize(options = {}) ⇒ Matcher

Returns a new instance of Matcher.



9
10
11
12
13
# File 'lib/rspec-api/matchers/filter/matcher.rb', line 9

def initialize(options = {})
  @field = options[:by]
  @value = options[:value]
  @compare_with = options.fetch :compare_with, :==
end

Instance Attribute Details

#compare_withObject

Returns the value of attribute compare_with.



7
8
9
# File 'lib/rspec-api/matchers/filter/matcher.rb', line 7

def compare_with
  @compare_with
end

#fieldObject

Returns the value of attribute field.



7
8
9
# File 'lib/rspec-api/matchers/filter/matcher.rb', line 7

def field
  @field
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/rspec-api/matchers/filter/matcher.rb', line 7

def value
  @value
end

Instance Method Details

#descriptionObject



19
20
21
22
23
24
25
# File 'lib/rspec-api/matchers/filter/matcher.rb', line 19

def description
  if field
    %Q(be filtered by #{field}#{compare_with}#{value})
  else
    %Q(be filtered)
  end
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rspec-api/matchers/filter/matcher.rb', line 15

def matches?(response)
  super && all_objects_have_field? && has_one_object? && is_filtered?
end