在TestUnit上,您可以使用-n选项在文件中启动一个测试
例如
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "the truth" do
assert true
end
test "the truth 2" do
assert true
end
end
Run Code Online (Sandbox Code Playgroud)
你只能执行测试真相
ruby -Itest test/unit/user_test.rb -n test_the_truth
Run Code Online (Sandbox Code Playgroud)
输出
1 tests, 1 assertions, 0 failures, 0 errors, 0 skip
Run Code Online (Sandbox Code Playgroud)
怎么能用rspec?
该命令似乎不起作用
rspec spec/models/user_spec.rb -e "User the truth"
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种从分叉存储库中恢复拉取请求的方法。是否可以?
Manualy卷曲工作完美:
curl https://www.googleapis.com/urlshortener/v1/url \
-H 'Content-Type: application/json' \
-d '{"longUrl": "http://www.rubyinside.com/"}'
Run Code Online (Sandbox Code Playgroud)
我试图在Net :: Http中做这个时:
require "net/https"
require "uri"
uri = URI.parse("https://www.googleapis.com/urlshortener/v1/url")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path)
request["Content-Type"] = "application/json"
request.set_form_data({"longUrl" => "http://www.rubyinside.com/"})
response = http.request(request)
puts response.body
Run Code Online (Sandbox Code Playgroud)
但是响应失败了:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "This API does not support parsing form-encoded input."
}
],
"code": 400,
"message": "This API does not support parsing form-encoded input." …
Run Code Online (Sandbox Code Playgroud) 我误解了Array的行为
当我创建这个矩阵
matrix, cell = [], []; 5.times { cell << [] } # columns
3.times { matrix << cell } # lines
matrix
sample_data = (0..5).to_a
matrix[1][2] = sample_data.clone
matrix.each { |line| puts "line : #{line}" }
Run Code Online (Sandbox Code Playgroud)
我有这个结果
line : [[], [], [0, 1, 2, 3, 4, 5], [], []]
line : [[], [], [0, 1, 2, 3, 4, 5], [], []]
line : [[], [], [0, 1, 2, 3, 4, 5], [], []]
Run Code Online (Sandbox Code Playgroud)
而是预期的结果
line : [[], [], …
Run Code Online (Sandbox Code Playgroud)