Downloads in verschiedenen Formaten:
Resourcen:
Gemfile
[ruby]
group :test do
gem "timecop"
gem "fakeweb"
end
[/ruby]
spec_helper.rb
[ruby]
FakeWeb.allow_net_connect = false RSpec.configure do |config|
config.before(:each) do
Timecop.return FakeWeb.clean_registry
end
end
[/ruby]
user_spec.rb
[ruby]
it "saves the time the password reset was sent" do
Timecop.freeze user.send_password_reset Time.use_zone("Paris") do
user.reload.password_reset_sent_at.should eq(Time.zone.now)
end
end
[/ruby]
web_request_spec.rb
[ruby]
it "fetches the content length" do
FakeWeb.register_uri(:head, "http://example.com/", :content_length => 123) WebRequest.new(:url =>"http://example.com/").content_length.should eq(123)
end
[/ruby]
models/web_request.rb
[ruby]
def content_length uri = URI.parse(url)
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request_head(uri.path) }
response["content-length"].to_i
end
[/ruby]
config/application.rb
[ruby]
require ’net/http‘
[/ruby]