All Projects → MaicolBen → twilio_mock

MaicolBen / twilio_mock

Licence: MIT License
Mock Twilio gem for Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to twilio mock

Mimic
Seamless client side mocking
Stars: ✭ 380 (+1361.54%)
Mutual labels:  test, mocking
Aioresponses
Aioresponses is a helper for mock/fake web requests in python aiohttp package.
Stars: ✭ 278 (+969.23%)
Mutual labels:  test, mocking
nala
🦁 Nala - A delightful test framework for C projects.
Stars: ✭ 58 (+123.08%)
Mutual labels:  test, mocking
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (+280.77%)
Mutual labels:  test, mocking
Mocktopus
Mocking framework for Rust
Stars: ✭ 179 (+588.46%)
Mutual labels:  test, mocking
Prig
Prig is a lightweight framework for test indirections in .NET Framework.
Stars: ✭ 106 (+307.69%)
Mutual labels:  test, mocking
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+319.23%)
Mutual labels:  test, mocking
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+6230.77%)
Mutual labels:  test, mocking
mockingbird
🐦 Decorator Powered TypeScript Library for Creating Mocks
Stars: ✭ 70 (+169.23%)
Mutual labels:  test, mocking
jaymock-cli
Mock an API and generate fake JSON test data, right from the terminal.
Stars: ✭ 13 (-50%)
Mutual labels:  test, mocking
golang-example
⚡ Golang Clean Boilerplate
Stars: ✭ 15 (-42.31%)
Mutual labels:  test
carina-demo
Carina demo project.
Stars: ✭ 40 (+53.85%)
Mutual labels:  test
expectest
Crate provides matchers and matcher functions for unit testing.
Stars: ✭ 25 (-3.85%)
Mutual labels:  test
cargo-testify
Watches changes in a rust project, runs test and shows friendly notification
Stars: ✭ 76 (+192.31%)
Mutual labels:  test
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-23.08%)
Mutual labels:  test
rasa-train-test-gha
A GitHub action to run easily rasa train and rasa test in the CIs.
Stars: ✭ 26 (+0%)
Mutual labels:  test
ineeda
Mocking library for TypeScript and JavaScript using Proxies!
Stars: ✭ 53 (+103.85%)
Mutual labels:  mocking
Dracker
An iOS and React App to track debt and send/receive payments.
Stars: ✭ 22 (-15.38%)
Mutual labels:  twilio
mocxx
A versatile C++ function mocking framework.
Stars: ✭ 103 (+296.15%)
Mutual labels:  mocking
dog-bathroom-button
A button for a dog to press to text their owner they need to go out
Stars: ✭ 16 (-38.46%)
Mutual labels:  twilio

Gem Version Build Status Code Climate Test Coverage Downloads Issues

twilio_mock

It is a mocking library for the twilio-ruby gem. It covers buy numbers, sms and lookup for numbers. It needs Ruby >= 2.2. Which version of twilio-ruby do you have?

  • 3: use 0.2.0 version
  • 4: use 0.3.0 version
  • 5: use 0.4.0 version

Installation

To install using bundler:

gem 'twilio_mock'

To manually install twilio_mock:

gem install twilio_mock

Includes

  • Send SMS/MMS (account.messages.create)
  • Get a new number (account.available_phone_numbers)
  • Buy a number (account.incoming_phone_numbers.create)
  • Lookup Phone Number information (client.lookups.v1.phone_numbers)

Setup

Add require 'twilio_mock' to the spec_helper.rb, and if you want to inspect the messages sent:

config.after(:each) do
  TwilioMock::Mocker.new.clean
end

Manual mock

By default the mocking is enabled, but you can disable it and call the mocker with your own parameters:

Sending messages

TwilioMock::Testing.disable!
mocker = TwilioMock::Mocker.new
attrs = {
  from: 'from_number',
  to: 'to_number',
  body: 'text message',
}
mocker.create_message(attrs)
account.messages.create(attrs)

mocker.messages.last # here is your message sent

TwilioMock::Testing.enable!

Buying numbers

TwilioMock::Testing.disable! do
  mocker = TwilioMock::Mocker.new
  mocker.available_number(my_number)
  number = account.available_phone_numbers.get('US').local.list.first.phone_number
  my_number == number # true
  attrs = {
    phone_number: my_number,
    sms_url: 'my sms callback',
    sms_method: 'POST'
  }
  mocker.buy_number(attrs)

  account.incoming_phone_numbers.create(
    phone_number: phone_number,
    sms_url: sms_url,
    sms_method: 'POST'
  )
end
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].