capybara-email 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-email.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Brian Cardarella
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Capybara::Email
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capybara-email'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capybara-email
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
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 'actionmailer'
19
+ gem.add_development_dependency 'capybara'
20
+ gem.add_development_dependency 'rspec'
21
+ end
@@ -0,0 +1,6 @@
1
+ require 'capybara/email/version'
2
+
3
+ module Capybara
4
+ module Email
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Capybara::Email
2
+ autoload :Node, 'capybara/email/node'
3
+ autoload :Driver, 'capybara/email/driver'
4
+ autoload :Version, 'capybara/email/version'
5
+ end
6
+
@@ -0,0 +1,41 @@
1
+ class Capybara::Email::Driver < Capybara::Driver::Base
2
+ attr_reader :email
3
+
4
+ def initialize(email)
5
+ @email = email
6
+ end
7
+
8
+ def follow(method, path, attributes = {})
9
+ Capybara.current_session.driver.follow(method, path, attributes)
10
+ end
11
+
12
+ def body
13
+ dom.to_xml
14
+ end
15
+
16
+ def dom
17
+ @dom ||= Nokogiri::HTML(source)
18
+ end
19
+
20
+ def find(selector)
21
+ dom.xpath(selector).map { |node| Capybara::Email::Node.new(self, node) }
22
+ end
23
+
24
+ def source
25
+ if email.mime_type == 'text/plain'
26
+ convert_to_html(email.body.encoded)
27
+ else
28
+ email.body.encoded
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def convert_to_html(text)
35
+ "<html><body>#{convert_links(text)}</body></html>"
36
+ end
37
+
38
+ def convert_links(text)
39
+ text.gsub(%r{(https?://\S+)}, %q{<a href="\1">\1</a>})
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ class Capybara::Email::Node < Capybara::Driver::Node
2
+ def text
3
+ native.text
4
+ end
5
+
6
+ def [](name)
7
+ string_node[name]
8
+ end
9
+
10
+ def value
11
+ string_node.value
12
+ end
13
+
14
+ def click
15
+ driver.follow(:get, self[:href].to_s)
16
+ end
17
+
18
+ def tag_name
19
+ native.node_name
20
+ end
21
+
22
+ def visible?
23
+ string_node.visible?
24
+ end
25
+
26
+ def find(locator)
27
+ native.xpath(locator).map { |node| self.class.new(driver, node) }
28
+ end
29
+
30
+ private
31
+
32
+ def string_node
33
+ @string_node ||= Capybara::Node::Simple.new(native)
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ require 'capybara/email'
2
+ require 'capybara/email/rspec/helpers'
3
+
4
+ RSpec.configure do |config|
5
+ config.include Capybara::Email::RSpecHelpers, :type => :request
6
+ config.include Capybara::Email::RSpecHelpers, :type => :acceptance
7
+ end
@@ -0,0 +1,30 @@
1
+ module Capybara::Email::RSpecHelpers
2
+ attr_accessor :current_email, :current_emails
3
+
4
+ def all_emails
5
+ ActionMailer::Base.deliveries
6
+ end
7
+
8
+ def emails_sent_to(recipient)
9
+ self.current_emails = all_emails.select { |email| email.to.include?(recipient) }.map do |email|
10
+ driver = Capybara::Email::Driver.new(email)
11
+ Capybara::Node::Document.new(Capybara.current_session, driver)
12
+ end
13
+ end
14
+
15
+ def first_email_sent_to(recipient)
16
+ self.current_email = emails_sent_to(recipient).first
17
+ end
18
+ alias :open_email :first_email_sent_to
19
+
20
+ def current_emails
21
+ @current_emails || []
22
+ end
23
+
24
+ def clear_emails
25
+ all_emails.clear
26
+ self.current_emails = nil
27
+ self.current_email = nil
28
+ end
29
+ alias :clear_email :clear_emails
30
+ end
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ module Email
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Integration test' do
4
+ background do
5
+ clear_email
6
+ Capybara.app = TestApp
7
+ end
8
+
9
+ scenario 'html email' do
10
+ deliver(html_email)
11
+ open_email('test@example.com')
12
+ current_email.click_link 'example'
13
+ page.should have_content 'Hello world!'
14
+ current_email.should have_content 'This is only a html test'
15
+ end
16
+
17
+ scenario 'plain text email' do
18
+ deliver(plain_email)
19
+ open_email('test@example.com')
20
+ current_email.click_link 'http://example.com'
21
+ page.should have_content 'Hello world!'
22
+ current_email.should have_content 'This is only a plain test.'
23
+ end
24
+ end
25
+
26
+ class TestApp
27
+ def self.call(env)
28
+ [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
29
+ end
30
+ end
31
+
32
+ def deliver(email)
33
+ ActionMailer::Base.deliveries << email
34
+ end
35
+
36
+ def html_email
37
+ Mail::Message.new(:body => <<-HTML, :content_type => 'text/html', :to => 'test@example.com')
38
+ <html>
39
+ <body>
40
+ <p>
41
+ This is only a html test.
42
+ <a href="http://example.com">example</a>
43
+ </p>
44
+ </body>
45
+ </html>
46
+ HTML
47
+ end
48
+
49
+ def plain_email
50
+ Mail::Message.new(:body => <<-PLAIN, :content_type => 'text/plain', :to => 'test@example.com')
51
+ This is only a plain test.
52
+ http://example.com
53
+ PLAIN
54
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require 'action_mailer'
3
+ require 'capybara/rspec'
4
+ require 'capybara/email/rspec'
5
+ require 'capybara/spec/driver'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-email
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Cardarella
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionmailer
16
+ requirement: &70167839111240 !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: *70167839111240
25
+ - !ruby/object:Gem::Dependency
26
+ name: capybara
27
+ requirement: &70167839110820 !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: *70167839110820
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70167839110400 !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: *70167839110400
47
+ description: Test your ActionMailer emails in Capybara
48
+ email:
49
+ - bcardarella@gmail.com
50
+ - brian@dockyard.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - capybara-email.gemspec
62
+ - lib/capybara-email.rb
63
+ - lib/capybara/email.rb
64
+ - lib/capybara/email/driver.rb
65
+ - lib/capybara/email/node.rb
66
+ - lib/capybara/email/rspec.rb
67
+ - lib/capybara/email/rspec/helpers.rb
68
+ - lib/capybara/email/version.rb
69
+ - spec/email/driver_spec.rb
70
+ - spec/email/node_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: https://github.com/dockyard/capybara-email
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.15
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Test your ActionMailer emails in Capybara
96
+ test_files: []