Class: Remarkable::Controller::Matchers::AssignMatcher

Inherits:
Matcher::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/remarkable/controller/macros/assign_matcher.rb

Instance Method Summary collapse

Methods included from Default::Helpers

#assert_contains, #assert_does_not_contain

Methods inherited from Matcher::Base

#failure_message, #negative, #negative_failure_message, #spec

Methods included from Matcher::DSL

included

Constructor Details

#initialize(*names, &block) ⇒ AssignMatcher

Returns a new instance of AssignMatcher.



7
8
9
10
11
12
13
# File 'lib/remarkable/controller/macros/assign_matcher.rb', line 7

def initialize(*names, &block)
  @options          = names.extract_options!
  @names            = names
  @options[:equals] = block if block_given?

  warn "[DEPRECATION] Strings given in :equals to should_assign_to won't be evaluated anymore. You can give procs or use blocks instead." if @options[:equals].is_a?(String)
end

Instance Method Details

#descriptionObject



26
27
28
29
30
31
# File 'lib/remarkable/controller/macros/assign_matcher.rb', line 26

def description
  description = "assign @#{@names.to_sentence}"
  description << " as class #{@options[:class]}" if @options[:class]
  description << " which is equal to #{@options[:equals]}" if @options[:equals]
  description
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
# File 'lib/remarkable/controller/macros/assign_matcher.rb', line 15

def matches?(subject)
  @subject = subject

  initialize_with_spec!

  assert_matcher_for(@names) do |name|
    @name = name
    assigned_value? && is_kind_of? && is_equals_expected_value?
  end
end