Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7051633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:17:13+00:00 2026-05-28T03:17:13+00:00

When trying to mock a Faraday::Response object, I’ve tried: mock(Faraday::Response, :env => {:body =>

  • 0

When trying to mock a Faraday::Response object, I’ve tried:

mock(Faraday::Response, :env => {:body => "...some xml..."})

…but this fails when I call response.body.xpath(...), because the body is a String, and it’s expecting a NodeSet.

Is there an easy way to convert an arbitrary XML string into a NodeSet? I’ve read through the Nokogiri::XML::NodeSet docs, but it’s either not there, or I’m missing it.

Here’s my actual stub+mock:

@conn.stub!(:get).and_return(mock Faraday::Response,
      :env => {:status=>207},
      :body => '<scheduled-calendar xmlns="[removed]" xmlns:xsi="[removed]" id="95ec6d99-2c4a-4e25-99a1-2e988c0dbce6" assignment-id="uuid_for_test" xsi:schemaLocation="[removed]" debug="true">
                <scheduled-study-segment id="4e5b24e3-b50a-45e2-aec1-cb6c839a20f1" start-date="2012-01-06" start-day="1" study-segment-id="524910e9-634a-4791-a0b2-90f506a86474">
                <scheduled-activity id="1caa08b2-acb0-4c93-8c76-6460f0e9ee09" ideal-date="2012-01-06" details="Screening survey" repetition-number="0" planned-activity-id="1fc520dd-5b6f-4125-b83c-2f8801ea3065">
                <current-scheduled-activity-state reason="Initialized from template" date="2012-01-06" state="conditional"/>
                </scheduled-activity>
                </scheduled-study-segment>
                </scheduled-calendar>'
    )

Here’s the call to xpath

response.body.xpath('//psc:scheduled-activity', Psc.xml_namespace).collect{|activity| activity.attributes["id"].value}

And here is the test failure:

NoMethodError in 'PscV1 should allow you to get a list of scheduled activity ids for a given involvement'
undefined method `xpath' for #<String:0x10dad1818>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:17:13+00:00Added an answer on May 28, 2026 at 3:17 am

    So, essentially the answer turned out to be that Faraday wasn’t treating my body as XML, and as a result, just passed the response back as a String, instead of a Nokogiri::XML::Document

    By doing…

    xml = Nokogiri::XML('<scheduled-calendar xmlns="[removed]" xmlns:xsi="[removed]" id="95ec6d99-2c4a-4e25-99a1-2e988c0dbce6" assignment-id="uuid_for_test" xsi:schemaLocation="[removed]" debug="true">
                <scheduled-study-segment id="4e5b24e3-b50a-45e2-aec1-cb6c839a20f1" start-date="2012-01-06" start-day="1" study-segment-id="524910e9-634a-4791-a0b2-90f506a86474">
                <scheduled-activity id="1caa08b2-acb0-4c93-8c76-6460f0e9ee09" ideal-date="2012-01-06" details="Screening survey" repetition-number="0" planned-activity-id="1fc520dd-5b6f-4125-b83c-2f8801ea3065">
                <current-scheduled-activity-state reason="Initialized from template" date="2012-01-06" state="conditional"/>
                </scheduled-activity>
                </scheduled-study-segment>
                </scheduled-calendar>')
    

    And then passing that xml variable in as the body…

    @conn.stub!(:get).and_return(mock Faraday::Response,
      :env => {:status=>207},
      :body => xml
    )
    

    …the issue was resolved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to mock the following method: bool IsLoginValid(LoginViewModel viewModel, out User user); Tried this
I´m encountering this problem trying to mock some objects that receive complex lambda expressions
I'm trying to mock a data repository object but after setting an expectation on
I'm trying to mock MouseButtonEventArgs.GetPosition() with Moq, but I keep receiving this error: System.ArgumentException:
I am trying to Mock an object that is being passed into another object,
I am trying to use Rhino Mocks to mock the following lambda, but keep
I'm trying to use Rhinomocks 3.5 and the new lambda notation to mock some
I am trying to mock some reflection based methods. Below you can see the
I am trying to mock a class using Mockito and also using PowerMock. This
I am trying to mock the following call: s.socket().bind(new InetSocketAddress(serverIPAddress_, serverPort_), 0); so I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.