smsmock 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a3d444cd9be9520d15a964c9451beae5ba9f6b0
4
- data.tar.gz: ca406ba1fb48ba90d770f854df9132ddb92af96a
3
+ metadata.gz: e9af7c5d75d0fabb9f1cbbd5f808b4ab8a00c628
4
+ data.tar.gz: a73b828c192ad76f991e0a6d60080fb7cf21009b
5
5
  SHA512:
6
- metadata.gz: 68138a4116bd1646b77874906805214f088e652bc23fbe73473d11a9a7da2ef4c0657377ad990db4b7f5fcf9e56f18ecb7c274cb6c14937a65ba8fa840f97445
7
- data.tar.gz: 210c5aa91753e365d6999b84e48f4e86090e62fff0b677715642efb1b1368a7560df762c11f050ed349a53182d920bd5f1317344093e179326271d09a4356b3a
6
+ metadata.gz: 445a165f2818c8fbb03010004717d45cfd99947c0064b3c6911650f881df5cfeeb56e1686031f700c824e798686467c64c7ee8aa93353bf4019920831c49c3a6
7
+ data.tar.gz: 3cbba8fb942dbaac2b277061bf3384697444ba64a8a176259c13e6b8313328a5eae5ad8cc4ebf0ddaf03d3a7253e676aac6016fd7f9f9b74fa0d7b923c4600c3
data/README.md CHANGED
@@ -1,24 +1,24 @@
1
1
  # SmsMock
2
2
 
3
- Adds [twilio-ruby](https://github.com/twilio/twilio-ruby) RSpec test for testing SMS interactions.
3
+ Adds [twilio-ruby](https://github.com/twilio/twilio-ruby) RSpec tests for testing SMS interactions.
4
4
 
5
5
  ##Setup
6
6
  Add the smsmock gem to your Gemfile:
7
- <pre>
7
+ ```ruby
8
8
  group :test do
9
9
  gem 'smsmock'
10
10
  end
11
- </pre>
11
+ ```
12
12
 
13
13
  ## RSpec
14
14
  In your spec_helper.rb file require the smsmocker.
15
15
 
16
- <pre>
16
+ ```ruby
17
17
  require 'smsmock'
18
- </pre>
18
+ ```
19
19
 
20
20
  ## Example
21
- <pre>
21
+ ```ruby
22
22
  require 'spec_helper'
23
23
 
24
24
  describe SmsMock do
@@ -29,10 +29,31 @@ describe SmsMock do
29
29
 
30
30
  it 'add a message to SmsMock::Client' do
31
31
  @client.messages.create(to: '123981', body: 'abc123', from: '1291')
32
- expect(SmsMock::Client).to have_messages
32
+ expect(SmsMock::Client).to have_sent_messages
33
33
  expect(SmsMock::Client.messages.last).to have_body 'abc123'
34
34
  expect(SmsMock::Client.messages.last).to be_sent_from '1291'
35
35
  expect(SmsMock::Client.messages.last).to be_sent_to '123981'
36
36
  end
37
37
  end
38
- </pre>
38
+ ```
39
+
40
+ The following matchers can be used:
41
+ ```ruby
42
+ # for SmsMock::Client
43
+ expect(SmsMock::Client).to have_sent_messages
44
+ expect(SmsMock::Client).to have_sent_messages 2
45
+ expect(SmsMock::Client).to have_sent_message_to '123456'
46
+ expect(SmsMock::Client).to have_sent_message_from '123456'
47
+ expect(SmsMock::Client).to have_sent_message_with_body 'abc123'
48
+
49
+ # with chaining:
50
+ expect(SmsMock::Client).to have_sent_message_to('123456').and from('654321').and with_body('abc123')
51
+
52
+ # for individual messages
53
+ expect(SmsMock::Client.messages.last).to have_body 'abc123'
54
+ expect(SmsMock::Client.messages.last).to be_sent_from '1291'
55
+ expect(SmsMock::Client.messages.last).to be_sent_to '123981'
56
+
57
+ # with chaining:
58
+ expect(SmsMock::Client.messages.last).to be_sent_to('123456').and from('654321').and with_body('abc123')
59
+ ```
@@ -18,7 +18,7 @@ module SmsMock
18
18
  end
19
19
  end
20
20
 
21
- RSpec::Matchers.define :have_messages do |size|
21
+ RSpec::Matchers.define :have_sent_messages do |size|
22
22
  match do |client|
23
23
  if !size.nil?
24
24
  client.messages.size == size
@@ -27,5 +27,47 @@ module SmsMock
27
27
  end
28
28
  end
29
29
  end
30
+
31
+ RSpec::Matchers.define :have_sent do |size|
32
+ match do |client|
33
+ if !size.nil?
34
+ client.messages.size == size
35
+ else
36
+ !client.messages.empty?
37
+ end
38
+ end
39
+
40
+ chain :messages, :void
41
+ end
42
+
43
+ RSpec::Matchers.define :have_sent_message_to do |to|
44
+ match do |client|
45
+ if client.respond_to? :messages
46
+ !(client.messages.find { |message| message.to == to } ).nil?
47
+ else
48
+ client.to == to
49
+ end
50
+ end
51
+ end
52
+
53
+ RSpec::Matchers.define :have_sent_message_from do |from|
54
+ match do |client|
55
+ if client.respond_to? :messages
56
+ !(client.messages.find { |message| message.from == from } ).nil?
57
+ else
58
+ client.from == from
59
+ end
60
+ end
61
+ end
62
+
63
+ RSpec::Matchers.define :have_sent_message_with_body do |body|
64
+ match do |client|
65
+ !(client.messages.find { |message| message.body == body } ).nil?
66
+ end
67
+ end
68
+
69
+ RSpec::Matchers.alias_matcher :to, :have_sent_message_to
70
+ RSpec::Matchers.alias_matcher :from, :have_sent_message_from
71
+ RSpec::Matchers.alias_matcher :with_body, :have_sent_message_with_body
30
72
  end
31
- end
73
+ end
@@ -2,7 +2,7 @@ module SmsMock
2
2
  class Message
3
3
  attr_accessor :to, :body, :from
4
4
 
5
- def initialize(opts={})
5
+ def initialize(opts = {})
6
6
  @to = opts[:to]
7
7
  @body = opts[:body]
8
8
  @from = opts[:from]
@@ -2,10 +2,11 @@ module Twilio
2
2
  module REST
3
3
  class Messages < ListResource
4
4
  include SmsMock::Helpers
5
+
5
6
  def initialize(*args)
6
7
  end
7
8
 
8
- def create(opts={})
9
+ def create(opts = {})
9
10
  add_message SmsMock::Message.new opts
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module SmsMock
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smsmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niels van der Zanden