Sha256: 02aa485ae930249dc048c1edca1a710ef7af23d229644dd67c2d5ad04af0183a

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true
require 'proxy_rb/http_proxy'
require 'proxy_rb/proxy_url_parser'

Given(/^I use the following proxies:$/) do |table|
  @proxies = table.hashes.map { |r| ProxyRb::HttpProxy.new(ProxyRb::ProxyUrlParser.new(r[:proxy])) }
end

Then(/the following requests are( not)? allowed to pass the proxy:/) do |forbidden, table|
  requests = []

  proxies.each do |proxy|
    table.hashes.map { |r| r[:url] }.each do |r|
      visit r, proxy
      requests << page.dup
    end
  end

  if forbidden
    expect(requests).to ProxyRb::Matchers.all be_forbidden
  else
    expect(requests).to ProxyRb::Matchers.all be_successful
  end
end

When(/^I visit "([^"]*)"$/) do |url|
  Array(proxies.first).each { |proxy| visit url, proxy }
end

When(/^I visit the following websites:$/) do |table|
  @websites = table.hashes.map { |r| r[:url] }
end

Then(/the (?:last response|last requested page) should( not)? contain:/) do |not_expected, content|
  if not_expected
    expect(page).not_to have_content content
  else
    expect(page).to have_content content
  end
end

Then(/all (?:requested pages|responses) should( not)? contain:/) do |not_expected, content|
  results = []

  proxies.each do |proxy|
    websites.each do |w|
      visit w, proxy
      results << page.dup
    end
  end

  if not_expected
    expect(results).not_to ProxyRb::Matchers.include have_content content
  else
    expect(results).to ProxyRb::Matchers.all have_content content
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proxy_rb-0.9.1 lib/proxy_rb/cucumber/steps.rb
proxy_rb-0.9.0 lib/proxy_rb/cucumber/steps.rb