小编Joe*_*MAR的帖子

只测试一个或用Rspec描述

在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)

rspec rspec2 ruby-on-rails-3

4
推荐指数
1
解决办法
2260
查看次数

Fork github 存储库及其拉取请求

我正在寻找一种从分叉存储库中恢复拉取请求的方法。是否可以?

git fork github pull-request

2
推荐指数
1
解决办法
525
查看次数

如何设置Header with Net :: Http for Goo.gl Shorten服务?

就像在API Goo.gl中描述一样

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)

ruby goo.gl net-http

1
推荐指数
1
解决办法
2744
查看次数

Ruby数组奇怪的行为

我误解了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)

ruby arrays

0
推荐指数
1
解决办法
83
查看次数

标签 统计

ruby ×2

arrays ×1

fork ×1

git ×1

github ×1

goo.gl ×1

net-http ×1

pull-request ×1

rspec ×1

rspec2 ×1

ruby-on-rails-3 ×1