smsmock 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 419f21fa634133dc05f4fe8202919e912760fc25
4
+ data.tar.gz: 04d592f01c69cb130a3b91a5efbab5e603ec5ded
5
+ SHA512:
6
+ metadata.gz: a5d3472b79bf90393f4e079f91b05202fcff0cff88c8eb78d15d293bf356c83b50520f757763f6a9ff507940a12bfd7eb207a1a688cac9cac7dcb00d0ceba8e5
7
+ data.tar.gz: 82837214dc7fc1d23c57043f907cc88facd8d6df708061faf8feca5e415dfc70caef6dbac2fba9f68db5fafc1054945753ea953522c820717644868ba83c589c
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # SmsMock
2
+
3
+ Adds [twilio-ruby](https://github.com/twilio/twilio-ruby) RSpec test for testing SMS interactions.
4
+
5
+ ##Setup
6
+ Add the smsmock gem to your Gemfile:
7
+ <pre>
8
+ group :test do
9
+ gem 'smsmock'
10
+ end
11
+ </pre>
12
+
13
+ ## RSpec
14
+ In your spec_helper.rb file require the smsmocker.
15
+
16
+ <pre>
17
+ require 'smsmock'
18
+ </pre>
19
+
20
+ ## Example
21
+ <pre>
22
+ require 'spec_helper'
23
+
24
+ describe SmsMock do
25
+
26
+ before :each do
27
+ @client = Twilio::REST::Client.new('','')
28
+ end
29
+
30
+ it 'add a message to SmsMock::Client' do
31
+ @client.account.sms.messages.create(number: '123981', body: 'abc123', from: '1291')
32
+ expect(SmsMock::Client).to have_messages
33
+ expect(SmsMock::Client.messages.last).to have_body 'abc123'
34
+ expect(SmsMock::Client.messages.last).to be_sent_from '1291'
35
+ expect(SmsMock::Client.messages.last).to be_sent_to '123981'
36
+ end
37
+ end
38
+ </pre>
@@ -0,0 +1,11 @@
1
+ module SmsMock
2
+ class Client
3
+ def Client.messages
4
+ @@messages ||= []
5
+ end
6
+
7
+ def Client.messages=(val)
8
+ @@messages = val
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module SmsMock
2
+ module Helpers
3
+ def add_message(message)
4
+ Client.messages << message
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ module SmsMock
2
+ module Matchers
3
+ RSpec::Matchers.define :have_body do |body|
4
+ match do |message|
5
+ message.body == body
6
+ end
7
+ end
8
+
9
+ RSpec::Matchers.define :be_sent_from do |from|
10
+ match do |message|
11
+ message.from == from
12
+ end
13
+ end
14
+
15
+ RSpec::Matchers.define :be_sent_to do |to|
16
+ match do |message|
17
+ message.to == to
18
+ end
19
+ end
20
+
21
+ RSpec::Matchers.define :have_messages do |size|
22
+ match do |client|
23
+ if !size.nil?
24
+ client.messages.size == size
25
+ else
26
+ !client.messages.empty?
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ module SmsMock
2
+ class Message
3
+ attr_accessor :to, :body, :from
4
+
5
+ def initialize(opts={})
6
+ @to = opts[:to]
7
+ @body = opts[:body]
8
+ @from = opts[:from]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ module Twilio
2
+ module REST
3
+ class Client < BaseClient
4
+ def initialize(account_sid, auth_token)
5
+ @account_sid = account_sid
6
+ @auth_token = auth_token
7
+ end
8
+
9
+ def account
10
+ @account ||= Account.new
11
+ end
12
+ end
13
+
14
+ class Account < InstanceResource
15
+ def initialize
16
+ end
17
+
18
+ def sms
19
+ @sms ||= Sms.new
20
+ end
21
+ end
22
+
23
+ class Sms < InstanceResource
24
+ def initialize
25
+ end
26
+
27
+ def messages
28
+ @messages ||= Messages.new
29
+ end
30
+ end
31
+
32
+ class Messages < ListResource
33
+ include SmsMock::Helpers
34
+ def initialize
35
+ end
36
+
37
+ def create(opts={})
38
+ add_message SmsMock::Message.new opts
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module SmsMock
2
+ VERSION = "0.0.4"
3
+ end
data/lib/smsmock.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'smsmock/helpers'
3
+ require 'smsmock/client'
4
+ require 'smsmock/message'
5
+ require 'smsmock/matchers'
6
+ require 'smsmock/twilio/client'
data/smsmock.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ # Maintain your gem's version:
5
+ require 'smsmock/version'
6
+
7
+ # Describe your gem and declare its dependencies:
8
+ Gem::Specification.new do |s|
9
+ s.name = 'smsmock'
10
+ s.version = SmsMock::VERSION
11
+ s.authors = ['Niels van der Zanden']
12
+ s.email = ['niels@pharynx.nl']
13
+ s.homepage = 'https://github.com/scarhand/smsmock'
14
+ s.summary = 'Sms mocker for twilio-ruby.'
15
+ s.description = 'Sms mocker for twilio-ruby.'
16
+
17
+ s.files = Dir["{lib}/**/*"] + ['smsmock.gemspec','README.md']
18
+
19
+ s.add_dependency 'rspec'
20
+ s.add_development_dependency 'twilio-ruby'
21
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smsmock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Niels van der Zanden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: twilio-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Sms mocker for twilio-ruby.
42
+ email:
43
+ - niels@pharynx.nl
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/smsmock.rb
50
+ - lib/smsmock/client.rb
51
+ - lib/smsmock/helpers.rb
52
+ - lib/smsmock/matchers.rb
53
+ - lib/smsmock/message.rb
54
+ - lib/smsmock/twilio/client.rb
55
+ - lib/smsmock/version.rb
56
+ - smsmock.gemspec
57
+ homepage: https://github.com/scarhand/smsmock
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.6
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Sms mocker for twilio-ruby.
80
+ test_files: []