I have set up FakeWeb to return some XML files that I pulled down from
another app of mine. I'm accessing these as ActiveResource objects. In
config/environments/test.rb I've added the following:
FakeWeb.allow_net_connect = false
%w{person1 person2 person3}.each do |internet_id|
file = File.new("#{RAILS_ROOT}/test/fakeweb/#{internet_id}.xml",
"r")
FakeWeb.register_uri(:get, "
https://example.com/people/#
{internet_id}.xml", :string => file)
FakeWeb.register_uri(:get, "
https://example.com:443/people/#
{internet_id}.xml", :string => file)
end
Person.rb is an ActiveResource, with the following:
self.site = "
https://example.com/"
Person.find 'person1' returns the XML the first time, but calling it a
second time breaks when FakeWeb is activated. I can request multiple
people without issue, but once I try to get one a second time, I get
the following error:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[] (NoMethodError)
/opt/local/lib/ruby/1.8/rexml/source.rb:150:in `initialize'
/opt/local/lib/ruby/1.8/rexml/source.rb:16:in `new'
/opt/local/lib/ruby/1.8/rexml/source.rb:16:in `create_from'
/opt/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:130:in
`stream='
/opt/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:107:in
`initialize'
/opt/local/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `new'
/opt/local/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in
`initialize'
/opt/local/lib/ruby/1.8/rexml/document.rb:204:in `new'
/opt/local/lib/ruby/1.8/rexml/document.rb:204:in `build'
/opt/local/lib/ruby/1.8/rexml/document.rb:42:in `initialize'
I'm not sure what is causing this. Any insight would be greatly
appreciated. Thanks in advance!