- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个看起来像这样的模型:
class Gist
def self.create(options)
post_response = Faraday.post do |request|
request.url 'https://api.github.com/gists'
request.headers['Authorization'] = "Basic " + Base64.encode64("#{GITHUB_USERNAME}:#{GITHUB_PASSWORD}")
request.body = options.to_json
end
end
end
require 'spec_helper'
describe Gist do
context '.create' do
it 'POSTs a new Gist to the user\'s account' do
Faraday.should_receive(:post)
Gist.create({:public => 'true',
:description => 'a test gist',
'files' => {'test_file.rb' => 'puts "hello world!"'}})
end
end
end
最佳答案
我的 friend @n1kh1l 将我指向 and_yield
Rspec 方法和 this SO post让我这样写我的测试:
require 'spec_helper'
describe Gist do
context '.create' do
it 'POSTs a new Gist to the user\'s account' do
gist = {:public => 'true',
:description => 'a test gist',
:files => {'test_file.rb' => {:content => 'puts "hello world!"'}}}
request = double
request.should_receive(:url).with('https://api.github.com/gists')
headers = double
headers.should_receive(:[]=).with('Authorization', "Basic " + Base64.encode64("#{GITHUB_USERNAME}:#{GITHUB_PASSWORD}"))
request.should_receive(:headers).and_return(headers)
request.should_receive(:body=).with(gist.to_json)
Faraday.should_receive(:post).and_yield(request)
Gist.create(gist)
end
end
end
关于rspec - 用法拉第和 Rspec 打桩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14329429/
我正在尝试使用 Faraday 将路由 A(Sinatra 应用程序)中生成的小有效载荷放入路由 B。所以代码基本上是这样的: post "/routeA" do foo.save foo_i
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试为我的 Rails 应用程序的用户设置 OAuth 到 GetPocket ( http://getpocket.com )。 在 Pocket Authentication 文档 ( ht
我想使用 Faraday 发送一个带有 JSON 正文(用于搜索)的获取请求,但我收到了上述错误。我认为 Proc 中的 self 把事情搞砸了,但这与它无关。我正在关注 [faraday githu
我想向 API 发送 POST 请求。这是我的代码: conn = Faraday.new(url: BASE) do |faraday| faraday.response :logger f
作为我正在尝试编写的 Recipe (新手)的一部分,我使用 berks 安装来自其他 Recipe 的依赖项,最终当我运行时 berks install ,我遇到证书验证错误。任何人都可以帮助我知道
我将一个旧脚本迁移到一个新的 CentOS box 并在运行脚本时收到以下消息: Faraday: you may want to install system_timer for reliable
我正在尝试将一些代码从 HTTPParty 转换为 Faraday。以前我用的是: HTTParty.post("http://localhost/widgets.json", body: { nam
我是一名优秀的程序员,十分优秀!