Class: Hurley::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/hurley/test.rb,
lib/hurley/test/integration.rb

Defined Under Namespace

Modules: Integration Classes: Handler

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Test

Returns a new instance of Test.

Yields:

  • (_self)

Yield Parameters:

  • _self (Hurley::Test)

    the object that the method was called on



3
4
5
6
# File 'lib/hurley/test.rb', line 3

def initialize
  @handlers = []
  yield self if block_given?
end

Instance Method Details

#all_run?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/hurley/test.rb', line 48

def all_run?
  @handlers.all?(&:run?)
end

#call(request) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/hurley/test.rb', line 40

def call(request)
  handler = @handlers.detect { |h| h.matches?(request) } ||
    Handler.method(:not_found)
  # Create a new url with fresh state from the url string
  request.url = Url.parse(request.url.to_s)
  handler.call(request)
end

#delete(url) ⇒ Object



28
29
30
# File 'lib/hurley/test.rb', line 28

def delete(url)
  handle(:delete, url, &Proc.new)
end

#get(url) ⇒ Object



12
13
14
# File 'lib/hurley/test.rb', line 12

def get(url)
  handle(:get, url, &Proc.new)
end

#handle(verb, url) ⇒ Object



36
37
38
# File 'lib/hurley/test.rb', line 36

def handle(verb, url)
  @handlers << Handler.new(Request.new(verb, Url.parse(url)), Proc.new)
end

#head(url) ⇒ Object



8
9
10
# File 'lib/hurley/test.rb', line 8

def head(url)
  handle(:head, url, &Proc.new)
end

#options(url) ⇒ Object



32
33
34
# File 'lib/hurley/test.rb', line 32

def options(url)
  handle(:options, url, &Proc.new)
end

#patch(url) ⇒ Object



24
25
26
# File 'lib/hurley/test.rb', line 24

def patch(url)
  handle(:patch, url, &Proc.new)
end

#post(url) ⇒ Object



20
21
22
# File 'lib/hurley/test.rb', line 20

def post(url)
  handle(:post, url, &Proc.new)
end

#put(url) ⇒ Object



16
17
18
# File 'lib/hurley/test.rb', line 16

def put(url)
  handle(:put, url, &Proc.new)
end