Module: Strelka::Testing

Defined in:
lib/strelka/testing.rb

Overview

A collection of testing functions and classes for use in Strelka handlers and libraries.

Defined Under Namespace

Classes: FinishWithMatcher, HaveJSONBodyMatcher, HaveJSONCollectionMatcher

Class Method Summary collapse

Class Method Details

.finish_with(status, message = nil, headers = {}) ⇒ Object

Match a response thrown via the finish_with function.



603
604
605
# File 'lib/strelka/testing.rb', line 603

def finish_with( status, message=nil, headers={} )
	return FinishWithMatcher.new( status, message, headers )
end

.have_json_body(expected_type = nil) ⇒ Object

Create a new matcher that will expect the response to have a JSON body of the expected_type. If expected_type is omitted, any JSON body will be sufficient for a match.



611
612
613
# File 'lib/strelka/testing.rb', line 611

def have_json_body( expected_type=nil )
	return HaveJSONBodyMatcher.new( expected_type )
end

.have_json_collectionObject

Create a new matcher that will expect the response to have a JSON body which is an Array of Objects (Hashes).



618
619
620
# File 'lib/strelka/testing.rb', line 618

def have_json_collection
	return HaveJSONCollectionMatcher.new
end

.response_json_body(response) ⇒ Object

Parse the body of the given response and return it as a Ruby object.



624
625
626
627
# File 'lib/strelka/testing.rb', line 624

def response_json_body( response )
	response.body.rewind
	Yajl::Parser.parse( response.body, check_utf8: true, symbolize_keys: true )
end