Module: TestHelpers::Rack

Included in:
ActiveSupport::TestCase
Defined in:
lib/isolation/abstract_unit.rb

Instance Method Summary collapse

Instance Method Details

#app(env = "production") ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/isolation/abstract_unit.rb', line 47

def app(env = "production")
  old_env = ENV["RAILS_ENV"]
  @app ||= begin
    ENV["RAILS_ENV"] = env
    require "#{app_path}/config/environment"
    Rails.application
  end
ensure
  ENV["RAILS_ENV"] = old_env
end

#assert_body(expected, resp) ⇒ Object



86
87
88
# File 'lib/isolation/abstract_unit.rb', line 86

def assert_body(expected, resp)
  assert_equal expected, extract_body(resp)
end

#assert_header(key, value, resp) ⇒ Object



82
83
84
# File 'lib/isolation/abstract_unit.rb', line 82

def assert_header(key, value, resp)
  assert_equal value, resp[1][key.to_s]
end

#assert_missing(resp) ⇒ Object



78
79
80
# File 'lib/isolation/abstract_unit.rb', line 78

def assert_missing(resp)
  assert_equal 404, resp[0]
end

#assert_success(resp) ⇒ Object



74
75
76
# File 'lib/isolation/abstract_unit.rb', line 74

def assert_success(resp)
  assert_equal 202, resp[0]
end

#assert_welcome(resp) ⇒ Object



68
69
70
71
72
# File 'lib/isolation/abstract_unit.rb', line 68

def assert_welcome(resp)
  assert_equal 200, resp[0]
  assert resp[1]["Content-Type"] = "text/html"
  assert extract_body(resp).match(/Welcome aboard/)
end

#extract_body(response) ⇒ Object



58
59
60
61
62
# File 'lib/isolation/abstract_unit.rb', line 58

def extract_body(response)
  "".tap do |body|
    response[2].each {|chunk| body << chunk }
  end
end

#get(path) ⇒ Object



64
65
66
# File 'lib/isolation/abstract_unit.rb', line 64

def get(path)
  @app.call(::Rack::MockRequest.env_for(path))
end