Class: InfinumJsonApiSetup::RSpec::Matchers::Util::BodyParser
- Inherits:
-
Object
- Object
- InfinumJsonApiSetup::RSpec::Matchers::Util::BodyParser
- Defined in:
- lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb
Instance Method Summary collapse
-
#initialize(attribute) ⇒ BodyParser
constructor
A new instance of BodyParser.
- #process(response) ⇒ Array
Constructor Details
#initialize(attribute) ⇒ BodyParser
Returns a new instance of BodyParser.
9 10 11 |
# File 'lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb', line 9 def initialize(attribute) @attribute = attribute end |
Instance Method Details
#process(response) ⇒ Array
15 16 17 18 19 20 21 |
# File 'lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb', line 15 def process(response) [true, JSON.parse(response.body).fetch(attribute)] rescue JSON::ParserError => _e [false, 'Failed to parse response body'] rescue KeyError => _e [false, "Failed to extract #{attribute} from response body"] end |