Class: Rack::ClientSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/client_spec.rb,
lib/rack/client_spec/result.rb,
lib/rack/client_spec/printer.rb,
lib/rack/client_spec/version.rb,
lib/rack/client_spec/test_case.rb,
lib/rack/client_spec/assertions.rb,
lib/rack/client_spec/got_request.rb,
lib/rack/client_spec/request_trace.rb,
lib/rack/client_spec/expect_request.rb

Defined Under Namespace

Modules: Assertions, Printer Classes: Assertion, ExpectRequest, GotRequest, RequestTrace, Result, TestCase

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(app, test_case) ⇒ ClientSpec

Returns a new instance of ClientSpec.



9
10
11
12
13
14
15
16
# File 'lib/rack/client_spec.rb', line 9

def initialize(app, test_case)
  @app = app
  @test_case = test_case
  @tracer = RequestTrace.new(test_case.make_sequences)
  @sequence = []
  Printer.print_initialized
  Printer.print_states @tracer.states
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rack/client_spec.rb', line 18

def call(env)
  response = @app.call(env)
  begin
    do_test(env, response)
  rescue => e
    p e # TODO error inspection
  end
  return response
end

#do_test(env, response) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rack/client_spec.rb', line 28

def do_test(env, response)
  @sequence << GotRequest.new(env, response)
  matched = @tracer.trace(env)
  if matched
    match_function = @tracer.match
    result = @test_case.run_sequence(match_function, @sequence)
    @tracer.reset(match_function)
  end

  Printer.print_states @tracer.states
  if result
    if result.success?
      Printer.print_success match_function
    else
      Printer.print_fail match_function, result
    end
  end
end