Parent

WebMock::RequestStub

Attributes

request_pattern[RW]

Public Class Methods

new(method, uri) click to toggle source
# File lib/webmock/request_stub.rb, line 6
def initialize(method, uri)
  @request_pattern = RequestPattern.new(method, uri)
  @responses_sequences = []
  self
end

Public Instance Methods

response() click to toggle source
# File lib/webmock/request_stub.rb, line 38
def response
  if @responses_sequences.empty?
    WebMock::Response.new
  elsif @responses_sequences.length > 1
    @responses_sequences.shift if @responses_sequences.first.end?
    @responses_sequences.first.next_response
  else
    @responses_sequences[0].next_response
  end
end
then() click to toggle source
# File lib/webmock/request_stub.rb, line 49
def then
  self
end
times(number) click to toggle source
# File lib/webmock/request_stub.rb, line 53
def times(number)
  raise "times(N) accepts integers >= 1 only" if !number.is_a?(Fixnum) || number < 1
  if @responses_sequences.empty?
    raise "Invalid WebMock stub declaration." +
      " times(N) can be declared only after response declaration."
  end
  @responses_sequences.last.times_to_repeat += number-1
  self
end
to_raise(*exceptions) click to toggle source
# File lib/webmock/request_stub.rb, line 26
def to_raise(*exceptions)
  @responses_sequences << ResponsesSequence.new([*exceptions].flatten.map {|e| 
    ResponseFactory.response_for(:exception => e)
  })
  self
end
to_return(*response_hashes, &block) click to toggle source
# File lib/webmock/request_stub.rb, line 17
def to_return(*response_hashes, &block)
  if block
    @responses_sequences << ResponsesSequence.new([ResponseFactory.response_for(block)])
  else
    @responses_sequences << ResponsesSequence.new([*response_hashes].flatten.map {|r| ResponseFactory.response_for(r)})
  end
  self
end
to_timeout() click to toggle source
# File lib/webmock/request_stub.rb, line 33
def to_timeout
  @responses_sequences << ResponsesSequence.new([ResponseFactory.response_for(:should_timeout => true)])
  self
end
with(params = {}, &block) click to toggle source
# File lib/webmock/request_stub.rb, line 12
def with(params = {}, &block)
  @request_pattern.with(params, &block)
  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.