I have a ruby method written and I need to test it. Below is my method.

    def iterate_each_doc
      count=1
      arr_of_doc = []
      max_offset = 700
      loop do
        begin
          feed_url = "http://www.example.com?q=&page=#{count}";
          json_doc = JSON.parse(page)
          jsons_rec = get_json_rec(json_doc)
    
          if jsons_rec.size > 0
            arr_of_doc += jsons_rec
          end
    
          count += 1
          break if json_doc["list"].empty? && offset > json_doc["lastPage"]
    
        rescue
          catch exception
        end
      end
      arr_of_doc
    end

I tested the return value of the method as below

    it "should fetch from json document and return an array of videos 
containing only full episodes" do
          stub_request(:get, url).to_return(status: 200, :body => 
File.read(File.join(json_saved_pages_path, 'sample.json')))
          result = subject.iterate_each_doc
          result.should_not be_empty
          result.size == 3
     end

But I need to make sure that the loop executes without any fail and
breaks only till it satisfies the condition

i.e.

    if json_doc["list"].empty? && offset > json_doc["lastPage"]

This condition will satisfy till lastpage of the json doc is 700. But
in my rspec I cannot allow to execute the loop everytime till the
condition. So what would be the best way to achieve this. Please help.


-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/ffb5adc1-2efb-414f-8881-d2b9fc9d2c93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to