Module: WebMock::RSpec::Helper

Defined in:
lib/webmock-rspec-helper.rb,
lib/webmock-rspec-helper/version.rb

Constant Summary collapse

VERSION =
'0.0.5'.freeze

Instance Method Summary collapse

Instance Method Details

#webmock(method, mocks = {}, with: false, headers: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/webmock-rspec-helper.rb', line 8

def webmock(method, mocks = {}, with: false, headers: nil)
  mocks.each do |regex, result|
    if result.to_s =~ /\A\d+\z/
      status = result
      body = ''
    else
      status = result[/\.(\d+)\./, 1] || 200
      body = File.read Rails.root.join('spec', 'support', 'stubs', result)
    end

    stub = WebMock.stub_request(method, regex)
    stub.with(with) if with
    stub.to_return status: status.to_i, body: body, headers: headers
  end
end