46. ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/autorun'
require 'rspec/rails’
require 'fb_graph/mock'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.order = 'random'
config.include FbGraph::Mock
end
WebMock.disable_net_connect!
spec/spec_helper.rb
47. describe FacebookWrapper, '.user_link' do
it 'retrieves user link' do
mock_graph :get, 'arjun', 'users/arjun_public' do
user_id = FacebookWrapper.user_id('arjun')
expect(user_id).to eq '7901103'
end
end
end
spec/lib/facebook_wrapper_spec.rb
48. describe FacebookWrapper, '.user_link' do
it 'retrieves user link' do
mock_graph :get, 'arjun', 'users/arjun_public' do
user_id = FacebookWrapper.user_id('arjun')
expect(user_id).to eq '7901103'
end
end
end
spec/lib/facebook_wrapper_spec.rb
52. ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/autorun'
require 'rspec/rails’
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.order = 'random’
end
WebMock.disable_net_connect!
spec/spec_helper.rb
53. ShamRack.at('graph.facebook.com', 443).sinatra do
get '/:username' do
%Q|{
"id": "7901103",
"name": "Arjun Banker",
"first_name": "Arjun",
"last_name": "Banker",
"link": "http://www.facebook.com/#{params[:username]}",
"location": {
"id": 114952118516947,
"name": "San Francisco, California"
},
"gender": "male"
}|
end
end
spec/support/fake_facebook.rb
54. ShamRack.at('graph.facebook.com', 443).sinatra do
get '/:username' do
%Q|{
"id": "7901103",
"name": "Arjun Banker",
"first_name": "Arjun",
"last_name": "Banker",
"link": "http://www.facebook.com/#{params[:username]}",
"location": {
"id": 114952118516947,
"name": "San Francisco, California"
},
"gender": "male"
}|
end
end
spec/support/fake_facebook.rb
55. ShamRack.at('graph.facebook.com', 443).sinatra do
get '/:username' do
%Q|{
"id": "7901103",
"name": "Arjun Banker",
"first_name": "Arjun",
"last_name": "Banker",
"link": "http://www.facebook.com/#{params[:username]}",
"location": {
"id": 114952118516947,
"name": "San Francisco, California"
},
"gender": "male"
}|
end
end
spec/support/fake_facebook.rb
56. ShamRack.at('graph.facebook.com', 443).sinatra do
get '/:username' do
%Q|{
"id": "7901103",
"name": "Arjun Banker",
"first_name": "Arjun",
"last_name": "Banker",
"link": "http://www.facebook.com/#{params[:username]}",
"location": {
"id": 114952118516947,
"name": "San Francisco, California"
},
"gender": "male"
}|
end
end
spec/support/fake_facebook.rb
57. describe FacebookWrapper, '.user_link' do
it 'retrieves user link' do
user_id = FacebookWrapper.user_id('arjun')
expect(user_id).to eq '7901103’
end
end
spec/lib/facebook_wrapper_spec.rb
60. ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/autorun'
require 'rspec/rails’
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.order = 'random’
end
WebMock.disable_net_connect!
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
end
spec/spec_helper.rb
61. describe FacebookWrapper, '.user_link' do
it 'retrieves user link' do
VCR.use_cassette('fb_user_arjun') do
user_id = FacebookWrapper.user_id('arjun')
expect(user_id).to eq '7901103'
end
end
end
spec/lib/facebook_wrapper_spec.rb
62. describe FacebookWrapper, '.user_link' do
it 'retrieves user link' do
VCR.use_cassette('fb_user_arjun') do
user_id = FacebookWrapper.user_id('arjun')
expect(user_id).to eq '7901103'
end
end
end
spec/lib/facebook_wrapper_spec.rb
Includes: things like Stripe, or an internal API, or an iPhone app calling into an API exposed by your rails app
LA kings checkingchicagoblackhawks
Can back with yaml
Can back with yaml
Can back with yaml
Can back with yaml
Re-writing web proxyAllowed to record and reuse (like VCR)
Can back with yaml
Ubiquitous PowerfulIn-browser (so easy!)
Easily send requestsEasy-to-use GUI
Postman without the GUICould run small scripts around it
re-writing web proxyTest mobile as well as desktopGood for collecting a lot of responsesGood for testing things that aren’t specific page loads in ChromeGood when you don’t know what’s even being requested!