Mocking capybara page object - Rails / RSpec

Question!

I am working on a web crawler which accesses remote pages by submitting search queries via the remote site's search bar:

class Crawler < PoltergeistDriver

   def fetch_listing_page(query)
    ...
    visit 'whatever.com'
    fill_in('#seachbar', with: query)
    find('#searchbar').native.send_key(:return)
    ...
  end

end

I then use the page object to search for specific text inside the body like so:

class Crawler < PoltergeistDriver
  ...

  def fetch_listing_data
    ...
    page.all('some element', ...)
    ...
  end

  ...

end

My question is can I mock this page object in my tests? My guess is that VCR / Webmock would not work as the requests are made from the client side (poltergeist in my case).

By : Dimitry_N


Answers

You can't use WebMock/VCR for this, but you can use a programmable proxy. PuffingBilly - https://github.com/oesmith/puffing-billy - is one that integrates nicely with capybara and poltergeist.



typedef unsigned char uint8_t; /* Not necessary if you are using C99, i.e. <stdint.h>. */

uint8_t buffer[BUF_SIZE] = {0};
    .
    .
    .
if (fread(buffer, sizeof(buffer[0]), 1, file) == 1)
{
    buffer[0] ^= 0xFFu; /* Or any other bit-wise operation. */
}

Refer -
1. https://linux.die.net/man/3/fread
2. http://en.cppreference.com/w/c/types/integer

By : work.bin


Binary operation can be performed on char data type with unsigned. Even if its an array binary operation can be done to the single element of the array.

for your reference.

ssize_t read(int fd, void *buf, size_t count);

buffer has to be address of the character or character array, in your single char is sufficient. If you want to use array use the element array[0] and perform operation on that.

As mentioned in the comments above

unsigned char c; 
read(file, &c, 1);


This video can help you solving your question :)
By: admin