Sha256: 0d0a8449a4b30d2255ba727ed31d8c869761cfd48108d87166e0f51d3dbfd35d

Contents?: true

Size: 1.77 KB

Versions: 2

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

RSpec::Core::ExampleGroup.class_eval do
  def self.with_http
    RSpec::Core::ExampleGroup.include Crystal::RSpecHelper
    
    before :each do
      self.response = nil
    end        
    
    before :all do
      crystal.before_scope :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

2 entries across 2 versions & 1 rubygems

Version Path
crystal-0.0.13 lib/crystal/spec/http.rb
crystal-0.0.12 lib/crystal/spec/http.rb