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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:57:04+00:00 2026-05-24T08:57:04+00:00

I am trying to get a Bill object to perform tests on. This is

  • 0

I am trying to get a Bill object to perform tests on. This is a US congress bill, which I have in xml via rsync on a data directory. My code takes in the name of the bill, say “h1.xml”, parses the xml and then gets the full text of the bill from http://www.govtrack.us. So, in my main app, to create a bill

  • Get a bill name (e.g. h1) (via globbing in the method def self.update_from_directory)
  def self.update_from_directory
    Dir.glob("#{Rails.root}/data/bills/small_set/*.xml").each do |bill_path|
      bill_name = bill_path.match(/.*\/(.*).xml$/)[1]
      b = Bill.find_or_create_by(:govtrack_name => bill_name)
      b.update_bill
      b.save!
    end
  end
  • Update the bill
def update_bill
    file_data = File.new("#{Rails.root}/data/bills/#{self.govtrack_name}.xml", 'r')
    bill = Feedzirra::Parser::GovTrackBill.parse(file_data)
    if bill && (self.introduced_date.nil? || (bill.introduced_date.to_date > self.introduced_date))

      self.congress = bill.congress
      self.bill_type = bill.bill_type
      self.bill_number = bill.bill_number
      ... and so on . . . until:
      get_bill_text 
  • Update the bill record with the bill text
  def get_bill_text
      bill_object = HTTParty.get("#{GOVTRACK_URL}data/us/bills.text/#{self.congress.to_s}/#{self.bill_type}/#{self.bill_type + self.bill_number.to_s}.html")
      self.bill_html = bill_object.response.body
      self.text_updated_on = Date.today
      Rails.logger.info "Updated Bill Text for #{self.ident}"
  end

My goal is very simple, I want to mock a whole bill for a test:

    def setup
       @my_test_bill = Bill.new(:govtrack_id => "h1")
       @my_test_bill.update_bill
    end

I am trying to get webmock and vcr working, but all the examples I can find, provide a way to mock a specific call and I don’t want to have to retype a whole new update_bill method.

Any thoughts greatly appreciated.

Tim

  • 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-24T08:57:05+00:00Added an answer on May 24, 2026 at 8:57 am

    Consider changing your update_bill method to:

    def update_bill
      file_data = File.new("#{Rails.root}/data/bills/#{self.govtrack_name}.xml", 'r')
      bill = Feedzirra::Parser::GovTrackBill.parse(file_data)
      if bill && (self.introduced_date.nil? || (bill.introduced_date.to_date > self.introduced_date))
    
      self.congress = bill.congress
      self.bill_type = bill.bill_type
      self.bill_number = bill.bill_number
    
      # Yield to a block that can perform arbitrary calls on this bill
      if block_given?
        yield(self)
      end
    
      # Fill bill text if empty
      if bill_html.blank? && text_updated_on.blank?
        get_bill_text
      end
    end
    

    Then change your setup method to:

    def setup
       @my_test_bill = Bill.new(:govtrack_id => "h1")
       @my_test_bill.update_bill do |bill|
         bill.text_updated_on = Date.today
         bill.bill_html = "The mock bill contents"
       end
    end
    

    That may not be exactly the solution, but this kind of approach–passing the receiver back to a block given to the method, allows you to modify the exact behavior of a given method at runtime.

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

Sidebar

Related Questions

I'm trying to get some data stored locally using IndexedDB. Below I'm I have
I have the following JSON: {COLUMNS:[ID,FIRSTNAME],DATA:[[1,Steve],[2,Jim],[3,Bill],[4,Tony]]} I am trying to write some jQuery that
i am trying to parse this xml file into an object to use the
I've been trying to somehow get my javascript function (which I have in the
Trying to get my css / C# functions to look like this: body {
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
I am trying to deserialize/map the below JSON to List<Bill > java object using
I'm trying to get an older Bill of Materials system to export parts to

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.