I have a model that looks like this:
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
and a test that looks like this:
require 'spec_helper' describe Gist do context '.create' do it 'POSTs a new Gist to the user\ account' do Faraday.should_receive(:post) Gist.create({:public => 'true', :description => 'a test gist', 'files' => {'test_file.rb' => 'puts "hello world!"'}}) end end end
This test does not really satisfy me, because all I am testing is that I am doing POST with Faraday, but I cannot check the URL, headers or body, as they went through the block. I tried using the Faraday testing adapter, but I don't see any way to test the URL, headers or body with this.
Is there a better way to write my rspec stub? Or can I use the Faraday testing adapter in some way that I could not understand about?
Thanks!
source share