Module: Brainstem::TestHelpers
- Defined in:
- lib/brainstem/test_helpers.rb
Overview
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 }
Defined Under Namespace
Classes: BrainstemDataHelper
Instance Method Summary collapse
-
#brainstem_data ⇒ Object
Use brainstem_data in your controller specs to easily access Brainstem JSON data payloads and their attributes.
Instance Method Details
#brainstem_data ⇒ Object
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')
30 31 32 |
# File 'lib/brainstem/test_helpers.rb', line 30 def brainstem_data BrainstemDataHelper.new(response.body) end |