I think you can easily accomplish this task declaring a variable, using
file.open to read a XML from your file system, and stubbing your method
call on your test. This is the most common way of doing some tests with
third party apis. But, if you want a more reliable way to do some test
with
API, I would recommended for you to try VCR. I am not a minitest guy,
but I
think VCR have setup to works fine with minitest too.
Have a nice day man
On Sunday, June 9, 2013, Linus P. wrote:
To get an artist I do
def self.find(name: nil)
an XML file from disk.
To post to this group, send email to [email protected]<javascript:_e({}, ‘cvml’,
‘[email protected]’);>
.
To view this discussion on the web visit
lib/my_lib/track.rb
calls and parses the XML response with Nokogiri
When writing my tests I don't want to hit the actual URL but instead
load an XML file from disk.
I'm using Minitest which has a mocking library, but how do I actually
mock (or is it more appropriate to stub?) the method?
I think you can easily accomplish this task declaring a variable, using
file.open to read a XML from your file system, and stubbing your method
call on your test. This is the most common way of doing some tests with
third party apis. But, if you want a more reliable way to do some test with
API, I would recommended for you to try VCR. I am not a minitest guy, but I
think VCR have setup to works fine with minitest too.
I suggest you use both WebMock and VCR. WebMock mocks out the HTTP calls
the API code is doing, and lets VCR record the response the first time,
and play it back from then on.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.