Sha256: 4a70a5d9005c6be78b0075b5171dd127c6a080c4e28e3461a66d16072f2d4ac6

Contents?: true

Size: 1.71 KB

Versions: 25

Compression:

Stored size: 1.71 KB

Contents

require 'webmock/rspec'

module StubHelper
  def initialize(*args)
    @base_url = 'http://www.example.com/'
  end

  def mock_get(url, response_headers = {}, status = 200)
    stub_request(:get, @base_url + url).to_return(headers: response_headers, body: get_json_response_file(url), status: status)
  end

  def mock_post(url, options = {}, status = 200)
    stub_request(:post, @base_url + url).with(body: options[:request_body] || {})
      .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
  end

  def mock_put(url, options = {}, status = 200)
    stub_request(:put, @base_url + url).with(body: options[:request_body] || {})
      .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
  end

  def mock_patch(url, options = {}, status = 200)
    stub_request(:patch, @base_url + url).with(body: options[:request_body] || {})
      .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
  end

  def mock_delete(url, options = {}, status = 200)
    stub_request(:delete, @base_url + url).with(body: options[:request_body] || {})
    .to_return(headers: options[:response_headers] || {}, body: get_json_response_file(url), status: status)
  end

  def mock_head(url, response_headers = {}, status = 200)
    stub_request(:head, @base_url + url).to_return(headers: response_headers, body: nil, status: status)
  end

  def mock_options(url, response_headers = {}, status = 200)
    stub_request(:options, @base_url + url).to_return(headers: response_headers, body: nil, status: status)
  end

  private

  def get_json_response_file(name)
    IO.read("spec/test_responses/#{name}.json")
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
airborne-0.3.7 spec/stub_helper.rb
airborne-0.3.6 spec/stub_helper.rb
airborne-0.3.5 spec/stub_helper.rb
hops-airborne-0.2.17 spec/stub_helper.rb
airborne-0.3.4 spec/stub_helper.rb
airborne-0.3.3 spec/stub_helper.rb
airborne-0.3.2 spec/stub_helper.rb
airborne-0.3.1 spec/stub_helper.rb
airborne-0.3.0 spec/stub_helper.rb
hops-airborne-0.2.16 spec/stub_helper.rb
hops-airborne-0.2.15 spec/stub_helper.rb
airborne-0.2.13 spec/stub_helper.rb
airborne-0.2.12 spec/stub_helper.rb
airborne-0.2.11 spec/stub_helper.rb
airborne-0.2.10 spec/stub_helper.rb
airborne-0.2.9 spec/stub_helper.rb
airborne-0.2.8 spec/stub_helper.rb
airborne-0.2.7 spec/stub_helper.rb
airborne-0.2.6 spec/stub_helper.rb
airborne-0.2.5 spec/stub_helper.rb