pipekit-webmock
This is a WebMock extension to stub requests to Pipedrive with the pipekit gem.
It provides a stub_pipedrive_request
method and readable error messages for unregistered requests.
Installation
Add this line to your application's Gemfile:
gem 'pipekit-webmock'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pipekit-webmock
Usage
# spec/spec_helper.rb
require "pipekit/webmock"
To use pipekit
you will need a dummy Pipedrive config for your tests. Create a file with Pipedrive field mapping in spec/support/config.yml
. Then add the following to your spec_helper
:
# Dummy config data
Pipekit.config_file_path = File.join(File.dirname(__FILE__), "support", "config.yml")
To stub requests to Pipedrive use stub_pipedrive_request
method where you would normally use WebMock
's stub_request
with the following params:
-
resource
- what "entity" is request made to. Possible values are::person
:deal
:note
:activity
:personField
-
action
:-
:get
- Stubs aGET
request to get resource by id or a query string. -
:create
- Stubs aPOST
request to create a resource. -
:update
- Stubs aPUT
request to update the resource.params
hash should includeid
. -
:search
- Stubs aGET
request to thesearchResults
endpoint. -
:find_by_person_id
- Only for thedeal
resource. Stubs aGET
request topersons/:id/deals
on Pipedrive. -
:find_by_email
- Only for theperson
resource. Stubs aGET
request topersons
withsearch_by_email=1
query param on Pipedrive. -
:find_by_name
- Only for theperson
resource. Stubs aGET
request topersons
on Pipedrive.
-
-
params
- a hash of parameters. Could be either a query string (forGET
requests) or a body (forPOST
andPUT
) requests. Forupdate
action must include:id
(as a symbol). Custom Pipedrive fields don't have to be converted to their Pipedrive ids. -
response
- what stubbed request should return. Note that mostGET
requests return an array, even if there's only one match.
Examples
stub_pipedrive_request(
resource: :person,
action: :create,
params: {
"email" => "octocat@github.com",
"name" => "Octocat",
"middle_name" => "Purr" # custom Pipedrive field
},
response: {id: 123}
)
stub_pipedrive_request(
resource: :deal,
action: :update,
params: {
id: 123,
stage: "1st Contact"
},
response: {id: 123}
)
stub_pipedrive_request(
resource: :person,
action: :find_by_email,
params: {
email: "octocat@gmail.com"
}
response: [{id: 123}] # notice the array
)
stub_pipedrive_request(
resource: :deal,
action: :find_by_person_id,
params: {
person_id: 123
},
response: [{id: 345}]
)
stub_pipedrive_request(
resource: :person,
action: :search,
params: {
"Middle name" => "Purr" # custom Pipedrive field
},
response: [{id: 123}]
)
stub_pipedrive_request(
resource: :activity,
action: :create,
params: {
:deal_id=>123,
:person_id=>321,
:subject=>"Interview Completed",
:due_date=>"2017-11-14",
:due_time=>"14:30",
:duration=>"00:45",
:done=>1,
:type=>"pairing_session",
:note=>"Super cool cat!\n - Interviewed by: Octocat"
},
response: {id: 123
)
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pipekit-webmock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.