mercredi 1 février 2017

Using Sinatra with Rspec for test JSON

I am new to Rspec and Sinatra and wanted to ask how one would go about testing the following. I think I configured Sinatra for work with Rspec all correctly. I have a JSON being consumed and the project is running 100%. However, the tests are not working. A test example:

it "Has response HTTP 200" do
      get "/"
      puts last_response.inspect
      expect(last_response).to have_http_status(:success)
    end

On return from .inspect, this resulted:

<Rack::MockResponse:0x007fbc948c2f50 @original_headers={"Content-Type"=>"text/html;charset=utf-8", "X-Cascade"=>"pass", "Content-Length"=>"459", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "X-Frame-Options"=>"SAMEORIGIN"}, @errors="", @body_string=nil, @status=404, @header={"Content-Type"=>"text/html;charset=utf-8", "X-Cascade"=>"pass", "Content-Length"=>"459", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "X-Frame-Options"=>"SAMEORIGIN"}, @chunked=false, @writer=#<Proc:0x007fbc948c28c0@/Users/eltonsantos/.rvm/gems/ruby-2.3.3@sinatra/gems/rack-1.6.5/lib/rack/response.rb:30 (lambda)>, @block=nil, @length=459, @body=["<!DOCTYPE html>\n<html>\n<head>\n  <style type=\"text/css\">\n  body { text-align:center;font-family:helvetica,arial;font-size:22px;\n    color:#888;margin:20px}\n  #c {margin:0 auto;width:500px;text-align:left}\n  </style>\n</head>\n<body>\n  <h2>Sinatra doesn&rsquo;t know this ditty.</h2>\n  <img src='http://ift.tt/2ksQ18M'>\n  <div id=\"c\">\n    Try this:\n    <pre>get &#x27;&#x2F;&#x27; do\n  &quot;Hello World&quot;\nend\n</pre>\n  </div>\n</body>\n</html>\n"]>

Atention for "Sinatra doesnt know this ditty". Configuration Sinatra for use with Rspec and json is correct??? Serious, I am trying but I do not know what to do anymore :( No one test with Rspec work :( This is my repository, clone, fork, commit, anything, but help me, please.

http://ift.tt/2jFBbHz

When I run ruby app.rb it work, but rspec doesnt work.

Thank you!

Aucun commentaire:

Enregistrer un commentaire