capybara-email 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.
- data/.gitignore +1 -0
- data/README.md +53 -11
- data/capybara-email.gemspec +3 -0
- data/lib/capybara/email.rb +10 -4
- data/lib/capybara/email/driver.rb +18 -2
- data/lib/capybara/email/rspec/helpers.rb +2 -2
- data/lib/capybara/email/version.rb +1 -1
- data/lib/capybara/node/email.rb +24 -0
- data/spec/email/driver_spec.rb +41 -9
- data/spec/node/email_spec.rb +73 -0
- data/spec/spec_helper.rb +10 -1
- metadata +42 -8
- data/spec/email/node_spec.rb +0 -1
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# CapybaraEmail #
|
2
2
|
|
3
|
-
|
3
|
+
Easily test ActionMailer and Mail emails in your Capybara integration tests
|
4
4
|
|
5
|
-
## Installation
|
5
|
+
## Installation ##
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
@@ -16,14 +16,56 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install capybara-email
|
18
18
|
|
19
|
-
## Usage
|
19
|
+
## Usage ##
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
# rspec example
|
22
23
|
|
23
|
-
|
24
|
+
feature 'Emailer' do
|
25
|
+
background do
|
26
|
+
# will clear the mail queue
|
27
|
+
clear_emails
|
28
|
+
visit email_trigger_path
|
29
|
+
# Will find an email sent to test@example.com
|
30
|
+
# and set the `current_email` helper
|
31
|
+
open_email('test@example.com')
|
32
|
+
end
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
scenario 'following a link' do
|
35
|
+
current_email.click_link 'your profile'
|
36
|
+
page.should have_content 'Profile page'
|
37
|
+
end
|
38
|
+
|
39
|
+
scenario 'testing for content' do
|
40
|
+
current_email.should have_content 'Hello Joe!'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
## Authors ##
|
46
|
+
|
47
|
+
[Brian Cardarella](http://twitter.com/bcardarella)
|
48
|
+
|
49
|
+
## Versioning ##
|
50
|
+
|
51
|
+
This gem follows [Semantic Versioning](http://semver.org)
|
52
|
+
|
53
|
+
## Want to help? ##
|
54
|
+
|
55
|
+
Stable branches are created based upon each minor version. Please make
|
56
|
+
pull requests to specific branches rather than master.
|
57
|
+
|
58
|
+
Please make sure you include tests!
|
59
|
+
|
60
|
+
Unless Rails drops support for Ruby 1.8.7 we will continue to use the
|
61
|
+
hash-rocket syntax. Please respect this.
|
62
|
+
|
63
|
+
Don't use tabs to indent, two spaces are the standard.
|
64
|
+
|
65
|
+
## Legal ##
|
66
|
+
|
67
|
+
[DockYard](http://dockyard.com), LLC © 2012
|
68
|
+
|
69
|
+
[@dockyard](http://twitter.com/dockyard)
|
70
|
+
|
71
|
+
[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
|
data/capybara-email.gemspec
CHANGED
@@ -15,7 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ['lib']
|
16
16
|
gem.version = Capybara::Email::VERSION
|
17
17
|
|
18
|
+
gem.add_development_dependency 'mail'
|
18
19
|
gem.add_development_dependency 'actionmailer'
|
20
|
+
gem.add_development_dependency 'sinatra'
|
19
21
|
gem.add_development_dependency 'capybara'
|
22
|
+
gem.add_development_dependency 'bourne'
|
20
23
|
gem.add_development_dependency 'rspec'
|
21
24
|
end
|
data/lib/capybara/email.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
module Capybara
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Capybara
|
2
|
+
module Node
|
3
|
+
autoload :Email, 'capybara/node/email'
|
4
|
+
end
|
5
|
+
|
6
|
+
module Email
|
7
|
+
autoload :Node, 'capybara/email/node'
|
8
|
+
autoload :Driver, 'capybara/email/driver'
|
9
|
+
autoload :Version, 'capybara/email/version'
|
10
|
+
end
|
5
11
|
end
|
6
12
|
|
@@ -13,6 +13,18 @@ class Capybara::Email::Driver < Capybara::Driver::Base
|
|
13
13
|
dom.to_xml
|
14
14
|
end
|
15
15
|
|
16
|
+
def subject
|
17
|
+
email.subject
|
18
|
+
end
|
19
|
+
|
20
|
+
def to
|
21
|
+
email.to
|
22
|
+
end
|
23
|
+
|
24
|
+
def from
|
25
|
+
email.from
|
26
|
+
end
|
27
|
+
|
16
28
|
def dom
|
17
29
|
@dom ||= Nokogiri::HTML(source)
|
18
30
|
end
|
@@ -23,12 +35,16 @@ class Capybara::Email::Driver < Capybara::Driver::Base
|
|
23
35
|
|
24
36
|
def source
|
25
37
|
if email.mime_type == 'text/plain'
|
26
|
-
convert_to_html(
|
38
|
+
convert_to_html(raw)
|
27
39
|
else
|
28
|
-
|
40
|
+
raw
|
29
41
|
end
|
30
42
|
end
|
31
43
|
|
44
|
+
def raw
|
45
|
+
email.body.encoded
|
46
|
+
end
|
47
|
+
|
32
48
|
private
|
33
49
|
|
34
50
|
def convert_to_html(text)
|
@@ -2,13 +2,13 @@ module Capybara::Email::RSpecHelpers
|
|
2
2
|
attr_accessor :current_email, :current_emails
|
3
3
|
|
4
4
|
def all_emails
|
5
|
-
|
5
|
+
Mail::TestMailer.deliveries
|
6
6
|
end
|
7
7
|
|
8
8
|
def emails_sent_to(recipient)
|
9
9
|
self.current_emails = all_emails.select { |email| email.to.include?(recipient) }.map do |email|
|
10
10
|
driver = Capybara::Email::Driver.new(email)
|
11
|
-
Capybara::Node::
|
11
|
+
Capybara::Node::Email.new(Capybara.current_session, driver)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Capybara::Node::Email < Capybara::Node::Document
|
2
|
+
|
3
|
+
def body
|
4
|
+
base.raw
|
5
|
+
end
|
6
|
+
|
7
|
+
def subject
|
8
|
+
base.subject
|
9
|
+
end
|
10
|
+
|
11
|
+
def to
|
12
|
+
base.to
|
13
|
+
end
|
14
|
+
|
15
|
+
def from
|
16
|
+
base.from
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_and_open
|
20
|
+
require 'capybara/util/save_and_open_page'
|
21
|
+
::Capybara.save_and_open_page(body)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/email/driver_spec.rb
CHANGED
@@ -1,36 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class TestApp
|
4
|
+
def self.call(env)
|
5
|
+
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
feature 'Integration test' do
|
4
10
|
background do
|
5
11
|
clear_email
|
6
|
-
Capybara.app = TestApp
|
12
|
+
Capybara.app = ::TestApp
|
7
13
|
end
|
8
14
|
|
9
15
|
scenario 'html email' do
|
10
|
-
deliver(html_email)
|
11
|
-
|
16
|
+
email = deliver(html_email)
|
17
|
+
|
18
|
+
open_email('test@example.com')
|
12
19
|
current_email.click_link 'example'
|
13
20
|
page.should have_content 'Hello world!'
|
14
21
|
current_email.should have_content 'This is only a html test'
|
22
|
+
|
23
|
+
all_emails.first.should == email
|
24
|
+
|
25
|
+
clear_emails()
|
26
|
+
all_emails.should be_empty
|
27
|
+
|
15
28
|
end
|
16
29
|
|
17
30
|
scenario 'plain text email' do
|
18
|
-
deliver(plain_email)
|
31
|
+
email = deliver(plain_email)
|
32
|
+
|
19
33
|
open_email('test@example.com')
|
20
34
|
current_email.click_link 'http://example.com'
|
21
35
|
page.should have_content 'Hello world!'
|
22
36
|
current_email.should have_content 'This is only a plain test.'
|
23
|
-
end
|
24
|
-
end
|
25
37
|
|
26
|
-
|
27
|
-
|
28
|
-
|
38
|
+
all_emails.first.should == email
|
39
|
+
|
40
|
+
clear_emails()
|
41
|
+
all_emails.should be_empty
|
29
42
|
end
|
43
|
+
|
44
|
+
scenario 'via ActionMailer' do
|
45
|
+
email = deliver(plain_email)
|
46
|
+
|
47
|
+
all_emails.first.should == email
|
48
|
+
|
49
|
+
clear_emails
|
50
|
+
all_emails.should be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
scenario 'via Mail' do
|
54
|
+
email = plain_email.deliver!
|
55
|
+
|
56
|
+
all_emails.first.should == email
|
57
|
+
|
58
|
+
clear_emails
|
59
|
+
all_emails.should be_empty
|
60
|
+
end
|
30
61
|
end
|
31
62
|
|
32
63
|
def deliver(email)
|
33
64
|
ActionMailer::Base.deliveries << email
|
65
|
+
email
|
34
66
|
end
|
35
67
|
|
36
68
|
def html_email
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Capybara::Node::Email do
|
4
|
+
let(:message) { Mail::Message.new }
|
5
|
+
let(:email) { Capybara::Node::Email.new(nil, Capybara::Email::Driver.new(message)) }
|
6
|
+
|
7
|
+
describe '#body' do
|
8
|
+
context 'html' do
|
9
|
+
before do
|
10
|
+
message.content_type = 'text/html'
|
11
|
+
message.body = '<a href="http://example.com">example</a>'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'delegates to the base' do
|
15
|
+
email.body.should eq '<a href="http://example.com">example</a>'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'plain' do
|
20
|
+
before do
|
21
|
+
message.content_type = 'text/plain'
|
22
|
+
message.body = 'http://example.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'delegates to the base' do
|
26
|
+
email.body.should eq 'http://example.com'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#subject' do
|
32
|
+
before do
|
33
|
+
message.subject = 'Test subject'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'delegates to the base' do
|
37
|
+
email.subject.should eq 'Test subject'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#to' do
|
42
|
+
before do
|
43
|
+
message.to = 'test@example.com'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'delegates to the base' do
|
47
|
+
email.to.should include 'test@example.com'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#from' do
|
52
|
+
before do
|
53
|
+
message.from = 'test@example.com'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'delegates to the base' do
|
57
|
+
email.from.should include 'test@example.com'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#save_and_open' do
|
62
|
+
before do
|
63
|
+
require 'capybara/util/save_and_open_page'
|
64
|
+
message.body = 'Test message'
|
65
|
+
::Capybara.stubs(:save_and_open_page)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'delegates to Capybara.save_and_open_page' do
|
69
|
+
email.save_and_open
|
70
|
+
Capybara.should have_received(:save_and_open_page).with('Test message')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'mail'
|
3
|
+
require 'bourne'
|
2
4
|
require 'action_mailer'
|
3
5
|
require 'capybara/rspec'
|
4
6
|
require 'capybara/email/rspec'
|
5
|
-
|
7
|
+
|
8
|
+
Mail.defaults do
|
9
|
+
delivery_method :test
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.mock_with :mocha
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,9 +11,31 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-03-04 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mail
|
16
|
+
requirement: &70133949377220 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70133949377220
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: actionmailer
|
16
|
-
requirement: &
|
27
|
+
requirement: &70133949376800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70133949376800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sinatra
|
38
|
+
requirement: &70133949376380 !ruby/object:Gem::Requirement
|
17
39
|
none: false
|
18
40
|
requirements:
|
19
41
|
- - ! '>='
|
@@ -21,10 +43,21 @@ dependencies:
|
|
21
43
|
version: '0'
|
22
44
|
type: :development
|
23
45
|
prerelease: false
|
24
|
-
version_requirements: *
|
46
|
+
version_requirements: *70133949376380
|
25
47
|
- !ruby/object:Gem::Dependency
|
26
48
|
name: capybara
|
27
|
-
requirement: &
|
49
|
+
requirement: &70133949375960 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70133949375960
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bourne
|
60
|
+
requirement: &70133949375540 !ruby/object:Gem::Requirement
|
28
61
|
none: false
|
29
62
|
requirements:
|
30
63
|
- - ! '>='
|
@@ -32,10 +65,10 @@ dependencies:
|
|
32
65
|
version: '0'
|
33
66
|
type: :development
|
34
67
|
prerelease: false
|
35
|
-
version_requirements: *
|
68
|
+
version_requirements: *70133949375540
|
36
69
|
- !ruby/object:Gem::Dependency
|
37
70
|
name: rspec
|
38
|
-
requirement: &
|
71
|
+
requirement: &70133949375120 !ruby/object:Gem::Requirement
|
39
72
|
none: false
|
40
73
|
requirements:
|
41
74
|
- - ! '>='
|
@@ -43,7 +76,7 @@ dependencies:
|
|
43
76
|
version: '0'
|
44
77
|
type: :development
|
45
78
|
prerelease: false
|
46
|
-
version_requirements: *
|
79
|
+
version_requirements: *70133949375120
|
47
80
|
description: Test your ActionMailer emails in Capybara
|
48
81
|
email:
|
49
82
|
- bcardarella@gmail.com
|
@@ -66,8 +99,9 @@ files:
|
|
66
99
|
- lib/capybara/email/rspec.rb
|
67
100
|
- lib/capybara/email/rspec/helpers.rb
|
68
101
|
- lib/capybara/email/version.rb
|
102
|
+
- lib/capybara/node/email.rb
|
69
103
|
- spec/email/driver_spec.rb
|
70
|
-
- spec/
|
104
|
+
- spec/node/email_spec.rb
|
71
105
|
- spec/spec_helper.rb
|
72
106
|
homepage: https://github.com/dockyard/capybara-email
|
73
107
|
licenses: []
|
data/spec/email/node_spec.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|