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:
我是Rspec和Sinatra的新手,想问一下如何测试以下内容。我想我已经将Sinatra配置为正确使用Rspec。我正在使用JSON,项目正在运行100%。但是,测试不起作用。一个测试例子:
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:
从.inspect返回时,结果如下:
<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’t know this ditty.</h2>\n <img src='http://example.org/__sinatra__/404.png'>\n <div id=\"c\">\n Try this:\n <pre>get '/' do\n "Hello World"\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.
对“Sinatra不知道这个小曲”的关注。用于Rspec和json的配置Sinatra是正确的???严重,我正在尝试,但我不知道该怎么办:(没有人用Rspec测试工作:(这是我的存储库,克隆,分叉,提交,任何东西,但请帮助我。
https://github.com/eltonsantos/locaweb-twitter
https://github.com/eltonsantos/locaweb-twitter
When I run ruby app.rb it work, but rspec doesnt work.
当我运行ruby app.rb它工作,但rspec不起作用。
Thank you!
谢谢!
1 个解决方案
#1
0
This blog post by Taryn may be helpful. She describes a Sinatra controller test sequence with RSpec to be along these lines:
Taryn的这篇博文可能会有所帮助。她用RSpec描述了一个Sinatra控制器测试序列:
describe "GET '/'" do
it "loads homepage" do
get '/'
expect(last_response).to be_ok
end
The post has a number of details, including an explanation of the mock return value.
帖子有很多细节,包括模拟返回值的解释。
#1
0
This blog post by Taryn may be helpful. She describes a Sinatra controller test sequence with RSpec to be along these lines:
Taryn的这篇博文可能会有所帮助。她用RSpec描述了一个Sinatra控制器测试序列:
describe "GET '/'" do
it "loads homepage" do
get '/'
expect(last_response).to be_ok
end
The post has a number of details, including an explanation of the mock return value.
帖子有很多细节,包括模拟返回值的解释。