This is what I use in my specifications:
let(:doc) { IO.read(Rails.root.join("spec", "fixtures", "api_response.xml")) }
It will copy the contents of the file to a string.
Please note that I disabled the default ActiveRecord settings for RSpec, so instead I put my lights in this directory.
Update: with Rspec Rails 3.5 and later
can also use file_fixture
let(:doc) { file_fixture("api_response.xml").read }
for
files stored in spec / fixtures / files by default
but the file location can be customized.
James source share