class Shoegaze::Scenario
Public Class Methods
# File lib/shoegaze/scenario.rb, line 6 def initialize(method_name, &block) @_method_name = method_name self.instance_eval(&block) end
Public Instance Methods
Specifies the datasource (actual implementation code) for the implementation scenario. This is ruby code in a block. The result of this block is fed into the scenario representer, if one is specified, or returned untouched if the scenario is not represented.
@param block [Block] The implementation for the scenario's data source expressed as a block. @return [Block] The block
# File lib/shoegaze/scenario.rb, line 89 def datasource(&block) @_datasource = block end
Specifies the method to call on the scenario's representer. Common examples as :as_json or :to_json. You can omit this and, if a representer is specified, the representer itself will be returned. This is a getter and a setter. Call it with no arg to get the current representation_method.
@param representation_method [Symbol] The method to call on the Representable::Decorator, the result of which is ultimately returned out of the implementation of this scenario. @return [Symbol] The representation method
example:
class FakeThing < Shoegaze::Mock mock "RealThing" implement :method do scenario :success do representer ThingRepresenter represent_method :as_json end end end
# File lib/shoegaze/scenario.rb, line 77 def represent_method(representation_method = nil) if representation_method @_representation_method = representation_method end @_representation_method end
Specifies the (optional) representer to use when returning the evaluated data source. If no representer is specified, the data source itself is returned untouched. You can specify either a stand-alone Representable::Decorator, or provide an inline one implementation via a block. This is a getter and a setter. Call it with no arg to get the current representer.
@param representer_class [Representable::Decorator] (optional) A decorator class that will be used to wrap the result of the data source. @param representer_block [Block] (optional) An inline Representable::Decorator implementation expressed as a block. @return [Representable::Decorator] The created or referenced representer.
example:
class FakeThing < Shoegaze::Mock mock "RealThing" implement :method do scenario :success do representer ThingRepresenter # or... representer do property :id property :name end end end end
# File lib/shoegaze/scenario.rb, line 41 def representer(representer_class = nil, &block) if representer_class @_representer = representer_class end if block_given? @_representer = Class.new(Representable::Decorator).class_eval do self.class_eval(&block) self end end @_representer end
This just returns the datasource block.
@return [Block] The current data source block
# File lib/shoegaze/scenario.rb, line 96 def to_proc @_datasource end