spec/fakeweb_helper.rb in anemone-0.5.0 vs spec/fakeweb_helper.rb in anemone-0.6.0

- old
+ new

@@ -7,10 +7,11 @@ FakeWeb.allow_net_connect = false module Anemone SPEC_DOMAIN = "http://www.example.com/" + AUTH_SPEC_DOMAIN = "http://user:pass@#{URI.parse(SPEC_DOMAIN).host}/" class FakePage attr_accessor :links attr_accessor :hrefs attr_accessor :body @@ -18,10 +19,11 @@ def initialize(name = '', options = {}) @name = name @links = [options[:links]].flatten if options.has_key?(:links) @hrefs = [options[:hrefs]].flatten if options.has_key?(:hrefs) @redirect = options[:redirect] if options.has_key?(:redirect) + @auth = options[:auth] if options.has_key?(:auth) @content_type = options[:content_type] || "text/html" @body = options[:body] create_body unless @body add_to_fakeweb @@ -29,10 +31,14 @@ def url SPEC_DOMAIN + @name end + def auth_url + AUTH_SPEC_DOMAIN + @name + end + private def create_body @body = "<html><body>" @links.each{|l| @body += "<a href=\"#{SPEC_DOMAIN}#{l}\"></a>"} if @links @@ -54,10 +60,18 @@ FakeWeb.register_uri(:get, redirect_url, {:body => '', :content_type => @content_type, :status => [200, "OK"]}) end - FakeWeb.register_uri(:get, SPEC_DOMAIN + @name, options) + if @auth + unautorized_options = { + :body => "Unauthorized", :status => ["401", "Unauthorized"] + } + FakeWeb.register_uri(:get, SPEC_DOMAIN + @name, unautorized_options) + FakeWeb.register_uri(:get, AUTH_SPEC_DOMAIN + @name, options) + else + FakeWeb.register_uri(:get, SPEC_DOMAIN + @name, options) + end end end end #default root