Class: ResourceSet::Testing::HaveActionMatchers
- Inherits:
-
Object
- Object
- ResourceSet::Testing::HaveActionMatchers
- Defined in:
- lib/resource_set/testing/have_action_matchers.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #at_path(path) ⇒ Object
- #failure_message ⇒ Object
- #handler_codes ⇒ Object
-
#initialize(action) ⇒ HaveActionMatchers
constructor
A new instance of HaveActionMatchers.
- #matches?(subject) ⇒ Boolean
- #that_handles(*codes) ⇒ Object
- #with_verb(verb) ⇒ Object
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
#action ⇒ Object (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 |
#path ⇒ Object (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 |
#verb ⇒ Object (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_message ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/resource_set/testing/have_action_matchers.rb', line 43 def 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_codes ⇒ Object
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 |