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.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/remarkable/controller/macros/assign_matcher.rb', line 9

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)
  warn "[DEPRECATION] :equals option is deprecated in should_assign_to. Please give :with instead."        if @options[:equals]
  warn "[DEPRECATION] :class option is deprecated in should_assign_to. Please give :with_kind_of instead." if @options[:class]

  @options[:with]         ||= @options.delete(:equals)
  @options[:with_kind_of] ||= @options.delete(:class)
end

Instance Method Details

#descriptionObject



33
34
35
36
37
38
# File 'lib/remarkable/controller/macros/assign_matcher.rb', line 33

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

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