Module: StubHelper
- Defined in:
- lib/cucoo/stub_helper.rb
Instance Method Summary collapse
- #assert_all_stubs! ⇒ Object
- #clear_stubs! ⇒ Object
- #expand_url(url) ⇒ Object
- #stub_my_request(method, url, params) ⇒ Object
Instance Method Details
#assert_all_stubs! ⇒ Object
6 7 8 9 10 |
# 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! ⇒ Object
25 26 27 |
# File 'lib/cucoo/stub_helper.rb', line 25 def clear_stubs! @stubs = [] end |
#expand_url(url) ⇒ Object
2 3 4 |
# File 'lib/cucoo/stub_helper.rb', line 2 def (url) ['http://', Cucoo::Config.stub_host, ':', Cucoo::Config.stub_port, url].join end |
#stub_my_request(method, url, params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# 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, (url)) @stubs << stub_obj stub_obj.with(body: params[:request], headers: {'Content-Type' => 'application/json'}) if params[:request] stub_obj.to_return(body: response, status: status) end |