Module: RSpecApi::Matchers::Jsonp

Included in:
RSpecApi::Matchers
Defined in:
lib/rspec-api/matchers/jsonp/matcher.rb,
lib/rspec-api/matchers/jsonp/be_wrapped_in_callback.rb

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Instance Method Details

#be_wrapped_in_callback(callback = nil) ⇒ Object

Note:

Passes if response body is a valid JSON wrapped in a JSONP callback

A JSONP should actually return application/javascript…

For more examples check be_wrapped_in_callback_spec.rb.

Examples:


# Passes if the body is wrapped in "alert"
body = 'alert([{"id": 1}])'
expect(OpenStruct.new body: body).to be_wrapped_in_callback(:alert)


19
20
21
# File 'lib/rspec-api/matchers/jsonp/be_wrapped_in_callback.rb', line 19

def be_wrapped_in_callback(callback = nil)
  RSpecApi::Matchers::Jsonp::Matcher.new callback
end