fibber_mailman 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +7 -0
- data/README.md +41 -0
- data/Rakefile +14 -0
- data/fibber_mailman.gemspec +34 -0
- data/lib/fibber_mailman.rb +47 -0
- data/test/fibber_mailman_test.rb +26 -0
- data/test/fixtures/mail1.raw_mail +11 -0
- data/test/fixtures/mail2.raw_mail +11 -0
- metadata +94 -0
data/Manifest
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# FibberMailman
|
2
|
+
|
3
|
+
**Hey Mailmal.. lie to me!**
|
4
|
+
|
5
|
+
Very simple library for mocking a
|
6
|
+
|
7
|
+
Net::POP3.start( ... ) do |pop|
|
8
|
+
<any code here>
|
9
|
+
end
|
10
|
+
|
11
|
+
call
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
raw_mails = [
|
15
|
+
File.read( "/fixtures/mail1.raw_mail" ) ),
|
16
|
+
File.read( "/fixtures/mail2.raw_mail" ) ),
|
17
|
+
]
|
18
|
+
|
19
|
+
FibberMailman.lie_to_me( raw_mails ) do
|
20
|
+
<your code that uses the Net::POP3.start on any point>
|
21
|
+
end
|
22
|
+
|
23
|
+
Not any real POP call will be done.
|
24
|
+
|
25
|
+
The mock will simulate that the mails received was the fake **raw_mails**.
|
26
|
+
|
27
|
+
See the **test** folder.
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
Only
|
32
|
+
pop.each_mail do |m|
|
33
|
+
<code here>
|
34
|
+
end
|
35
|
+
|
36
|
+
is supported.
|
37
|
+
|
38
|
+
## Special Thanks
|
39
|
+
|
40
|
+
* To the people on this (Ruby Forum Thread)[http://www.ruby-forum.com/topic/214129]
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('fibber_mailman', '0.0.3') do |p|
|
6
|
+
p.description = "FibberMailman lie to you when you ask for a Net::POP3.start call."
|
7
|
+
p.url = "http://github.com/fguillen/FibberMailman"
|
8
|
+
p.author = "http://fernandoguillen.info"
|
9
|
+
p.email = "fguillen.mail@gmail.com"
|
10
|
+
p.ignore_pattern = []
|
11
|
+
p.development_dependencies = [ "tmail" ]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{fibber_mailman}
|
5
|
+
s.version = "0.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["http://fernandoguillen.info"]
|
9
|
+
s.date = %q{2010-08-02}
|
10
|
+
s.description = %q{FibberMailman lie to you when you ask for a Net::POP3.start call.}
|
11
|
+
s.email = %q{fguillen.mail@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.md", "lib/fibber_mailman.rb"]
|
13
|
+
s.files = ["README.md", "Rakefile", "lib/fibber_mailman.rb", "test/fibber_mailman_test.rb", "test/fixtures/mail1.raw_mail", "test/fixtures/mail2.raw_mail", "Manifest", "fibber_mailman.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/fguillen/FibberMailman}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fibber_mailman", "--main", "README.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{fibber_mailman}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{FibberMailman lie to you when you ask for a Net::POP3.start call.}
|
20
|
+
s.test_files = ["test/fibber_mailman_test.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_development_dependency(%q<tmail>, [">= 0"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<tmail>, [">= 0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<tmail>, [">= 0"])
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/pop'
|
2
|
+
|
3
|
+
class FibberPop
|
4
|
+
def initialize( raw_mail)
|
5
|
+
@raw_mail = raw_mail
|
6
|
+
end
|
7
|
+
|
8
|
+
def pop
|
9
|
+
return @raw_mail
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(m, *args, &block)
|
13
|
+
puts "PopMock.#{m} called"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class FibberMailman
|
18
|
+
def self.lie_to_me( raw_mails )
|
19
|
+
@@raw_mails = raw_mails
|
20
|
+
|
21
|
+
# mocking
|
22
|
+
Net::POP3.class_eval do
|
23
|
+
alias_method :orig_start, :start
|
24
|
+
def start( *, &block )
|
25
|
+
block.call( self )
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :orig_mails, :mails
|
29
|
+
def mails
|
30
|
+
pop_mails = @@raw_mails.map { |raw_mail| FibberPop.new( raw_mail ) }
|
31
|
+
return pop_mails
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
yield
|
37
|
+
ensure
|
38
|
+
|
39
|
+
# unmocking
|
40
|
+
Net::POP3.class_eval do
|
41
|
+
alias_method :start, :orig_start
|
42
|
+
alias_method :mails, :orig_mails
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/pop'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'tmail'
|
5
|
+
require File.dirname(__FILE__) + "/../lib/fibber_mailman"
|
6
|
+
|
7
|
+
class FibberMailmanTest < Test::Unit::TestCase
|
8
|
+
def test_mocking
|
9
|
+
raw_mails = [
|
10
|
+
File.read( File.dirname(__FILE__) + "/fixtures/mail1.raw_mail" ),
|
11
|
+
File.read( File.dirname(__FILE__) + "/fixtures/mail2.raw_mail" ),
|
12
|
+
]
|
13
|
+
|
14
|
+
mails_subjects = []
|
15
|
+
FibberMailman.lie_to_me( raw_mails ) do
|
16
|
+
Net::POP3.start( 'server', 'port', 'user', 'pass' ) do |pop|
|
17
|
+
pop.each_mail do |mail|
|
18
|
+
tmail = TMail::Mail.parse( mail.pop )
|
19
|
+
mails_subjects << tmail.subject
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal( ['test 1', 'test 2'], mails_subjects )
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
MIME-Version: 1.0
|
2
|
+
Received: by 10.227.154.200 with HTTP; Mon, 2 Aug 2010 07:51:46 -0700 (PDT)
|
3
|
+
Date: Mon, 2 Aug 2010 16:51:46 +0200
|
4
|
+
Delivered-To: xxx@gmail.com
|
5
|
+
Message-ID: <AANLkTim3fkv-8hUrKf-MPUfyQxdV_3jH44UqQh2dWqjS@mail.gmail.com>
|
6
|
+
Subject: test 1
|
7
|
+
From: Fernando Guillen <xxx@gmail.com>
|
8
|
+
To: =?UTF-8?Q?Fernando_Guill=C3=A9n?= <xxx@gmail.com>
|
9
|
+
Content-Type: text/plain; charset=UTF-8
|
10
|
+
|
11
|
+
Test Mail 1
|
@@ -0,0 +1,11 @@
|
|
1
|
+
MIME-Version: 1.0
|
2
|
+
Received: by 10.227.154.200 with HTTP; Mon, 2 Aug 2010 07:51:59 -0700 (PDT)
|
3
|
+
Date: Mon, 2 Aug 2010 16:51:59 +0200
|
4
|
+
Delivered-To: xxx@gmail.com
|
5
|
+
Message-ID: <AANLkTiku5OQEfRK8tgpd_fnF44BRCaT61Pz3Q9EDUJhm@mail.gmail.com>
|
6
|
+
Subject: test 2
|
7
|
+
From: Fernando Guillen <xxx@gmail.com>
|
8
|
+
To: =?UTF-8?Q?Fernando_Guill=C3=A9n?= <xxx@gmail.com>
|
9
|
+
Content-Type: text/plain; charset=UTF-8
|
10
|
+
|
11
|
+
Test Mail 2
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fibber_mailman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- http://fernandoguillen.info
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-02 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: tmail
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: FibberMailman lie to you when you ask for a Net::POP3.start call.
|
36
|
+
email: fguillen.mail@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
43
|
+
- lib/fibber_mailman.rb
|
44
|
+
files:
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- lib/fibber_mailman.rb
|
48
|
+
- test/fibber_mailman_test.rb
|
49
|
+
- test/fixtures/mail1.raw_mail
|
50
|
+
- test/fixtures/mail2.raw_mail
|
51
|
+
- Manifest
|
52
|
+
- fibber_mailman.gemspec
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/fguillen/FibberMailman
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --line-numbers
|
60
|
+
- --inline-source
|
61
|
+
- --title
|
62
|
+
- Fibber_mailman
|
63
|
+
- --main
|
64
|
+
- README.md
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 11
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 2
|
85
|
+
version: "1.2"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: fibber_mailman
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: FibberMailman lie to you when you ask for a Net::POP3.start call.
|
93
|
+
test_files:
|
94
|
+
- test/fibber_mailman_test.rb
|