module Brainstem::TestHelpers
Helpers for easing the testing of brainstem responses in controller specs
To use, add the following to you spec_helper file:
require 'brainstem/test_helpers' Rspec.configure { |config| config.include Brainstem::TestHelpers, :type => :controller }
Public Instance Methods
brainstem_data()
click to toggle source
Use brainstem_data
in your controller specs to easily access Brainstem
JSON data payloads and their attributes
Examples:
Assume user is the model and name is an attribute
Selecting an item from a collection by it's id
expect(brainstem_data.users.by_id(235).name).to eq('name')
Getting an array of all ids of in a collection without map
expect(brainstem_data.users.ids).to include(1)
Accessing the keys of a collection
expect(brainstem_data.users.first.keys).to =~ %w(id name email address)
Using standard array methods on a collection
expect(brainstem_data.users.first.name).to eq('name') expect(brainstem_data.users[2].name).to eq('name')
# File lib/brainstem/test_helpers.rb, line 30 def brainstem_data BrainstemDataHelper.new(response.body) end