Project

smsmock

0.0
No commit activity in last 3 years
No release in over 3 years
Sms mocker for twilio-ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

SmsMock

Adds twilio-ruby RSpec tests for testing SMS interactions.

##Setup Add the smsmock gem to your Gemfile:

group :test do
  gem 'smsmock'
end

RSpec

In your spec_helper.rb file require the smsmocker.

require 'smsmock'

Example

require 'spec_helper'

describe SmsMock do

  before :each do
    @client = Twilio::REST::Client.new('','')
  end

  it 'add a message to SmsMock::Client' do
    @client.messages.create(to: '123981', body: 'abc123', from: '1291')
    expect(SmsMock::Client).to have_sent_messages
    expect(SmsMock::Client.messages.last).to have_body 'abc123'
    expect(SmsMock::Client.messages.last).to be_sent_from '1291'
    expect(SmsMock::Client.messages.last).to be_sent_to '123981'
  end
end

The following matchers can be used:

  # for SmsMock::Client
  expect(SmsMock::Client).to have_sent_messages
  expect(SmsMock::Client).to have_sent_messages 2
  expect(SmsMock::Client).to have_sent_message_to '123456'
  expect(SmsMock::Client).to have_sent_message_from '123456'
  expect(SmsMock::Client).to have_sent_message_with_body 'abc123'

  # with chaining:
  expect(SmsMock::Client).to have_sent_message_to('123456').and from('654321').and with_body('abc123')

  # for individual messages
  expect(SmsMock::Client.messages.last).to have_body 'abc123'
  expect(SmsMock::Client.messages.last).to be_sent_from '1291'
  expect(SmsMock::Client.messages.last).to be_sent_to '123981'

  # with chaining:
  expect(SmsMock::Client.messages.last).to be_sent_to('123456').and from('654321').and with_body('abc123')