Build Status

RestforceMock

Mock out Restforce in tests

Installation

Add this line to your application's Gemfile:

group :test do

  gem 'restforce_mock'

end

And then execute:

$ bundle

Or install it yourself as:

$ gem install restforce_mock

Usage

To mock out Restforce global in your test environment

Restforce::Client = RestforceMock::Client

This will direct all calls to Restforce to RestforceMock. Test as usual.

Configuration

RestforceMock.configure do |config|
  config.schema_file = "spec/fixtures/schema.yml"
  config.error_on_required = true  # raise error if required field is not set
  config.required_exclusions = [:LastModifiedById ...] # fields that should not be considered required
end

Mimicking Salesforce data

To mimic Salesforce database, add some data to the RestfoceMock sandbox

  RestforceMock::Sandbox.add_object("Contact", "HGUKK674J79HjsH", { Name__c: "John" })

To access the object in the RestforceMock object

  RestforceMock::Sandbox.get_object("Contact", "HGUKK674J79HjsH")

RestforceMock sandbox is shared across all your tests (same way as real Salesforce instace would be), hence, after completion of tests make sure to clean up if necessary

  RestforceMock::Sandbox.reset!

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec 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]/restforce_mock. 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.

Dedication

This gem is dedicated to the memory of Adrian P.

License

The gem is available as open source under the terms of the MIT License.