Module: JSpecRunner::XhrProxy

Extended by:
XhrProxy
Included in:
XhrProxy
Defined in:
lib/jspec_runner.rb

Overview

This module allows routing ajax requests to rails controllers

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject

Test object context (i.e. within test methods)



15
16
17
# File 'lib/jspec_runner.rb', line 15

def context
  @context
end

Instance Method Details

#log(s) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/jspec_runner.rb', line 30

def log(s)
  # TODO: can't seem to figure out where the logger is...
  # context.instance_eval do
  #   RAILS_DEFAULT_LOGGER.info s
  #   logger.info s
  # end
  puts s
  ""
end

#request(info, data = "") ⇒ Object

Surrogate ajax request



18
19
20
21
22
23
# File 'lib/jspec_runner.rb', line 18

def request(info, data="")
  context.instance_eval do
    xhr(info["method"].downcase, info["url"], data)
    @response.body.to_s
  end
end

#specRequest(path) ⇒ Object

Special for spec requests



26
27
28
# File 'lib/jspec_runner.rb', line 26

def specRequest(path)
  File.open(Rails.root.join('spec', path)).read
end