Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Merge branch 'kill-fakeweb' into single-registration-point
Browse files Browse the repository at this point in the history
  • Loading branch information
dhwthompson committed Jun 21, 2012
2 parents f7a47ca + ebd531d commit 10daeb3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -69,8 +69,8 @@ group :test do
gem 'factory_girl_rails'
gem 'capybara-mechanize', '~> 0.3.0.rc3'
gem 'launchy'
gem 'fakeweb'
gem 'mocha'
gem 'webmock', :require => false
end

group :import do
Expand Down
7 changes: 5 additions & 2 deletions Gemfile.lock
Expand Up @@ -76,6 +76,7 @@ GEM
ci_reporter (1.6.9)
builder (>= 2.1.2)
colorize (0.5.8)
crack (0.3.1)
cucumber (1.1.4)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
Expand All @@ -99,7 +100,6 @@ GEM
factory_girl_rails (1.5.0)
factory_girl (~> 2.4.0)
railties (>= 3.0.0)
fakeweb (1.3.0)
faraday (0.7.6)
addressable (~> 2.2)
multipart-post (~> 1.1)
Expand Down Expand Up @@ -262,6 +262,9 @@ GEM
multi_json (>= 1.0.2)
warden (1.0.6)
rack (>= 1.0)
webmock (1.8.7)
addressable (>= 2.2.7)
crack (>= 0.1.7)
webrobots (0.0.12)
nokogiri (>= 1.4.4)
whenever (0.7.2)
Expand All @@ -287,7 +290,6 @@ DEPENDENCIES
exception_notification
factory_girl
factory_girl_rails
fakeweb
formtastic!
formtastic-bootstrap!
gds-api-adapters
Expand Down Expand Up @@ -318,4 +320,5 @@ DEPENDENCIES
therubyracer (~> 0.9.4)
turn
uglifier
webmock
whenever
14 changes: 5 additions & 9 deletions features/step_definitions/registration_steps.rb
Expand Up @@ -64,21 +64,17 @@
end

Then /^rummager should be notified$/ do
# We allow one request to search. FakeWeb will decrement
# the allowed number of requests each time one is made
assert_equal 1, @fake_search.first.options[:times] - @fake_search.first.times
assert_requested @fake_search, times: 1 # The default, but let's be explicit
end

Then /^the router should be notified$/ do
# We allow one request to the router. FakeWeb will decrement
# the allowed number of requests each time one is made
assert_equal 1, @fake_router.first.options[:times] - @fake_router.first.times
assert_requested @fake_router, times: 1 # The default, but let's be explicit
end

Then /^rummager should not be notified$/ do
assert_equal @fake_search.first.options[:times], @fake_search.first.times
assert_not_requested @fake_search
end

Then /^the router should not be notified$/ do
assert_equal @fake_router.first.options[:times], @fake_router.first.times
end
assert_not_requested @fake_router
end
3 changes: 0 additions & 3 deletions features/support/fakeweb.rb

This file was deleted.

4 changes: 2 additions & 2 deletions features/support/registration_info.rb
Expand Up @@ -30,11 +30,11 @@ def setup_user
end

def stub_search
@fake_search = FakeWeb.register_uri(:post, "http://search.test.gov.uk/documents", times: 1)
@fake_search = WebMock.stub_request(:post, "http://search.test.gov.uk/documents").to_return(status: 200)
end

def stub_router
@fake_router = FakeWeb.register_uri(:put, /http:\/\/router.cluster:8080\/router\/routes\/.*/, times: 1)
@fake_router = WebMock.stub_request(:put, /http:\/\/router.cluster:8080\/router\/routes\/.*/).to_return(status: 200)
end

def setup_existing_artefact
Expand Down
13 changes: 13 additions & 0 deletions features/support/webmock.rb
@@ -0,0 +1,13 @@
require 'webmock'
require 'webmock/cucumber'

include WebMock::API

WebMock.disable_net_connect!

Before do
# Mock out all publisher URLs
stub_request(:get, %r{^#{Regexp.escape Plek.current.find('publisher')}/}).to_return(status: 200)

stub_request(:get, "#{Plek.current.find('data')}/data_sets/public_bodies.json").to_return(body: [].to_json)
end
9 changes: 7 additions & 2 deletions test/integration/integration_test_helper.rb
@@ -1,19 +1,24 @@
require_relative '../test_helper'
require 'capybara/rails'
require 'capybara/mechanize'
FakeWeb.allow_net_connect = true
FakeWeb.register_uri :get, /assets.test.gov.uk/, :status => [404, 'Not found']
require 'webmock'

DatabaseCleaner.strategy = :truncation

class ActionDispatch::IntegrationTest
include Capybara::DSL
include WebMock

def setup
DatabaseCleaner.clean

WebMock.allow_net_connect!
stub_request(:get, /assets\.test\.gov\.uk/).to_return(status: 404)
end

def teardown
DatabaseCleaner.clean
WebMock.reset! # Not entirely sure whether this happens anyway
end

end
Expand Down
11 changes: 10 additions & 1 deletion test/test_helper.rb
Expand Up @@ -13,7 +13,8 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'mocha'
FakeWeb.allow_net_connect = false
require 'webmock'


DatabaseCleaner.strategy = :truncation
# initial clean
Expand All @@ -27,6 +28,10 @@ def clean_db
end
set_callback :teardown, :before, :clean_db

def setup
WebMock.disable_net_connect!
end

def app
Panopticon::Application
end
Expand All @@ -35,4 +40,8 @@ def login_as_stub_user
temp_user = User.create!(:name => 'Stub User')
request.env['warden'] = stub(:authenticate! => true, :authenticated? => true, :user => temp_user)
end

def teardown
WebMock.reset!
end
end

1 comment on commit 10daeb3

@jystewart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice to see that assert_requested in there. Much cleaner than what I had with fakeweb.

Please sign in to comment.