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

Passes if the object has a JSONP callback-wrapped body

Examples:

Passes if the body is wrapped in the function “alert”

require 'rspec-api-matchers'

body = 'alert([{"id": 1}])'
obj = OpenStruct.new body: body

describe 'be_wrapped_in_callback' do
  include RSpecApi::Matchers::Jsonp
  it { expect(obj).to be_wrapped_in_callback(:alert) }
end

# => (rspec) 1 example, 0 failures

Parameters:

  • callback (Symbol or String) (defaults to: nil)

    Name of the wrapping JSONP callback

See Also:


24
25
26
# File 'lib/rspec-api/matchers/jsonp/be_wrapped_in_callback.rb', line 24

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