Sha256: 7fae1df386539b2ad6203e9550429cf6b4b822c9fc74adf808be2249d0bd52da

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

module Crystal
  module RSpecHelper
    attr_accessor :response, :workspace
  end
end

Crystal::Response.class_eval do
  inject :workspace => :workspace
  attr_accessor :rson
end

Spec::Example::ExampleGroup.class_eval do
  def self.with_http
    Spec::Example::ExampleGroup.include Crystal::RSpecHelper
    
    before :each do
      self.response = nil
    end        
    
    before :all do
      crystal.before :cycle do  
        if defined?(Crystal::Processors) and defined?(Crystal::Processors::PrepareParams)
          crystal.conveyors.web do |web|
            web.definitions.delete_if{|pdef, args| pdef == Crystal::Processors::PrepareParams}
            web.build!
          end
        end
      end
    end
  end
  
  def wcall *args, &block
    # parsing arguments
    params = args.extract_options!
    
    workspace_variables = {}            
    if args.size == 1 and args.first.is_a?(String)
      workspace_variables[:path] = args.first
    elsif args.first.is_a?(Class) and args.size >= 2       
      workspace_variables[:path] = '/'
      workspace_variables[:class] = args[0]
      workspace_variables[:method_name] = args[1].to_s    
      if args.size > 2
        workspace_variables.merge! args[2].symbolize_keys
      end
    else
      raise "Invalid input!"
    end
    
    # calling
    self.response = Crystal::Response.new
    workspace_variables.merge!({
      :request => Crystal::Request.new(workspace_variables[:env] || {}),
      :params => Crystal::Params.new(params),
      :response => response,
    })
    
    workspace = crystal.conveyors.web.call(workspace_variables, &block)    
    
    workspace.response.must_be.defined
    self.response = workspace.response
    self.response.rson = workspace.remote_result
    self.workspace = workspace
  
    response
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crystal_ext-0.0.11 lib/crystal/spec/http.rb