Sha256: c8debb66ad3b2eaf88807d60ea39ef7f390748f93da983f9cefd30e8e7fa2b98

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

require 'webmock/rspec'

RSpec.configure do |config|
  config.before(:each) do
    WebMock.stub_request :any, 'http://a-page.com/a/page.txt'
    WebMock.stub_request :any, 'www.website.com'
    WebMock.stub_request(:any, /notfound.com/).to_return(status: 404)
    WebMock.stub_request(:any, 'outoforder.com').to_return(status: 503)

    # A host which doesn't support HEAD
    WebMock.stub_request(:head, 'appengine.com').to_return(status: 405)
    WebMock.stub_request(:get,  'appengine.com').to_return(status: 200)

    WebMock.stub_request(:any, 'perm-redirector.com')
      .to_return(status: 301, headers: { Location: 'http://www.website.com/' })

    WebMock.stub_request(:any, 'temp-redirector.org')
      .to_return(status: 302, headers: { Location: 'http://a-page.com/a/page.txt' })

    WebMock.stub_request(:any, 'temp-307-redirector.net')
      .to_return(status: 307, headers: { Location: 'http://a-page.com/a/page.txt' })

    # Timeout scenarios
    WebMock.stub_request(:any, 'www.timeout.com').to_timeout
    WebMock.stub_request(:any, 'www.timeout-once.com').to_timeout.then.to_return(body: 'abc')

    # Insights API
    key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
    WebMock.stub_request(:get, "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?key=#{key}&screenshot=false&url=http://nonstop.qa")
      .with(headers:
        {
          'Host' => 'www.googleapis.com:443',
          'User-Agent' => 'excon/0.45.4'
        })
      .to_return(
        status: 200,
        body: IO.read('spec/fixtures/pagespeed.json'),
        headers: {})

    WebMock.allow_net_connect!
  end
end

module RSpec
  # Matchers to help test RSpec matchers
  module Matchers
    def fail
      raise_error(RSpec::Expectations::ExpectationNotMetError)
    end

    def fail_with(message)
      raise_error(RSpec::Expectations::ExpectationNotMetError, message)
    end

    def fail_matching(regex)
      raise_error(RSpec::Expectations::ExpectationNotMetError, regex)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-webservice_matchers-4.4.3 spec/spec_helper.rb
rspec-webservice_matchers-4.4.2 spec/spec_helper.rb
rspec-webservice_matchers-4.4.1 spec/spec_helper.rb
rspec-webservice_matchers-4.4.0 spec/spec_helper.rb