class Shokkenki::Consumer::DSL::Order

Public Class Methods

new(patronage) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 14
def initialize patronage
  @patronage = patronage
  @fixtures = []
end

Public Instance Methods

and_respond(details) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 29
def and_respond details
  @response_details = details
  self
end
during(label) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 19
def during label
  @interaction_label = label
  self
end
given(name, arguments=nil) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 34
def given name, arguments=nil
  @fixtures << Shokkenki::Consumer::Model::Fixture.new(
    :name => name,
    :arguments => arguments
  )
  self
end
method_missing(method, *args, &block) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 66
def method_missing(method, *args, &block)
  @caller_context.send method, *args, &block
end
receive(details) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 24
def receive details
  @request_details = Shokkenki::Consumer::Model::Request.new details
  self
end
to(&block) click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 56
def to &block
  # allows caller context and order to both be referenced from block
  # see http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation (instance_eval + delegation)
  @caller_context = eval 'self', block.binding

  instance_eval &block
  validate!
  @patronage.add_interaction to_interaction
end
to_interaction() click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 47
def to_interaction
  Shokkenki::Consumer::Model::Interaction.new(
    :label => @interaction_label,
    :request => @request_details,
    :response => @response_details,
    :fixtures => @fixtures
  )
end
validate!() click to toggle source
# File lib/shokkenki/consumer/dsl/order.rb, line 42
def validate!
  raise "No request has been specified." unless @request_details
  raise "No response has been specified." unless @response_details
end