malone 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,11 @@ Originally taken from my initial draft [here][blogpost].
3
3
  [blogpost]: http://www.pipetodevnull.com/past/2010/11/27/simple_mailer/
4
4
 
5
5
  ## USAGE
6
-
6
+
7
7
  $ gem install malone
8
8
 
9
9
  require "malone"
10
-
10
+
11
11
  # typically you would do this somewhere in the bootstrapping
12
12
  # part of your application
13
13
 
@@ -27,6 +27,28 @@ Originally taken from my initial draft [here][blogpost].
27
27
 
28
28
  That's it!
29
29
 
30
- ## LICENSE
30
+ ## TESTING
31
+
32
+ require "malone/sandbox"
33
+
34
+ Malone.deliver(from: "me@me.com", to: "you@me.com",
35
+ subject: "Test subject", body: "Great!")
36
+
37
+ Malone.deliveries.size == 1
38
+ # => true
39
+
40
+ envelope = Malone.deliveries.first
41
+
42
+ "me@me.com" == envelope.from
43
+ # => true
44
+
45
+ "you@me.com" == envelope.to
46
+ # => true
47
+
48
+ "FooBar" == envelope.body
49
+ # => true
50
+
51
+ "Hello World" == envelope.subject## LICENSE
52
+ # => true
31
53
 
32
- MIT
54
+ MIT
@@ -3,7 +3,7 @@ require "ostruct"
3
3
  require "mailfactory"
4
4
 
5
5
  class Malone
6
- VERSION = "0.0.1"
6
+ VERSION = "0.0.2"
7
7
 
8
8
  attr :envelope
9
9
 
@@ -0,0 +1,13 @@
1
+ require "ostruct"
2
+
3
+ class Malone
4
+ def self.deliveries
5
+ @deliveries ||= []
6
+ end
7
+
8
+ def self.deliver(*args)
9
+ deliveries << OpenStruct.new(*args)
10
+ end
11
+ end
12
+
13
+
@@ -51,34 +51,36 @@ scope do
51
51
  auth: :login
52
52
  )
53
53
  end
54
-
54
+
55
55
  test "delivering successfully" do
56
56
  malone = Malone.new(to: "you@me.com", from: "me@me.com",
57
57
  subject: "My subject", body: "My body")
58
-
58
+
59
59
  # Let's begin the mocking fun
60
60
  sender = flexmock("smtp sender")
61
-
61
+
62
62
  # We start out by capturing the Net::SMTP.new part
63
- flexmock(Net::SMTP).should_receive(:new).and_return(sender)
64
-
65
- # Since we configured it with tls: true, then enable_starttls
63
+ flexmock(Net::SMTP).should_receive(:new).with(
64
+ "smtp.gmail.com", 587
65
+ ).and_return(sender)
66
+
67
+ # Since we configured it with tls: true, then enable_starttls
66
68
  # should be called
67
69
  sender.should_receive(:enable_starttls).once
68
-
70
+
69
71
  # Now we verify that start was indeed called exactly with the arguments
70
72
  # we passed in
71
73
  sender.should_receive(:start).once.with(
72
- "mydomain.com", "me@mydomain.com", "mypass", :login,
74
+ "mydomain.com", "me@mydomain.com", "mypass", :login,
73
75
  )
74
76
 
75
77
  # This is a bit of a hack, since envelope.to_s changes everytime.
76
78
  # Specifically, The Message-ID part changes.
77
79
  envelope_to_s = malone.envelope.to_s
78
-
80
+
79
81
  # So we get one result of envelope.to_s
80
82
  flexmock(malone.envelope).should_receive(:to_s).and_return(envelope_to_s)
81
-
83
+
82
84
  # And then we make sure that that value of envelope.to_s is used
83
85
  # instead of making it generate a new Message-ID
84
86
  sender.should_receive(:send_message).once.with(
@@ -88,7 +90,7 @@ scope do
88
90
  # I think this is important, otherwise the connection to the
89
91
  # smtp server won't be closed properly
90
92
  sender.should_receive(:finish).once
91
-
93
+
92
94
  # One important part of the API of malone is that deliver
93
95
  # should return the result of Net::SMTP#send_message.
94
96
  assert "OK" == malone.deliver
@@ -97,25 +99,27 @@ scope do
97
99
  test "delivering and failing" do
98
100
  malone = Malone.new(to: "you@me.com", from: "me@me.com",
99
101
  subject: "My subject", body: "My body")
100
-
102
+
101
103
  # This is more or less the same example as above,
102
104
  # except that here we make send_message fail
103
105
  # and verify that finish is still called
104
106
  sender = flexmock("smtp sender")
105
107
 
106
- flexmock(Net::SMTP).should_receive(:new).and_return(sender)
108
+ flexmock(Net::SMTP).should_receive(:new).with(
109
+ "smtp.gmail.com", 587
110
+ ).and_return(sender)
107
111
 
108
112
  sender.should_receive(:enable_starttls).once
109
113
 
110
114
  sender.should_receive(:start).once.with(
111
- "mydomain.com", "me@mydomain.com", "mypass", :login,
115
+ "mydomain.com", "me@mydomain.com", "mypass", :login,
112
116
  )
113
-
117
+
114
118
  sender.should_receive(:send_message).once.and_raise(StandardError)
115
119
  sender.should_receive(:finish).once
116
-
120
+
117
121
  assert_raise StandardError do
118
122
  assert nil == malone.deliver
119
123
  end
120
124
  end
121
- end
125
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path("helper", File.dirname(__FILE__))
2
+ require File.expand_path("../lib/malone/sandbox", File.dirname(__FILE__))
3
+
4
+ test "deliveries" do
5
+ Malone.deliver from: "me@me.com", to: "you@me.com",
6
+ body: "FooBar", subject: "Hello World"
7
+
8
+ assert_equal 1, Malone.deliveries.size
9
+
10
+ envelope = Malone.deliveries.first
11
+
12
+ assert_equal "me@me.com", envelope.from
13
+ assert_equal "you@me.com", envelope.to
14
+ assert_equal "FooBar", envelope.body
15
+ assert_equal "Hello World", envelope.subject
16
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-28 00:00:00 +08:00
17
+ date: 2011-01-10 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -65,11 +65,13 @@ extensions: []
65
65
  extra_rdoc_files: []
66
66
 
67
67
  files:
68
+ - lib/malone/sandbox.rb
68
69
  - lib/malone.rb
69
70
  - README.markdown
70
71
  - LICENSE
71
72
  - test/helper.rb
72
- - test/malone_test.rb
73
+ - test/malone.rb
74
+ - test/sandbox.rb
73
75
  has_rdoc: true
74
76
  homepage: http://github.com/cyx/malone
75
77
  licenses: []