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 9144555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:17:54+00:00 2026-06-17T10:17:54+00:00

I have a requirement to read a third-party public website. Currently I am able

  • 0

I have a requirement to read a third-party public website. Currently I am able to do this via Nokogiri, but I’m having trouble writing some unit tests using rspec.

I have this HTML <div>:

<div class="user">
  <div class="name">User Name</div>
</div>

In my Reader model I have the method name, which reads the name from the HTML:

class SampleReader
    def name(html_div)
      html_div.css('name')
    end
end

In my RSpec test case I pass the above HTML <div> as a string to the name method and I get the following error:

undefined method `css' for #<String:0x007fd8a0b39c98>

I believe it’s because Nokogiri cannot identified the string as HTML, so I would appreciate if someone can help me write the test case. And, if possible, my preferred option is to pass only the <div> string, not the entire HTML page source, to the method.

  • I’m using Rails 3.2.9
  • Rspec2
  • Nokogiri
  • 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-06-17T10:17:55+00:00Added an answer on June 17, 2026 at 10:17 am

    You’ll need to wrap the HTML string as a Nokogiri document:

    require 'nokogiri'
    
    str = <<-HTML
    <div class="user">
      <div class="name">User Name</div>
    </div>
    HTML
    
    class SampleReader
      def name(html_div)
        doc = Nokogiri::HTML(html_div)
        doc.css('.name').text
      end
    end
    
    reader = SampleReader.new
    puts reader.name(str) #=> "User Name"
    

    Also, don’t forget to upgrade your application to rails 3.2.11.

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

Sidebar

Related Questions

I have a requirement to create an installer that includes third party dll's that
I have a specific requirement to read a resource from jar file and then
I have a requirement where i have to read data streams coming on serial
I have requirement to disable copy/paste/cut operations on a textbox. For this purpose I
Hi i have requirement to process large number of files via multithreading in java.
I have been researching various third party libraries and approaches to low latency serial
i have a requirement to read data from a gif. The gif is exported
I start learning packaging for several distros (currently Cygwin and Debian). They have requirement
I have a requirement of waiting using read until a buffer is full on
I need some advice. (For those who have already read this before I have

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.