mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add webmock for external requests in tests
external_request.rb needs to be required before lint is run.
This commit is contained in:
parent
640be7497f
commit
6301072484
5 changed files with 47 additions and 1 deletions
2
Gemfile
2
Gemfile
|
|
@ -179,6 +179,8 @@ group :test do
|
|||
# Extracted from RSpec 3 stub_model and mock_model
|
||||
gem 'rspec-activemodel-mocks'
|
||||
gem 'timecop'
|
||||
# Mock external requests
|
||||
gem 'webmock'
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
|
|
|
|||
|
|
@ -130,6 +130,8 @@ GEM
|
|||
simplecov (>= 0.7)
|
||||
term-ansicolor
|
||||
thor
|
||||
crack (0.4.2)
|
||||
safe_yaml (~> 1.0.0)
|
||||
currencies (0.4.2)
|
||||
daemons (1.1.9)
|
||||
database_cleaner (1.3.0)
|
||||
|
|
@ -409,6 +411,7 @@ GEM
|
|||
ruby-openid (2.5.0)
|
||||
ruby-progressbar (1.7.5)
|
||||
rubyzip (1.0.0)
|
||||
safe_yaml (1.0.4)
|
||||
sass (3.2.19)
|
||||
sass-rails (4.0.4)
|
||||
railties (>= 4.0.0, < 5.0)
|
||||
|
|
@ -464,6 +467,9 @@ GEM
|
|||
binding_of_caller (>= 0.7.2)
|
||||
railties (>= 4.0)
|
||||
sprockets-rails (>= 2.0, < 4.0)
|
||||
webmock (1.20.4)
|
||||
addressable (>= 2.3.6)
|
||||
crack (>= 0.3.2)
|
||||
websocket-driver (0.3.3)
|
||||
whenever (0.9.2)
|
||||
activesupport (>= 2.3.4)
|
||||
|
|
@ -553,6 +559,7 @@ DEPENDENCIES
|
|||
turbolinks
|
||||
uglifier (>= 1.3.0)
|
||||
web-console (~> 2.0)
|
||||
webmock
|
||||
whenever
|
||||
|
||||
BUNDLED WITH
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
require_relative '../../spec/support/external_request'
|
||||
|
||||
namespace :factory_girl do
|
||||
desc "Verify that all FactoryGirl factories are valid"
|
||||
task lint: :environment do
|
||||
if Rails.env.test?
|
||||
begin
|
||||
DatabaseCleaner.start
|
||||
mock_commercial_request
|
||||
FactoryGirl.lint
|
||||
ensure
|
||||
DatabaseCleaner.clean
|
||||
|
|
|
|||
29
spec/support/external_request.rb
Normal file
29
spec/support/external_request.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Mock external requests to youtube
|
||||
require 'webmock/rspec'
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before(:each) do
|
||||
mock_commercial_request
|
||||
end
|
||||
end
|
||||
|
||||
def mock_commercial_request
|
||||
response = {
|
||||
author_name: 'Confreaks',
|
||||
html: '<iframe width=\'560\' height=\'315\' src=\'https://www.youtube.com/embed/BTTygyxuGj8?feature=oembed\' frameborder=\'0\' allowfullscreen></iframe>',
|
||||
thumbnail_width: 480,
|
||||
thumbnail_url: 'https://i.ytimg.com/vi/BTTygyxuGj8/hqdefault.jpg',
|
||||
provider_name: 'YouTube',
|
||||
width: 459,
|
||||
type: 'video',
|
||||
provider_url: 'http://www.youtube.com/',
|
||||
version: '1.0',
|
||||
thumbnail_height: 360,
|
||||
title: 'RailsConf 2014 - Closing Keynote by Aaron Patterson',
|
||||
author_url: 'https://www.youtube.com/user/Confreaks',
|
||||
height: 344
|
||||
}
|
||||
WebMock.stub_request(:get, /.*youtube.*/).
|
||||
to_return(status: 200, body: response.to_json, headers: {})
|
||||
end
|
||||
|
|
@ -1,7 +1,12 @@
|
|||
require_relative 'external_request'
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
||||
config.before(:suite) do
|
||||
FactoryGirl.lint if CONFIG['factory_girl_lint']
|
||||
if CONFIG['factory_girl_lint']
|
||||
mock_commercial_request
|
||||
FactoryGirl.lint
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue