Class: ClassAction::RSpec::RespondWithMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/class_action/rspec/respond_with_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ RespondWithMatcher

Returns a new instance of RespondWithMatcher.



6
7
8
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 6

def initialize(expected)
  @expected = expected.to_sym
end

Instance Method Details

#descriptionObject



21
22
23
24
25
26
27
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 21

def description
  if @condition
    "respond with method :#{@expected} on :#{@condition}"
  else
    "respond with method :#{@expected}"
  end
end

#failure_messageObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 29

def failure_message
  suffix = if @actual
    ", but it responds with :#{@actual}"
  else
    ", but it has no response method"
  end

  if @condition
    "expected action of class #{@action.class} to respond with :#{@expected} on :#{@condition}#{suffix}"
  else
    "expected action of class #{@action.class} to respond with :#{@expected}#{suffix}"
  end
end

#failure_message_when_negatedObject



43
44
45
46
47
48
49
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 43

def failure_message_when_negated
  if @condition
    "expected action of class #{@action.class} not to respond with :#{@expected} on :#{@condition}"
  else
    "expected action of class #{@action.class} not to respond with :#{@expected}"
  end
end

#matches?(action) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 15

def matches?(action)
  @action = action
  @actual = action.class._responses[@condition].try(:to_sym)
  @actual == @expected
end

#on(condition) ⇒ Object



10
11
12
13
# File 'lib/class_action/rspec/respond_with_matcher.rb', line 10

def on(condition)
  @condition = condition
  self
end