Class: ResourceSet::Testing::HaveActionMatchers

Inherits:
Object
  • Object
show all
Defined in:
lib/resource_set/testing/have_action_matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ HaveActionMatchers



6
7
8
9
# File 'lib/resource_set/testing/have_action_matchers.rb', line 6

def initialize(action)
  @action = action
  @failures = []
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



4
5
6
# File 'lib/resource_set/testing/have_action_matchers.rb', line 4

def action
  @action
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/resource_set/testing/have_action_matchers.rb', line 4

def path
  @path
end

#verbObject (readonly)

Returns the value of attribute verb.



4
5
6
# File 'lib/resource_set/testing/have_action_matchers.rb', line 4

def verb
  @verb
end

Instance Method Details

#at_path(path) ⇒ Object



19
20
21
22
# File 'lib/resource_set/testing/have_action_matchers.rb', line 19

def at_path(path)
  @path = path
  self
end

#failure_messageObject



43
44
45
46
47
48
49
# File 'lib/resource_set/testing/have_action_matchers.rb', line 43

def failure_message
  return "expected class to have action #{action}." if failures.empty?

  failures.map do |validation, expected, got|
    "expected #{expected} #{validation}, got #{got} instead."
  end.join('\n')
end

#handler_codesObject



39
40
41
# File 'lib/resource_set/testing/have_action_matchers.rb', line 39

def handler_codes
  @handler_codes ||= []
end

#matches?(subject) ⇒ Boolean



29
30
31
32
33
34
35
36
37
# File 'lib/resource_set/testing/have_action_matchers.rb', line 29

def matches?(subject)
  action = subject.resources.find_action(self.action)
  return false unless action

  %i(check_keys check_path check_verb).inject(true) do |rv, method_name|
    break false unless send(method_name, action)
    true
  end
end

#that_handles(*codes) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/resource_set/testing/have_action_matchers.rb', line 11

def that_handles(*codes)
  codes.each do |code|
    handler_codes << StatusCodeMapper.code_for(code)
  end

  self
end

#with_verb(verb) ⇒ Object



24
25
26
27
# File 'lib/resource_set/testing/have_action_matchers.rb', line 24

def with_verb(verb)
  @verb = verb
  self
end