0.0
No commit activity in last 3 years
No release in over 3 years
Registers a `stub_pipedrive_request` method and makes unregistered request error messages more readable
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
>= 0
~> 10.0
~> 3.0

Runtime

~> 2.1.1
>= 0
~> 2.1
 Project Readme

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 a GET request to get resource by id or a query string.
    • :create - Stubs a POST request to create a resource.
    • :update - Stubs a PUT request to update the resource. params hash should include id.
    • :search - Stubs a GET request to the searchResults endpoint.
    • :find_by_person_id - Only for the deal resource. Stubs a GET request to persons/:id/deals on Pipedrive.
    • :find_by_email - Only for the person resource. Stubs a GET request to persons with search_by_email=1 query param on Pipedrive.
    • :find_by_name - Only for the person resource. Stubs a GET request to persons on Pipedrive.
  • params - a hash of parameters. Could be either a query string (for GET requests) or a body (for POST and PUT) requests. For update 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 most GET 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.