Module: AssertResponse::Methods

Included in:
Rack::Test::Methods
Defined in:
lib/assert-response.rb

Overview

these methods are included in Rack::Test::Methods to be used in a Test Class

call assert_response with a code block to use the DSL (methods from AssertResponse) or use a method like assert_response_xxx where xxx is the name of the method from AssertResponse you want to call

Examples:

with Test::Unit, simple

require 'rack/test'
require 'assert-response'

class TestMe < Test::Unit::Testcase
  include Rack::Test::Methods
  def app
    MyApp
  end

  def test_something
    get '/works'
    assert_response_html "should really work"
  end
end

without including Rack::Test::Methods

require 'rack/test'
require 'assert-response'

class AppWrapper
  include Rack::Test::Methods
  def app
    MyApp
  end
end

class TestMe < Test::Unit::Testcase
  include AssertResponse::Methods

  def test_something
    server = AppWrapper.new
    server.get '/works'
    assert_response server.last_response do
      html "should really work"
    end
  end
end

with Minitest, simple

require 'rack/test'
require 'assert-response'
include Rack::Test::Methods

# write your tests here
it "should work" do
  get '/works'
  assert_response_html "should really work"
end

without including Rack::Test::Methods

require 'rack/test'
require 'assert-response'

class AppWrapper
  include Rack::Test::Methods
  def app
    MyApp
  end
end

include AssertResponse::Methods

describe "my app" do
  before do
    @app = AppWrapper.new
  end

  it "should work" do
    @app.get '/works'
    assert_response(@app.last_response) do
      html "should really work"
    end
  end
end

See Also:

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &code) ⇒ Object

route assert_response_ methods to AssertResponse

See Also:



400
401
402
403
404
405
406
# File 'lib/assert-response.rb', line 400

def method_missing(meth, *args, &code)
  if meth.to_s =~ /^assert_response_(.+)$/
    AssertResponse.new(self, last_response, last_request).send($1.to_sym, *args, &code)
  else
    super
  end
end

Instance Method Details

#assert_response(response = last_response, request = last_request, &code) ⇒ Object

creates an AssertResponse Object and instance_exec the code (DSL) in it

See Also:



410
411
412
413
# File 'lib/assert-response.rb', line 410

def assert_response(response=last_response, request=last_request, &code) 
  file, line, rest = caller[0].split(':', 3)
  AssertResponse.new(self, response, request).instance_exec(file, line.to_i, &code)
end