module StubHelper
Public Instance Methods
assert_all_stubs!()
click to toggle source
# File lib/cucoo/stub_helper.rb, line 6 def assert_all_stubs! @stubs.each do |stub| expect(stub).to have_been_requested end end
clear_stubs!()
click to toggle source
# File lib/cucoo/stub_helper.rb, line 26 def clear_stubs! @stubs = [] end
expand_url(url)
click to toggle source
# File lib/cucoo/stub_helper.rb, line 2 def expand_url(url) ['http://', Cucoo::Config.stub_host, ':', Cucoo::Config.stub_port, url].join end
stub_my_request(method, url, params={})
click to toggle source
# File lib/cucoo/stub_helper.rb, line 12 def stub_my_request(method, url, params={}) response = if params[:file] File.new(params['file']).read else params[:response] || {}.to_json end status = params[:status] ? params[:status].to_i : 200 stub_obj = stub_request(method, expand_url(url)) @stubs << stub_obj stub_obj.with(body: params[:request], headers: {'Content-Type' => 'application/json'}) if params[:request] stub_obj.with(body: params[:form_params], headers: {'Content-Type' => 'application/x-www-form-urlencoded'}) if params[:form_params] stub_obj.to_return(body: response, status: status) end