capybara-email 0.0.2 → 0.1.0
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/README.md +59 -6
- data/lib/capybara-email.rb +1 -4
- data/lib/capybara/email.rb +1 -0
- data/lib/capybara/email/{rspec/helpers.rb → dsl.rb} +25 -2
- data/lib/capybara/email/rspec.rb +2 -3
- data/lib/capybara/email/version.rb +1 -1
- data/lib/capybara/node/email.rb +13 -0
- metadata +16 -34
- data/.gitignore +0 -18
- data/.rspec +0 -1
- data/Gemfile +0 -4
- data/Rakefile +0 -2
- data/capybara-email.gemspec +0 -24
- data/spec/email/driver_spec.rb +0 -86
- data/spec/node/email_spec.rb +0 -73
- data/spec/spec_helper.rb +0 -14
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# CapybaraEmail #
|
2
2
|
|
3
|
-
|
3
|
+
[](http://travis-ci.org/dockyard/capybara-email)
|
4
|
+
|
5
|
+
Easily test [ActionMailer](https://github.com/rails/rails/tree/master/actionmailer) and [Mail](https://github.com/mikel/mail) messages in your Capybara integration tests
|
4
6
|
|
5
7
|
## Installation ##
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'capybara-email'
|
13
|
+
```
|
10
14
|
|
11
15
|
And then execute:
|
12
16
|
|
@@ -18,16 +22,20 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
## Usage ##
|
20
24
|
|
21
|
-
|
22
|
-
|
25
|
+
### RSpec ###
|
26
|
+
|
27
|
+
Require `capybara/email/rspec` in your `spec_helper`
|
23
28
|
|
29
|
+
Example:
|
30
|
+
|
31
|
+
```ruby
|
24
32
|
feature 'Emailer' do
|
25
33
|
background do
|
26
|
-
# will clear the
|
34
|
+
# will clear the message queue
|
27
35
|
clear_emails
|
28
36
|
visit email_trigger_path
|
29
37
|
# Will find an email sent to test@example.com
|
30
|
-
# and set
|
38
|
+
# and set `current_email`
|
31
39
|
open_email('test@example.com')
|
32
40
|
end
|
33
41
|
|
@@ -39,6 +47,51 @@ feature 'Emailer' do
|
|
39
47
|
scenario 'testing for content' do
|
40
48
|
current_email.should have_content 'Hello Joe!'
|
41
49
|
end
|
50
|
+
|
51
|
+
scenario 'view the email body in your browser' do
|
52
|
+
# the `launchy` gem is required
|
53
|
+
current_email.save_and_open
|
54
|
+
end
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
### Test::Unit ###
|
59
|
+
|
60
|
+
Include `Capybara::Email::DSL` in your test class
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class ActionController::IntegrationTest
|
64
|
+
include Capybara::Email::DSL
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Example:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
class EmailTriggerControllerTest < ActionController::IntegrationTest
|
72
|
+
def setup
|
73
|
+
# will clear the message queue
|
74
|
+
clear_emails
|
75
|
+
visit email_trigger_path
|
76
|
+
|
77
|
+
# Will find an email sent to `test@example.com`
|
78
|
+
# and set `current_email`
|
79
|
+
open_email('test@example.com')
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'following a link' do
|
83
|
+
current_email.click_link 'your profile'
|
84
|
+
page.should have_content 'Profile page'
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'testing for content' do
|
88
|
+
current_email.should have_content 'Hello Joe!'
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'view the email body in your browser' do
|
92
|
+
# the `launchy` gem is required
|
93
|
+
current_email.save_and_open
|
94
|
+
end
|
42
95
|
end
|
43
96
|
```
|
44
97
|
|
data/lib/capybara-email.rb
CHANGED
data/lib/capybara/email.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
-
module Capybara::Email::
|
2
|
-
attr_accessor :current_email, :current_emails
|
1
|
+
module Capybara::Email::DSL
|
3
2
|
|
3
|
+
# Returns the currently set email.
|
4
|
+
# If no email set will return nil.
|
5
|
+
#
|
6
|
+
# @return [Mail::Message, nil]
|
7
|
+
attr_accessor :current_email
|
8
|
+
attr_accessor :current_emails
|
9
|
+
|
10
|
+
# Access all emails
|
11
|
+
#
|
12
|
+
# @return [Array]
|
4
13
|
def all_emails
|
5
14
|
Mail::TestMailer.deliveries
|
6
15
|
end
|
7
16
|
|
17
|
+
# Access all emails for a recipient.
|
18
|
+
#
|
19
|
+
# @param [String]
|
20
|
+
#
|
21
|
+
# @return [Array<Mail::Message>]
|
8
22
|
def emails_sent_to(recipient)
|
9
23
|
self.current_emails = all_emails.select { |email| email.to.include?(recipient) }.map do |email|
|
10
24
|
driver = Capybara::Email::Driver.new(email)
|
@@ -12,15 +26,24 @@ module Capybara::Email::RSpecHelpers
|
|
12
26
|
end
|
13
27
|
end
|
14
28
|
|
29
|
+
# Access the first email for a recipient and set it to.
|
30
|
+
#
|
31
|
+
# @param [String]
|
32
|
+
#
|
33
|
+
# @return [Mail::Message]
|
15
34
|
def first_email_sent_to(recipient)
|
16
35
|
self.current_email = emails_sent_to(recipient).first
|
17
36
|
end
|
18
37
|
alias :open_email :first_email_sent_to
|
19
38
|
|
39
|
+
# Returns a collection of all current emails retrieved
|
40
|
+
#
|
41
|
+
# @return [Array<Mail::Message>]
|
20
42
|
def current_emails
|
21
43
|
@current_emails || []
|
22
44
|
end
|
23
45
|
|
46
|
+
# Clear the email queue
|
24
47
|
def clear_emails
|
25
48
|
all_emails.clear
|
26
49
|
self.current_emails = nil
|
data/lib/capybara/email/rspec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'capybara/email'
|
2
|
-
require 'capybara/email/rspec/helpers'
|
3
2
|
|
4
3
|
RSpec.configure do |config|
|
5
|
-
config.include Capybara::Email::
|
6
|
-
config.include Capybara::Email::
|
4
|
+
config.include Capybara::Email::DSL, :type => :request
|
5
|
+
config.include Capybara::Email::DSL, :type => :acceptance
|
7
6
|
end
|
data/lib/capybara/node/email.rb
CHANGED
@@ -1,21 +1,34 @@
|
|
1
1
|
class Capybara::Node::Email < Capybara::Node::Document
|
2
2
|
|
3
|
+
# Delgate to the email body
|
4
|
+
#
|
5
|
+
# @return [Mail::Message#body]
|
3
6
|
def body
|
4
7
|
base.raw
|
5
8
|
end
|
6
9
|
|
10
|
+
# Delgate to the email subject
|
11
|
+
#
|
12
|
+
# @return [Mail::Message#subject]
|
7
13
|
def subject
|
8
14
|
base.subject
|
9
15
|
end
|
10
16
|
|
17
|
+
# Delgate to the email to
|
18
|
+
#
|
19
|
+
# @return [Mail::Message#to]
|
11
20
|
def to
|
12
21
|
base.to
|
13
22
|
end
|
14
23
|
|
24
|
+
# Delgate to the email from
|
25
|
+
#
|
26
|
+
# @return [Mail::Message#from]
|
15
27
|
def from
|
16
28
|
base.from
|
17
29
|
end
|
18
30
|
|
31
|
+
# Will open the email body in your browser
|
19
32
|
def save_and_open
|
20
33
|
require 'capybara/util/save_and_open_page'
|
21
34
|
::Capybara.save_and_open_page(body)
|
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.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mail
|
16
|
-
requirement: &
|
16
|
+
requirement: &70105786630540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70105786630540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: actionmailer
|
27
|
-
requirement: &
|
27
|
+
requirement: &70105786630120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,21 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: sinatra
|
38
|
-
requirement: &70133949376380 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70133949376380
|
35
|
+
version_requirements: *70105786630120
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: capybara
|
49
|
-
requirement: &
|
38
|
+
requirement: &70105786629700 !ruby/object:Gem::Requirement
|
50
39
|
none: false
|
51
40
|
requirements:
|
52
41
|
- - ! '>='
|
@@ -54,10 +43,10 @@ dependencies:
|
|
54
43
|
version: '0'
|
55
44
|
type: :development
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *70105786629700
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
48
|
name: bourne
|
60
|
-
requirement: &
|
49
|
+
requirement: &70105774149520 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
52
|
- - ! '>='
|
@@ -65,10 +54,10 @@ dependencies:
|
|
65
54
|
version: '0'
|
66
55
|
type: :development
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *70105774149520
|
69
58
|
- !ruby/object:Gem::Dependency
|
70
59
|
name: rspec
|
71
|
-
requirement: &
|
60
|
+
requirement: &70105774149100 !ruby/object:Gem::Requirement
|
72
61
|
none: false
|
73
62
|
requirements:
|
74
63
|
- - ! '>='
|
@@ -76,8 +65,8 @@ dependencies:
|
|
76
65
|
version: '0'
|
77
66
|
type: :development
|
78
67
|
prerelease: false
|
79
|
-
version_requirements: *
|
80
|
-
description: Test your ActionMailer
|
68
|
+
version_requirements: *70105774149100
|
69
|
+
description: Test your ActionMailer and Mailer messages in Capybara
|
81
70
|
email:
|
82
71
|
- bcardarella@gmail.com
|
83
72
|
- brian@dockyard.com
|
@@ -85,24 +74,16 @@ executables: []
|
|
85
74
|
extensions: []
|
86
75
|
extra_rdoc_files: []
|
87
76
|
files:
|
88
|
-
- .gitignore
|
89
|
-
- .rspec
|
90
|
-
- Gemfile
|
91
77
|
- LICENSE
|
92
78
|
- README.md
|
93
|
-
- Rakefile
|
94
|
-
- capybara-email.gemspec
|
95
79
|
- lib/capybara-email.rb
|
96
80
|
- lib/capybara/email.rb
|
97
81
|
- lib/capybara/email/driver.rb
|
82
|
+
- lib/capybara/email/dsl.rb
|
98
83
|
- lib/capybara/email/node.rb
|
99
84
|
- lib/capybara/email/rspec.rb
|
100
|
-
- lib/capybara/email/rspec/helpers.rb
|
101
85
|
- lib/capybara/email/version.rb
|
102
86
|
- lib/capybara/node/email.rb
|
103
|
-
- spec/email/driver_spec.rb
|
104
|
-
- spec/node/email_spec.rb
|
105
|
-
- spec/spec_helper.rb
|
106
87
|
homepage: https://github.com/dockyard/capybara-email
|
107
88
|
licenses: []
|
108
89
|
post_install_message:
|
@@ -126,5 +107,6 @@ rubyforge_project:
|
|
126
107
|
rubygems_version: 1.8.15
|
127
108
|
signing_key:
|
128
109
|
specification_version: 3
|
129
|
-
summary: Test your ActionMailer
|
110
|
+
summary: Test your ActionMailer and Mailer messages in Capybara
|
130
111
|
test_files: []
|
112
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/capybara-email.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/capybara/email/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ['Brian Cardarella']
|
6
|
-
gem.email = ['bcardarella@gmail.com', 'brian@dockyard.com']
|
7
|
-
gem.description = %q{Test your ActionMailer emails in Capybara}
|
8
|
-
gem.summary = %q{Test your ActionMailer emails in Capybara}
|
9
|
-
gem.homepage = 'https://github.com/dockyard/capybara-email'
|
10
|
-
|
11
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
gem.files = `git ls-files`.split("\n")
|
13
|
-
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
-
gem.name = 'capybara-email'
|
15
|
-
gem.require_paths = ['lib']
|
16
|
-
gem.version = Capybara::Email::VERSION
|
17
|
-
|
18
|
-
gem.add_development_dependency 'mail'
|
19
|
-
gem.add_development_dependency 'actionmailer'
|
20
|
-
gem.add_development_dependency 'sinatra'
|
21
|
-
gem.add_development_dependency 'capybara'
|
22
|
-
gem.add_development_dependency 'bourne'
|
23
|
-
gem.add_development_dependency 'rspec'
|
24
|
-
end
|
data/spec/email/driver_spec.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class TestApp
|
4
|
-
def self.call(env)
|
5
|
-
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
feature 'Integration test' do
|
10
|
-
background do
|
11
|
-
clear_email
|
12
|
-
Capybara.app = ::TestApp
|
13
|
-
end
|
14
|
-
|
15
|
-
scenario 'html email' do
|
16
|
-
email = deliver(html_email)
|
17
|
-
|
18
|
-
open_email('test@example.com')
|
19
|
-
current_email.click_link 'example'
|
20
|
-
page.should have_content 'Hello world!'
|
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
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
scenario 'plain text email' do
|
31
|
-
email = deliver(plain_email)
|
32
|
-
|
33
|
-
open_email('test@example.com')
|
34
|
-
current_email.click_link 'http://example.com'
|
35
|
-
page.should have_content 'Hello world!'
|
36
|
-
current_email.should have_content 'This is only a plain test.'
|
37
|
-
|
38
|
-
all_emails.first.should == email
|
39
|
-
|
40
|
-
clear_emails()
|
41
|
-
all_emails.should be_empty
|
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
|
61
|
-
end
|
62
|
-
|
63
|
-
def deliver(email)
|
64
|
-
ActionMailer::Base.deliveries << email
|
65
|
-
email
|
66
|
-
end
|
67
|
-
|
68
|
-
def html_email
|
69
|
-
Mail::Message.new(:body => <<-HTML, :content_type => 'text/html', :to => 'test@example.com')
|
70
|
-
<html>
|
71
|
-
<body>
|
72
|
-
<p>
|
73
|
-
This is only a html test.
|
74
|
-
<a href="http://example.com">example</a>
|
75
|
-
</p>
|
76
|
-
</body>
|
77
|
-
</html>
|
78
|
-
HTML
|
79
|
-
end
|
80
|
-
|
81
|
-
def plain_email
|
82
|
-
Mail::Message.new(:body => <<-PLAIN, :content_type => 'text/plain', :to => 'test@example.com')
|
83
|
-
This is only a plain test.
|
84
|
-
http://example.com
|
85
|
-
PLAIN
|
86
|
-
end
|
data/spec/node/email_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
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
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'mail'
|
3
|
-
require 'bourne'
|
4
|
-
require 'action_mailer'
|
5
|
-
require 'capybara/rspec'
|
6
|
-
require 'capybara/email/rspec'
|
7
|
-
|
8
|
-
Mail.defaults do
|
9
|
-
delivery_method :test
|
10
|
-
end
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.mock_with :mocha
|
14
|
-
end
|