Module: FbGraph::Mock

Defined in:
lib/fb_graph/mock.rb

Instance Method Summary collapse

Instance Method Details

#mock_fql(query, response_file, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fb_graph/mock.rb', line 27

def mock_fql(query, response_file, options = {})
  options[:params] ||= {}
  options[:params].merge!(:q => query)
  stub_request(:get, FbGraph::Query.new(query).endpoint).with(
    request_for(:get, options)
  ).to_return(
    response_for(response_file, options)
  )
  if block_given?
    response = yield
    a_request(:get, FbGraph::Query.new(query).endpoint).with(
      request_for(:get, options)
    ).should have_been_made.once
    response
  end
end

#mock_graph(method, path, response_path, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fb_graph/mock.rb', line 6

def mock_graph(method, path, response_path, options = {})
  stub_request(
    method,
    endpoint_for(path)
  ).with(
    request_for(method, options)
  ).to_return(
    response_for(response_path, options)
  )
  if block_given?
    response = yield
    a_request(
      method,
      endpoint_for(path)
    ).with(
      request_for(method, options)
    ).should have_been_made.once
    response
  end
end

#request_to(path, method = :get) ⇒ Object



44
45
46
47
48
49
# File 'lib/fb_graph/mock.rb', line 44

def request_to(path, method = :get)
  raise_error(WebMock::NetConnectNotAllowedError) { |e|
    e.message.should include("Unregistered request: #{method.to_s.upcase}")
    e.message.should include(endpoint_for path)
  }
end