Module: Nyara::Test

Defined in:
lib/nyara/test.rb,
ext/test_response.c

Overview

Test helper

Defined Under Namespace

Classes: Env, Response

Instance Method Summary collapse

Instance Method Details


157
158
159
# File 'lib/nyara/test.rb', line 157

def cookie
  env.cookie
end

#delete(path, header = {}, body_string_or_hash = "") ⇒ Object


129
130
131
# File 'lib/nyara/test.rb', line 129

def delete path, header={}, body_string_or_hash=""
  env.http 'DELETE', path, header, body_string_or_hash
end

#envObject


96
97
98
# File 'lib/nyara/test.rb', line 96

def env
  @_env ||= Env.new
end

#follow_redirectObject


177
178
179
180
181
182
# File 'lib/nyara/test.rb', line 177

def follow_redirect
  # todo validate scheme and host
  u = URI.parse(redirect_location)
  path = [u.path, u.query].compact.join '?'
  get path
end

#get(path, header = {}, body_string_or_hash = "") ⇒ Object

Call-seq

get '/', headers

112
113
114
# File 'lib/nyara/test.rb', line 112

def get path, header={}, body_string_or_hash=""
  env.http 'GET', path, header, body_string_or_hash
end

#http(*xs) ⇒ Object

Call-seq

http :trace, '/'

104
105
106
# File 'lib/nyara/test.rb', line 104

def http *xs
  env.http *xs
end

#options(path, header = {}, body_string_or_hash = "") ⇒ Object


137
138
139
# File 'lib/nyara/test.rb', line 137

def options path, header={}, body_string_or_hash=""
  env.http 'OPTIONS', path, header, body_string_or_hash
end

#patch(path, header = {}, body_string_or_hash = "") ⇒ Object


133
134
135
# File 'lib/nyara/test.rb', line 133

def patch path, header={}, body_string_or_hash=""
  env.http 'PATCH', path, header, body_string_or_hash
end

#path_to(id, *args) ⇒ Object


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/nyara/test.rb', line 141

def path_to id, *args
  # similar to Controller#path_to, but without local query
  if args.last.is_a?(Hash)
    opts = args.pop
  end

  r = Route.global_path_template(id) % args

  if opts
    format = opts.delete :format
    r << ".#{format}" if format
    r << '?' << opts.to_param unless query.empty?
  end
  r
end

#post(path, header = {}, body_string_or_hash = "") ⇒ Object

Call-seq

post '/', {}, page: 3
post '/', { 'content-type' => 'application/json' }, '{"page":3}'

121
122
123
# File 'lib/nyara/test.rb', line 121

def post path, header={}, body_string_or_hash=""
  env.http 'POST', path, header, body_string_or_hash
end

#put(path, header = {}, body_string_or_hash = "") ⇒ Object


125
126
127
# File 'lib/nyara/test.rb', line 125

def put path, header={}, body_string_or_hash=""
  env.http 'PUT', path, header, body_string_or_hash
end

#redirect_locationObject


173
174
175
# File 'lib/nyara/test.rb', line 173

def redirect_location
  env.response.redirect_location
end

#requestObject


165
166
167
# File 'lib/nyara/test.rb', line 165

def request
  env.request
end

#responseObject


169
170
171
# File 'lib/nyara/test.rb', line 169

def response
  env.response
end

#sessionObject


161
162
163
# File 'lib/nyara/test.rb', line 161

def session
  env.session
end