Questions tagged [fakeweb]

FakeWeb is a helper for faking web requests in Ruby. It works at a global level, without modifying code or writing extensive stubs.

FakeWeb is a helper for faking web requests in . It works at a global level, without modifying code or writing extensive stubs.

FakeWeb lets you decouple your test environment from live services without modifying code or writing extensive stubs. In addition to the conceptual advantage of having idempotent request behaviour, FakeWeb makes tests run faster than if they were made to remote (or even local) web servers. It also makes it possible to run tests without a network connection or in situations where the server is behind a firewall or has host-based access controls.

FakeWeb works with anything based on Net::HTTP–both higher-level wrappers, like OpenURI, as well as a ton of libraries for popular web services.

Yous should be using this tag if the question is related to the use of FakeWeb or its APIs.

15 questions
8
votes
3 answers

Library like fakeweb for Python

I really like the way fakeweb in Ruby can be used to fake http requests when testing. Is there a similar library or an alternative for Python?
VoY
  • 5,111
  • 1
  • 33
  • 43
7
votes
1 answer

How to return object instead of string for response with nock?

When I stub request with nock it returns String result instead of Object even with 'Content-Type': 'application/json': var response = { success: true, statusCode: 200, body: { "status": "OK", "id": "05056b27b82", …
zishe
  • 10,055
  • 12
  • 60
  • 101
7
votes
2 answers

Downsides to using FakeWeb compared to writing mocks for testing

I never liked writing mocks and a while ago someone here recommended to use FakeWeb. I immediately fell completely in love with FakeWeb. However, I have to wonder if there is a downside to using FakeWeb. It seems like mocks are still much more…
ajmurmann
  • 1,543
  • 2
  • 14
  • 23
3
votes
3 answers

In Python, are there any libraries that mock out responses for httplib?

I'm currently using python_flickr_api to upload photos for my app: it uses httplib to perform a multipart POST request. Problem: I want to verify that the upload really is issued in an integration test by intercepting the POST request and creating a…
fatuhoku
  • 4,306
  • 2
  • 28
  • 65
2
votes
2 answers

Functionality similar to FakeWeb for Java

to test my program against webpages, which change quite often, I need to mock the answers. I've found FakeWeb for Ruby, which would be a good starting point. Unfortunately, there seems to be no library, which provides similar functionality for…
Daniel
  • 91
  • 2
  • 4
2
votes
1 answer

undefined method `it' in RSpec::Core::ExampleGroup::Nested_2

I have this error when I tried to implement "Fakeweb" and I do not understand the problem. Scenario: "After user had filled in all the information, the system will use one of the attributes "fbid" for validation and if success then only a new…
shoujo_sm
  • 3,103
  • 4
  • 33
  • 57
2
votes
1 answer

Overwriting http.request with EventEmitter

I'm using the fakeweb module which overwrites Node's http.request with the following function: var old_request = http.request; http.request = function(options, callback){ var rule = match_rule(options); if(rule){ var res = new…
bgcode
  • 24,347
  • 30
  • 92
  • 158
2
votes
1 answer

Stub a image url and return an image

How can I stub a call to a url eg http://www.example.com/images/123.png and return an image named 123.png? I'm using Rails 3.2, Carrierwave. I've tried Fakeweb but got a bit stumped.
robzolkos
  • 1,996
  • 2
  • 25
  • 43
2
votes
1 answer

List of URIs registered to FakeWeb

Is there a way to get a list of registered URIs in FakeWeb? When I register one like: FakeWeb.register_uri(:get, url, body: expected_response) It seems like it should be available somewhere since it keeps track of it internally, but I can't track…
Peter Brown
  • 48,818
  • 16
  • 106
  • 142
1
vote
1 answer

How to write a test to specify the format of a http request in ruby?

I am writing a gem and I want to check that it is performing an http request with the parameters , headers and content that its supposed to pass. How do I write a unit test. I am using httparty to do the request, I am also using fakeweb to test…
Pedro
  • 403
  • 5
  • 13
1
vote
3 answers

Testing that HTTP-request is not made in Rails

What is the easiest way to test if HTTP-request is not made? Say, I want my application NOT to send an API call to a remote server, if the user doesn't supply a username. What RSpec test should I write in my Rails app to test that HTTP-request is…
Alex Smolov
  • 1,763
  • 4
  • 22
  • 40
1
vote
0 answers

FakeWeb::NetConnectNotAllowedError

I am trying to test my app and remote control. I use Rails 3.2 and lastest version of vcr and fakeweb. Actually I have watched RailsCast and now i want to do anti testing but I cannot. My request test file; require "spec_helper" describe…
ndrx42
  • 1,129
  • 1
  • 21
  • 38
0
votes
1 answer

Stub out a request to google maps api in my tests

I try to mock out geocoding request by using FakeWeb (in cucumber/rails). When I block all http requests I get the message: Real HTTP connections are disabled. Unregistered request: GET http://maps.google.com/maps/api/geocode/json?.....…
0
votes
1 answer

ruby Fakeweb error if a Mechanize agent's read_timeout= is called

I'm using Mechanize to spider some websites. While spidering I save pages to files that I use later with Fakeweb to do tests. My Mechanize agent is created this way: Mechanize.new do |a| a.read_timeout = 20 # doesn't work with Fakeweb? …
marcel massana
  • 337
  • 2
  • 11
0
votes
0 answers

How to get a list of fake websites, such as spoofed urls/websites?

I am looking for a list of popular fake websites that impersonate legitimate websites, e.g. spoofed websites. I have searched in the internet but I couldn't find such a list. Does anyone have an idea of how to get a list containing fake websites?