Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using webmock, fixing tests.

  • Loading branch information...
commit 724cbe6ea83413c11f90dfbe1e7a9a1c56c8489f 1 parent 2310018
@lunks lunks authored
View
2  app/fotolog.rb
@@ -29,7 +29,7 @@ def photos
end
def photos_for_month year, month
- doc = Nokogiri::HTML(@client.get_content("http://www.fotolog.com.br/#{@user}/archive/#{'0' if month.to_i < 10}#{month.to_i}/#{year}"))
+ doc = Nokogiri::HTML(@client.get_content("http://www.fotolog.com.br/#{@user}/archive/#{month.to_i}/#{year}/"))
doc.css('.calendar_month_day img').map do |photo|
full_image_for photo.attributes['src'].value
end
View
12 spec/fotolog_spec.rb
@@ -3,7 +3,7 @@
describe Fotolog do
context 'for non existent fotolog' do
- before { FakeWeb.register_uri(:get, "http://www.fotolog.com/this_fotolog_doesnt_exists/archive", :body => fixture_file('non_existent_fotolog.html'), :status => ["404", "Not Found"]) }
+ before { stub_request(:get, "http://www.fotolog.com.br/this_fotolog_doesnt_exists/archive/").to_return(:body => fixture_file('non_existent_fotolog.html'), :status => ["404", "Not Found"]) }
let(:fotolog) { Fotolog.new 'this_fotolog_doesnt_exists' }
it 'should tell it is not valid' do
fotolog.should_not be_valid
@@ -12,7 +12,7 @@
context 'that exists' do
before(:each) do
- FakeWeb.register_uri(:get, "http://www.fotolog.com/marano/archive", :body => fixture_file('archive.html'))
+ stub_request(:get, "http://www.fotolog.com.br/marano/archive/").to_return(:body => fixture_file('archive.html'))
end
let(:fotolog) { Fotolog.new 'marano' }
it 'should tell it is valid' do
@@ -20,7 +20,7 @@
end
context 'retrieving archive information' do
before(:each) do
- FakeWeb.register_uri(:get, "http://www.fotolog.com/marano/archive", :body => fixture_file('archive.html'))
+ stub_request(:get, "http://www.fotolog.com.br/marano/archive/").to_return(:body => fixture_file('archive.html'))
end
it 'should retrieve user archive URL' do
fotolog.archive_url.should == 'http://www.fotolog.com.br/marano/archive/'
@@ -37,7 +37,7 @@
context 'retrieving photos' do
before(:each) do
- FakeWeb.register_uri(:get, "http://www.fotolog.com.br/marano/archive?year=2008&month=09", :body => fixture_file('photos.html'))
+ stub_request(:get, "http://www.fotolog.com.br/marano/archive/9/2008/").to_return(:body => fixture_file('photos.html'))
end
it 'should retrieve photo urls' do
@@ -62,7 +62,7 @@
end
pending 'should get new photos to cache' do
- FakeWeb.register_uri(:get, "http://www.fotolog.com.br/gabocaa/archive", :body => fixture_file('uncached_archive.html') )
+ stub_request(:get, "http://www.fotolog.com.br/gabocaa/archive/").to_return(:body => fixture_file('uncached_archive.html') )
mock_requests_fixture_for_fotolog 'gabocaa'
fotolog.retrieve_photos
fotolog = Fotolog.new 'gabocaa'
@@ -70,7 +70,7 @@
fotolog.update_cache.should be_false
end
pending 'should not find any photos to a fotolog not updated' do
- FakeWeb.register_uri(:get, "http://www.fotolog.com.br/gabocaa/archive", :body => fixture_file('cached_archive.html') )
+ stub_request(:get, "http://www.fotolog.com.br/gabocaa/archive/").to_return(:body => fixture_file('cached_archive.html') )
mock_requests_fixture_for_fotolog 'gabocaa'
fotolog.retrieve_photos
fotolog = Fotolog.new 'gabocaa'
View
22 spec/main_controller_spec.rb
@@ -28,7 +28,7 @@ def app
end
context 'given a non existent fotolog' do
- before { FakeWeb.register_uri(:get, "http://www.fotolog.com/this_fotolog_doesnt_exists/archive", :body => fixture_file('non_existent_fotolog.html'), :status => ["404", "Not Found"]) }
+ before { stub_request(:get, "http://www.fotolog.com.br/this_fotolog_doesnt_exists/archive/").to_return(:body => fixture_file('non_existent_fotolog.html'), :status => ["404", "Not Found"]) }
before do
get '/this_fotolog_doesnt_exists'
end
@@ -74,17 +74,27 @@ def app
end
end
context 'slide show' do
- before { get '/marano/slide' }
+ before do
+ stub_request(:get, "http://www.fotolog.com.br/marano/archive/").to_return(body: fixture_file('archive.html'))
+ mock_requests_fixture_for_fotolog 'marano'
+ get '/marano/slide'
+ end
+
it 'should be ok' do
last_response.should be_ok
end
end
context 'rss feed' do
- before { get '/marano/feed' }
- it 'should be ok' do
- last_response.should be_ok
- end
+ before do
+ stub_request(:get, "http://www.fotolog.com.br/marano/archive/").to_return(body: fixture_file('archive.html'))
+ mock_requests_fixture_for_fotolog 'marano'
+ get '/marano/feed'
+ end
+
+ it 'should be ok' do
+ last_response.should be_ok
+ end
end
end
View
12 spec/spec_helper.rb
@@ -2,7 +2,8 @@
require 'sinatra'
require 'rack/test'
-require 'fakeweb'
+require 'webmock'
+require 'webmock/rspec'
require 'mocha/setup'
set :environment, :test
@@ -11,22 +12,23 @@
set :views => File.join(File.dirname(__FILE__), "..", "views")
-FakeWeb.allow_net_connect = false
+WebMock.disable_net_connect!(:allow_localhost => true)
def fixture_file(file)
File.open(File.join(File.dirname(__FILE__), 'fixtures', file), 'r:utf-8').read
end
def mock_requests_fixture_for_fotolog name
- FakeWeb.register_uri(:get, "http://www.fotolog.com/#{name}/archive", :body => fixture_file('archive.html'))
+ stub_request(:get, "http://www.fotolog.com/#{name}/archive/").to_return(:body => fixture_file('archive.html'))
+ stub_request(:get, "http://www.fotolog.com.br/#{name}/archive/").to_return(:body => fixture_file('archive.html'))
(2003..2013).to_a.each do |year|
(1..12).to_a.each do |month|
- FakeWeb.register_uri(:get, "http://www.fotolog.com.br/#{name}/archive/#{'0' if month.to_i < 10}#{month}/#{year}", :body => fixture_file('photos.html'))
+ stub_request(:get, "http://www.fotolog.com.br/#{name}/archive/#{month}/#{year}/").to_return(:body => fixture_file('photos.html'))
end
end
- FakeWeb.register_uri(:get, "http://www.fotolog.com.br/#{name}/archive?year=2008&month=09", :body => fixture_file('photos.html'))
+ stub_request(:get, "http://www.fotolog.com.br/#{name}/archive/9/2008/").to_return(:body => fixture_file('photos.html'))
end
Cache.stubs(:instance).returns(CacheStub.new)
Please sign in to comment.
Something went wrong with that request. Please try again.