Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json_api_client_mock

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json_api_client_mock

  • 0.3.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

JsonApiClientMock Build Status

This gem allows you to easily test json_api_client gem.

Usage

In your Gemfile:

group :test do
  gem 'json_api_client_mock', '~> 0'
end

To set a global mock for MyResource:

MyResource.set_test_results([
  {foo: 'bar', qwer: 'asdf'},
  {foo: 'wat', qwer: 'zxcv'}
])

MyResource.all
=> [<#MyResource foo:'bar', qwer:'asdf'>, <#MyResource foo:'wat', qwer:'zxcv'>]

MyResource.where(condition1: 'value', condition2: 'value2').all
=> [<#MyResource foo:'bar', qwer:'asdf'>, <#MyResource foo:'wat', qwer:'zxcv'>]

To set a targeted mock for MyResource:

MyResource.set_test_results([
  {foo: 'asdf', 'qwer': 'bar'}
], {
  condition1: 'value1',
  condition2: 'value2',
})

MyResource.where(condition1: 'value1', condition2: 'value2').all
=> [<#MyResource foo:'asdf', qwer:'bar'>]

To set the response meta for MyResource:

MyResource.set_test_results([
  {foo: 'asdf', 'qwer': 'bar'}
], {
  condition1: 'value1',
  condition2: 'value2',
}, {
  meta_attribute: 1000
})

response = MyResource.where(condition1: 'value1', condition2: 'value2').all
=> [<#MyResource foo:'asdf', qwer:'bar'>]
puts response.meta
=> { :meta_attribute => 1000 }

condition order should not matter

MyResource.where(condition2: 'value2', condition1: 'value1').all => [<#MyResource foo:'asdf', qwer:'bar'>]


### Mock Priority

If you set multiple mocks that match the same query, the last matching result set should be returned. If no targetted match is found, we will return the untargeted result set you've specified (if it exists). If no mock is found, we will raise a `JsonApiClientMock::MissingMock` exception.

## Contributing

Please fork and send me a pull request.

## License

This project rocks and uses MIT-LICENSE.

[json_api_client]: http://github.com/chingor13/json_api_client

FAQs

Package last updated on 20 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc