with headers {'Accept'=>'*/*', 'User- Agent'=>'Ruby'} (WebMock::NetConnectNotAllowedError) You can stub this request with the following snippet: stub_request(:get, "https://api.github.com/users/bioritmo/repos"). with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}). to_return(:status => 200, :body => "", :headers => {}) registered request stubs: stub_request(:get, "https://api.github.com/users/rodrigoflores/repos") ============================================================ from request_fakeweb.rb:16:in `<main>' É possível desativar e permitir requests HTTP Saturday, June 22, 13
true request = Net::HTTP::Get.new(uri.request_uri) VCR.use_cassette('repos') do response = http.request(request) repos = JSON.parse(response.body) repos.each do |repo| puts repo['name'] end end Saturday, June 22, 13
Faraday.new(:url => 'https://api.github.com') do | faraday| faraday.adapter :test do |stub| stub.get('/users/rodrigoflores/repos') do [ 200, { 'Content-Type' => 'application/json; charset=utf-8' }, File.read('response.json') ] end end faraday.response :json, :content_type => /\bjson$/ end repos = conn.get('/users/rodrigoflores/repos').body repos.each do |repo| puts repo['name'] end Saturday, June 22, 13
como uma aplicação Ruby Tomar cuidado para não fazer requests em teste (pelo menos não o tempo todo) Testes de contrato valem a pena? Saturday, June 22, 13
"shows the version info" do get :index parsed_response = JSON.parse(response.body) parsed_response['version'].should == '3.2.19' end it "has a max-age of 10 minutes" do get :index response.headers['Cache-Control'].should == "max- age=600, public" end it 'has a 200 status' do get :index response.status.should == 200 end end end Saturday, June 22, 13