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 +4 -4
- data/README.md +29 -8
- data/lib/smsmock/matchers.rb +44 -2
- data/lib/smsmock/message.rb +1 -1
- data/lib/smsmock/twilio/client.rb +2 -1
- data/lib/smsmock/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9af7c5d75d0fabb9f1cbbd5f808b4ab8a00c628
|
4
|
+
data.tar.gz: a73b828c192ad76f991e0a6d60080fb7cf21009b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
7
|
+
```ruby
|
8
8
|
group :test do
|
9
9
|
gem 'smsmock'
|
10
10
|
end
|
11
|
-
|
11
|
+
```
|
12
12
|
|
13
13
|
## RSpec
|
14
14
|
In your spec_helper.rb file require the smsmocker.
|
15
15
|
|
16
|
-
|
16
|
+
```ruby
|
17
17
|
require 'smsmock'
|
18
|
-
|
18
|
+
```
|
19
19
|
|
20
20
|
## Example
|
21
|
-
|
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
|
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
|
-
|
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
|
+
```
|
data/lib/smsmock/matchers.rb
CHANGED
@@ -18,7 +18,7 @@ module SmsMock
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
RSpec::Matchers.define :
|
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
|
data/lib/smsmock/message.rb
CHANGED
data/lib/smsmock/version.rb
CHANGED