mocking external requests

This commit is contained in:
Tyrel Souza 2014-05-06 11:13:58 -04:00
parent adf4ad8c51
commit 01af9115a0
7 changed files with 64 additions and 17 deletions

View File

@ -52,6 +52,7 @@ group :test do
gem 'simplecov', "~> 0.7.1" gem 'simplecov', "~> 0.7.1"
gem 'timecop' gem 'timecop'
gem 'webmock' gem 'webmock'
gem 'sinatra'
end end
group :production do group :production do

View File

@ -177,6 +177,8 @@ GEM
pry-rails (0.3.2) pry-rails (0.3.2)
pry (>= 0.9.10) pry (>= 0.9.10)
rack (1.5.2) rack (1.5.2)
rack-protection (1.5.3)
rack
rack-test (0.6.2) rack-test (0.6.2)
rack (>= 1.0) rack (>= 1.0)
rack-timeout (0.0.4) rack-timeout (0.0.4)
@ -229,6 +231,10 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
simplecov-html (~> 0.7.1) simplecov-html (~> 0.7.1)
simplecov-html (0.7.1) simplecov-html (0.7.1)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.5.0) slop (3.5.0)
spring (1.1.2) spring (1.1.2)
spring-commands-rspec (1.0.2) spring-commands-rspec (1.0.2)
@ -310,6 +316,7 @@ DEPENDENCIES
shoulda-matchers shoulda-matchers
simple_form! simple_form!
simplecov (~> 0.7.1) simplecov (~> 0.7.1)
sinatra
spring spring
spring-commands-rspec spring-commands-rspec
timecop timecop

View File

@ -29,23 +29,7 @@
<video class="video-js vjs-blue-skin" id="bvVideo1" preload="auto" controls> <video class="video-js vjs-blue-skin" id="bvVideo1" preload="auto" controls>
<source src="//video2.bettervideo.com/video/PRO/MP4640x360/720.<%= @videolisting.videocode %>.mp4" type="video/mp4"></source> <!-- Video URL goes here" --> <source src="//video2.bettervideo.com/video/PRO/MP4640x360/720.<%= @videolisting.videocode %>.mp4" type="video/mp4"></source> <!-- Video URL goes here" -->
</video> </video>
<script>
videojs('bvVideo1',{
"width": 640,
"height": 360,
"poster": '//video2.bettervideo.com/video/PRO/JPG640x360/720.<%= @videolisting.videocode %>.jpg', // Video Preview URL goes here
"plugins": {
"errors": {},
"bvSocial": {"reddit":false,"delicious":false},
"bvReporting": {
"secondaryGA":"UA-XXXXXXXX-X", /* Put your Google Analytics UID here */
"secondaryLabel":"Interactive Video"
},
"bvThemeLoader": {}
}
}, function() { /* Player Ready Callback, 'this' => reference to this player */ } );
</script>
</div> </div>
</li> </li>
@ -63,5 +47,20 @@
var clip = new ZeroClipboard($("#clip_button")); var clip = new ZeroClipboard($("#clip_button"));
}); });
</script> </script>
<script>
videojs('bvVideo1',{
"width": 640,
"height": 360,
"poster": '//video2.bettervideo.com/video/PRO/JPG640x360/720.<%= @videolisting.videocode %>.jpg', // Video Preview URL goes here
"plugins": {
"errors": {},
"bvSocial": {"reddit":false,"delicious":false},
"bvReporting": {
"secondaryGA":"UA-XXXXXXXX-X", /* Put your Google Analytics UID here */
"secondaryLabel":"Interactive Video"
},
"bvThemeLoader": {}
}
}, function() { /* Player Ready Callback, 'this' => reference to this player */ } );
</script>
<% end %> <% end %>

View File

@ -0,0 +1,11 @@
require 'spec_helper'
require 'json'
feature 'External request' do
it 'queries FactoryGirl contributors on Github' do
uri = URI('http://servicestest.bettervideo.com/orders/MDS.OrdersWS.svc/addVideo')
response = JSON.parse(Net::HTTP.get(uri))
expect(response['success']).to eq(true)
end
end

View File

@ -29,3 +29,9 @@ end
Capybara.javascript_driver = :webkit Capybara.javascript_driver = :webkit
WebMock.disable_net_connect!(allow_localhost: true) WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.before(:each) do
stub_request(:any, /servicestest.bettervideo.com/).to_rack(FakeBetterVideo)
end
end

View File

@ -0,0 +1,16 @@
# spec/support/fake_github.rb
require 'sinatra/base'
class FakeBetterVideo < Sinatra::Base
get '/orders/MDS.OrdersWS.svc/addVideo' do
json_response 200, 'bettervideo_0.json'
end
private
def json_response(response_code, file_name)
content_type :json
status response_code
File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
end
end

View File

@ -0,0 +1,7 @@
{
"errorcode": "0",
"errormessage": "Success",
"listingcode": "242000",
"success": true,
"videocode": "242001"
}