Sha256: eab3a94a82c457ba44aa33b960fe3a65adefe8a178bcf8f9905b928a600e06e7

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 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)

    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.3.2 spec/spec_helper.rb
rspec-webservice_matchers-4.3.1 spec/spec_helper.rb
rspec-webservice_matchers-4.3.0 spec/spec_helper.rb
rspec-webservice_matchers-4.2.0 spec/spec_helper.rb