e2e testing made eas(y/ier)
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

69 行
1.5KB

  1. require 'fileutils'
  2. class Server < Routes
  3. enable :logging
  4. disable :show_exceptions
  5. get '/sinatra' do
  6. return 'sinatra running'
  7. end
  8. get '/proxied' do
  9. return haml :proxied
  10. end
  11. get '/pseudo' do
  12. return Client.new.hit 'get',
  13. 'http://localhost:4567/proxied',
  14. { 'Accept' => 'text/html' }
  15. end
  16. get '/api/json/masked' do
  17. puts request.env['HTTP_AUTHORIZATION']
  18. return '{"result":"masked"}'
  19. end
  20. get '/page/masked' do
  21. Fx::pipe({ 'Accept' => 'application/json',
  22. 'Authorization' => "Bearer #{request.cookies['token']}" },
  23. -> (t) {
  24. Client.new.hit 'get',
  25. 'http://localhost:4567/api/json/masked',
  26. t
  27. },
  28. -> (t) {
  29. haml :page,
  30. {
  31. locals: {
  32. data: t
  33. }
  34. }
  35. })
  36. end
  37. get '/upload' do
  38. haml :upload
  39. end
  40. post '/upload' do
  41. puts params
  42. FileUtils.copy(params[:data][:tempfile],
  43. "#{Dir.pwd}/upload.tmp")
  44. return 'OK'
  45. end
  46. get '/uploads' do
  47. Fx::pipe(Dir.pwd.concat('/upload.*'),
  48. -> (t) { Dir.glob(t) },
  49. -> (t) {
  50. t.each { |f| File.delete f }
  51. haml :uploads, {
  52. locals: {
  53. data: t
  54. }
  55. }
  56. })
  57. end
  58. end