email_spec 1.6.0 → 2.0.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.
- checksums.yaml +7 -0
- data/History.txt +18 -0
- data/README.md +30 -28
- data/examples/rails4_root/Gemfile +19 -0
- data/examples/rails4_root/Gemfile.lock +180 -0
- data/examples/rails4_root/README +5 -0
- data/examples/rails4_root/Rakefile +11 -0
- data/examples/rails4_root/app/controllers/application_controller.rb +3 -0
- data/examples/rails4_root/app/controllers/welcome_controller.rb +18 -0
- data/examples/rails4_root/app/helpers/application_helper.rb +2 -0
- data/examples/rails4_root/app/mailers/user_mailer.rb +39 -0
- data/examples/rails4_root/app/models/user.rb +2 -0
- data/examples/rails4_root/app/views/user_mailer/email_with_attachment.html.erb +6 -0
- data/examples/rails4_root/app/views/user_mailer/newsletter.html.erb +8 -0
- data/examples/rails4_root/app/views/user_mailer/signup.html.erb +4 -0
- data/examples/rails4_root/app/views/user_mailer/signup.text.erb +4 -0
- data/examples/rails4_root/app/views/welcome/attachments.html.erb +0 -0
- data/examples/rails4_root/app/views/welcome/confirm.html.erb +1 -0
- data/examples/rails4_root/app/views/welcome/index.html.erb +8 -0
- data/examples/rails4_root/app/views/welcome/newsletter.html.erb +0 -0
- data/examples/rails4_root/app/views/welcome/signup.html.erb +1 -0
- data/examples/rails4_root/attachments/document.pdf +0 -0
- data/examples/rails4_root/attachments/image.png +0 -0
- data/examples/rails4_root/config.ru +4 -0
- data/examples/rails4_root/config/application.rb +45 -0
- data/examples/rails4_root/config/boot.rb +14 -0
- data/examples/rails4_root/config/cucumber.yml +8 -0
- data/examples/rails4_root/config/database.yml +25 -0
- data/examples/rails4_root/config/environment.rb +6 -0
- data/examples/rails4_root/config/environments/development.rb +19 -0
- data/examples/rails4_root/config/environments/production.rb +42 -0
- data/examples/rails4_root/config/environments/test.rb +32 -0
- data/examples/rails4_root/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails4_root/config/initializers/cookie_verification_secret.rb +7 -0
- data/examples/rails4_root/config/initializers/delayed_job.rb +1 -0
- data/examples/rails4_root/config/initializers/inflections.rb +10 -0
- data/examples/rails4_root/config/initializers/mime_types.rb +5 -0
- data/examples/rails4_root/config/initializers/notifier_job.rb +1 -0
- data/examples/rails4_root/config/initializers/rspec_generator.rb +6 -0
- data/examples/rails4_root/config/initializers/session_store.rb +10 -0
- data/examples/rails4_root/config/locales/en.yml +5 -0
- data/examples/rails4_root/config/routes.rb +7 -0
- data/examples/rails4_root/config/secrets.yml +22 -0
- data/examples/rails4_root/db/migrate/20090125013728_create_users.rb +11 -0
- data/examples/rails4_root/db/migrate/20090908054656_create_delayed_jobs.rb +20 -0
- data/examples/rails4_root/db/migrate/20141119224309_add_queue_to_delayed_jobs.rb +9 -0
- data/examples/rails4_root/db/schema.rb +35 -0
- data/examples/rails4_root/db/seeds.rb +7 -0
- data/examples/rails4_root/db/test.sqlite3 +0 -0
- data/examples/rails4_root/doc/README_FOR_APP +2 -0
- data/examples/rails4_root/features/attachments.feature +27 -0
- data/examples/rails4_root/features/delayed_job.feature +13 -0
- data/examples/rails4_root/features/errors.feature +40 -0
- data/examples/rails4_root/features/example.feature +93 -0
- data/examples/rails4_root/features/step_definitions/email_steps.rb +210 -0
- data/examples/rails4_root/features/step_definitions/user_steps.rb +26 -0
- data/examples/rails4_root/features/step_definitions/web_steps.rb +219 -0
- data/examples/rails4_root/features/support/env.rb +59 -0
- data/examples/rails4_root/features/support/env_ext.rb +4 -0
- data/examples/rails4_root/features/support/paths.rb +33 -0
- data/examples/rails4_root/lib/notifier_job.rb +5 -0
- data/examples/rails4_root/lib/tasks/cucumber.rake +65 -0
- data/examples/rails4_root/lib/tasks/rspec.rake +69 -0
- data/examples/rails4_root/log/development.log +0 -0
- data/examples/rails4_root/log/test.log +43813 -0
- data/examples/rails4_root/public/404.html +26 -0
- data/examples/rails4_root/public/422.html +26 -0
- data/examples/rails4_root/public/500.html +26 -0
- data/examples/rails4_root/public/favicon.ico +0 -0
- data/examples/rails4_root/public/images/rails.png +0 -0
- data/examples/rails4_root/public/javascripts/application.js +2 -0
- data/examples/rails4_root/public/javascripts/controls.js +965 -0
- data/examples/rails4_root/public/javascripts/dragdrop.js +974 -0
- data/examples/rails4_root/public/javascripts/effects.js +1123 -0
- data/examples/rails4_root/public/javascripts/prototype.js +4874 -0
- data/examples/rails4_root/public/javascripts/rails.js +109 -0
- data/examples/rails4_root/public/robots.txt +5 -0
- data/examples/rails4_root/script/cucumber +10 -0
- data/examples/rails4_root/script/delayed_job +5 -0
- data/examples/rails4_root/script/rails +9 -0
- data/examples/rails4_root/spec/controllers/welcome_controller_spec.rb +20 -0
- data/examples/rails4_root/spec/models/user_mailer_spec.rb +47 -0
- data/examples/rails4_root/spec/spec_helper.rb +20 -0
- data/examples/rails4_root/test/mailers/user_mailer_classic_test.rb +27 -0
- data/examples/rails4_root/test/mailers/user_mailer_spec_test.rb +29 -0
- data/examples/rails4_root/test/test_helper.rb +10 -0
- data/{rails_generators → examples/rails4_root/vendor/plugins/email_spec/rails_generators}/email_spec/email_spec_generator.rb +0 -0
- data/{rails_generators → examples/rails4_root/vendor/plugins/email_spec/rails_generators}/email_spec/templates/email_steps.rb +22 -18
- data/examples/sinatra_root/Gemfile +15 -0
- data/examples/sinatra_root/Gemfile.lock +95 -0
- data/examples/sinatra_root/config.ru +4 -0
- data/examples/sinatra_root/features/errors.feature +40 -0
- data/examples/sinatra_root/features/example.feature +93 -0
- data/examples/sinatra_root/features/step_definitions/email_steps.rb +210 -0
- data/examples/sinatra_root/features/step_definitions/user_steps.rb +26 -0
- data/examples/sinatra_root/features/step_definitions/web_steps.rb +219 -0
- data/examples/sinatra_root/features/support/env.rb +21 -0
- data/examples/sinatra_root/features/support/paths.rb +29 -0
- data/examples/sinatra_root/lib/example_sinatra_app.rb +45 -0
- data/features/rails4_app.feature +32 -0
- data/features/sinatra_app.feature +14 -0
- data/features/step_definitions/app_steps.rb +58 -0
- data/features/support/env.rb +16 -0
- data/lib/email_spec.rb +1 -1
- data/lib/email_spec/deliveries.rb +0 -1
- data/lib/email_spec/email_viewer.rb +1 -1
- data/lib/email_spec/helpers.rb +16 -5
- data/lib/email_spec/matchers.rb +2 -1
- data/lib/email_spec/version.rb +3 -0
- data/lib/generators/email_spec/steps/templates/email_steps.rb +24 -20
- data/spec/email_spec/email_viewer_spec.rb +20 -0
- data/spec/email_spec/helpers_spec.rb +316 -0
- data/spec/email_spec/mail_ext_spec.rb +34 -0
- data/spec/email_spec/matchers_spec.rb +513 -0
- data/spec/spec_helper.rb +24 -0
- metadata +161 -150
- data/lib/email_spec/background_processes.rb +0 -45
- data/lib/generators/email_spec/steps/USAGE +0 -5
@@ -0,0 +1,21 @@
|
|
1
|
+
# Generated by cucumber-sinatra. (Tue Jul 27 10:45:23 -0400 2010)
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib/example_sinatra_app.rb')
|
4
|
+
require 'capybara'
|
5
|
+
require 'capybara/cucumber'
|
6
|
+
require 'rspec/core'
|
7
|
+
#require 'activesupport'
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../../../lib/email_spec')
|
9
|
+
require 'email_spec/cucumber'
|
10
|
+
|
11
|
+
ExampleSinatraApp.set(:environment, :test)
|
12
|
+
|
13
|
+
Capybara.app = ExampleSinatraApp
|
14
|
+
|
15
|
+
class ExampleSinatraAppWorld
|
16
|
+
include Capybara::DSL
|
17
|
+
end
|
18
|
+
|
19
|
+
World do
|
20
|
+
ExampleSinatraAppWorld.new
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Taken from the cucumber-rails project.
|
2
|
+
|
3
|
+
module NavigationHelpers
|
4
|
+
# Maps a name to a path. Used by the
|
5
|
+
#
|
6
|
+
# When /^I go to (.+)$/ do |page_name|
|
7
|
+
#
|
8
|
+
# step definition in web_steps.rb
|
9
|
+
#
|
10
|
+
def path_to(page_name)
|
11
|
+
case page_name
|
12
|
+
|
13
|
+
when /the home\s?page/
|
14
|
+
'/'
|
15
|
+
|
16
|
+
# Add more mappings here.
|
17
|
+
# Here is an example that pulls values out of the Regexp:
|
18
|
+
#
|
19
|
+
# when /^(.*)'s profile page$/i
|
20
|
+
# user_profile_path(User.find_by_login($1))
|
21
|
+
|
22
|
+
else
|
23
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
24
|
+
"Now, go and add a mapping in #{__FILE__}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
World(NavigationHelpers)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'pony'
|
3
|
+
|
4
|
+
class ExampleSinatraApp < Sinatra::Base
|
5
|
+
get '/' do
|
6
|
+
<<-EOHTML
|
7
|
+
<form method="post" action="/signup">
|
8
|
+
<label for="Name">Name</label>
|
9
|
+
<input type="text" id="Name" name="user[name]">
|
10
|
+
<label for="Email">Email</label>
|
11
|
+
<input type="text" id="Email" name="user[email]">
|
12
|
+
<input type="submit" value="Sign up">
|
13
|
+
</form>
|
14
|
+
EOHTML
|
15
|
+
end
|
16
|
+
|
17
|
+
post '/signup' do
|
18
|
+
user = params[:user]
|
19
|
+
body = <<-EOTEXT
|
20
|
+
Hello #{user['name']}!
|
21
|
+
|
22
|
+
Copy and paste this URL into your browser to confirm your account!
|
23
|
+
|
24
|
+
http://www.example.com/confirm
|
25
|
+
This is the text part.
|
26
|
+
EOTEXT
|
27
|
+
html_body = <<-EOHTML
|
28
|
+
Hello #{user['name']}!
|
29
|
+
|
30
|
+
<a href="http://www.example.com/confirm">Click here to confirm your account!</a>
|
31
|
+
This is the HTML part.
|
32
|
+
EOHTML
|
33
|
+
Pony.mail(:from => 'admin@example.com',
|
34
|
+
:to => user['email'],
|
35
|
+
:subject => 'Account confirmation',
|
36
|
+
:body => body,
|
37
|
+
:html_body => html_body
|
38
|
+
)
|
39
|
+
'Thanks! Go check your email!'
|
40
|
+
end
|
41
|
+
|
42
|
+
get '/confirm' do
|
43
|
+
'Confirm your new account!'
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: Email Spec in Rails 4 App
|
2
|
+
|
3
|
+
In order to prevent me from shipping a defective email_spec gem
|
4
|
+
As a email_spec dev
|
5
|
+
I want to verify that the example rails 4 app runs all of it's features as expected
|
6
|
+
|
7
|
+
Scenario: generators test
|
8
|
+
Given the rails4 app is setup with the latest generators
|
9
|
+
When I run "bundle exec rails g email_spec:steps" in the rails4 app
|
10
|
+
Then the rails4 app should have the email steps in place
|
11
|
+
|
12
|
+
Scenario: regression test
|
13
|
+
Given the rails4 app is setup with the latest email steps
|
14
|
+
When I run "bundle exec rake db:migrate RAILS_ENV=test" in the rails4 app
|
15
|
+
And I run "bundle exec cucumber features -q --no-color" in the rails4 app
|
16
|
+
Then I should see the following summary report:
|
17
|
+
"""
|
18
|
+
15 scenarios (7 failed, 8 passed)
|
19
|
+
136 steps (7 failed, 1 skipped, 128 passed)
|
20
|
+
"""
|
21
|
+
|
22
|
+
When I run "bundle exec rake spec RAILS_ENV=test" in the rails4 app
|
23
|
+
Then I should see the following summary report:
|
24
|
+
"""
|
25
|
+
9 examples, 0 failures
|
26
|
+
"""
|
27
|
+
|
28
|
+
When I run "bundle exec rake test RAILS_ENV=test" in the rails4 app
|
29
|
+
Then I should see the following summary report:
|
30
|
+
"""
|
31
|
+
8 runs, 8 assertions, 0 failures, 0 errors, 0 skips
|
32
|
+
"""
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Email Spec in Sinatra App
|
2
|
+
|
3
|
+
In order to prevent me from shipping a defective email_spec gem
|
4
|
+
As a email_spec dev
|
5
|
+
I want to verify that the example sinatra app runs all of it's features as expected
|
6
|
+
|
7
|
+
Scenario: regression test
|
8
|
+
Given the sinatra app is setup with the latest email steps
|
9
|
+
When I run "bundle exec cucumber features -q --no-color" in the sinatra app
|
10
|
+
Then I should see the following summary report:
|
11
|
+
"""
|
12
|
+
12 scenarios (7 failed, 5 passed)
|
13
|
+
110 steps (7 failed, 1 skipped, 102 passed)
|
14
|
+
"""
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
Given /^the (\w+) app is setup with the latest email steps$/ do |app_name|
|
4
|
+
app_dir = File.join(root_dir, 'examples',"#{app_name}_root")
|
5
|
+
email_specs_path = File.join(app_dir, 'features', 'step_definitions',
|
6
|
+
'email_steps.rb')
|
7
|
+
latest_specs_path = File.join(root_dir, 'lib', 'generators', 'email_spec',
|
8
|
+
'steps', 'templates','email_steps.rb')
|
9
|
+
FileUtils.rm(email_specs_path) if File.exists?(email_specs_path)
|
10
|
+
FileUtils.cp_r(latest_specs_path, email_specs_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^the (\w+) app should have the email steps in place$/ do |app_name|
|
14
|
+
email_specs_path = "#{root_dir}/examples/#{app_name}_root/features/step_definitions/email_steps.rb"
|
15
|
+
expect(File.exists?(email_specs_path)).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^I should see the following summary report:$/ do |expected_report|
|
19
|
+
expect(@output).to include(expected_report)
|
20
|
+
end
|
21
|
+
|
22
|
+
Given /^the (\w+) app is setup with the latest generators$/ do |app_name|
|
23
|
+
app_dir= File.join(root_dir,'examples',"#{app_name}_root")
|
24
|
+
email_specs_path = File.join(app_dir,'features','step_definitions','email_steps.rb')
|
25
|
+
FileUtils.rm(email_specs_path) if File.exists?(email_specs_path)
|
26
|
+
|
27
|
+
if app_name == 'rails4'
|
28
|
+
#Testing using the gem
|
29
|
+
#make sure we are listed in the bundle
|
30
|
+
Dir.chdir(app_dir) do
|
31
|
+
output =`bundle list`
|
32
|
+
expect(output).to include('email_spec')
|
33
|
+
end
|
34
|
+
else
|
35
|
+
FileUtils.mkdir_p("#{app_dir}/vendor/plugins/email_spec")
|
36
|
+
FileUtils.cp_r("#{root_dir}/rails_generators","#{app_dir}/vendor/plugins/email_spec/")
|
37
|
+
Dir.chdir(app_dir) do
|
38
|
+
system "ruby ./script/generate email_spec"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
When /^I run "([^\"]*)" in the (\w+) app$/ do |cmd, app_name|
|
44
|
+
#cmd.gsub!('cucumber', "#{Cucumber::RUBY_BINARY} #{Cucumber::BINARY}")
|
45
|
+
app_path = File.join(root_dir, 'examples', "#{app_name}_root")
|
46
|
+
app_specific_gemfile = File.join(app_path,'Gemfile')
|
47
|
+
Dir.chdir(app_path) do
|
48
|
+
#hack to fight competing bundles (email specs vs rails4_root's
|
49
|
+
if File.exists? app_specific_gemfile
|
50
|
+
orig_gemfile = ENV['BUNDLE_GEMFILE']
|
51
|
+
ENV['BUNDLE_GEMFILE'] = app_specific_gemfile
|
52
|
+
@output = `#{cmd}`
|
53
|
+
ENV['BUNDLE_GEMFILE'] = orig_gemfile
|
54
|
+
else
|
55
|
+
@output = `#{cmd}`
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
#require 'spec/expectations'
|
3
|
+
|
4
|
+
class EmailSpecWorld
|
5
|
+
def self.root_dir
|
6
|
+
@root_dir ||= File.join(File.expand_path(File.dirname(__FILE__)), "..", "..")
|
7
|
+
end
|
8
|
+
|
9
|
+
def root_dir
|
10
|
+
EmailSpecWorld.root_dir
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
World do
|
15
|
+
EmailSpecWorld.new
|
16
|
+
end
|
data/lib/email_spec.rb
CHANGED
@@ -5,8 +5,8 @@ end
|
|
5
5
|
|
6
6
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
7
7
|
|
8
|
+
require 'htmlentities'
|
8
9
|
require 'mail'
|
9
|
-
require 'email_spec/background_processes'
|
10
10
|
require 'email_spec/deliveries'
|
11
11
|
require 'email_spec/address_converter'
|
12
12
|
require 'email_spec/email_viewer'
|
@@ -35,7 +35,7 @@ module EmailSpec
|
|
35
35
|
if m.multipart? && text_part = m.parts.detect{ |p| p.content_type.include?('text/plain') }
|
36
36
|
if m.respond_to?(:ordered_each) # Rails 2 / TMail
|
37
37
|
m.ordered_each{|k,v| f.write "#{k}: #{v}\n" }
|
38
|
-
else # Rails
|
38
|
+
else # Rails 4 / Mail
|
39
39
|
f.write(text_part.header.to_s + "\n")
|
40
40
|
end
|
41
41
|
|
data/lib/email_spec/helpers.rb
CHANGED
@@ -43,7 +43,12 @@ module EmailSpec
|
|
43
43
|
def current_email(address=nil)
|
44
44
|
address = convert_address(address)
|
45
45
|
email = address ? email_spec_hash[:current_emails][address] : email_spec_hash[:current_email]
|
46
|
-
|
46
|
+
exception_class = if defined?(RSpec)
|
47
|
+
RSpec::Expectations::ExpectationNotMetError
|
48
|
+
else
|
49
|
+
StandardError
|
50
|
+
end
|
51
|
+
raise exception_class, "Expected an open email but none was found. Did you forget to call open_email?" unless email
|
47
52
|
email
|
48
53
|
end
|
49
54
|
|
@@ -52,7 +57,8 @@ module EmailSpec
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def unread_emails_for(address)
|
55
|
-
|
60
|
+
read_message_ids = read_emails_for(address).map(&:message_id)
|
61
|
+
mailbox_for(address).reject { |m| read_message_ids.include?(m.message_id) }
|
56
62
|
end
|
57
63
|
|
58
64
|
def read_emails_for(address)
|
@@ -76,7 +82,8 @@ module EmailSpec
|
|
76
82
|
end
|
77
83
|
|
78
84
|
def links_in_email(email)
|
79
|
-
URI.extract(email.default_part_body.to_s, ['http', 'https'])
|
85
|
+
links = URI.extract(email.default_part_body.to_s, ['http', 'https'])
|
86
|
+
links.map{|url| HTMLEntities.new.decode(url) }.uniq
|
80
87
|
end
|
81
88
|
|
82
89
|
private
|
@@ -107,7 +114,11 @@ module EmailSpec
|
|
107
114
|
|
108
115
|
def parse_email_for_link(email, text_or_regex)
|
109
116
|
matcher = EmailSpec::Matchers::HaveBodyText.new(text_or_regex)
|
110
|
-
RSpec
|
117
|
+
if defined?(RSpec)
|
118
|
+
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(email, matcher)
|
119
|
+
else
|
120
|
+
assert_must matcher, email
|
121
|
+
end
|
111
122
|
|
112
123
|
url = parse_email_for_explicit_link(email, text_or_regex)
|
113
124
|
url ||= parse_email_for_anchor_text_link(email, text_or_regex)
|
@@ -131,7 +142,7 @@ module EmailSpec
|
|
131
142
|
|
132
143
|
# e.g. Click here in <a href="http://confirm">Click here</a>
|
133
144
|
def parse_email_for_anchor_text_link(email, link_text)
|
134
|
-
if textify_images(email.default_part_body) =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]
|
145
|
+
if textify_images(email.default_part_body) =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?(.*?)#{link_text}(.*?)[^<]*?</a>}
|
135
146
|
URI.split($1)[5..-1].compact!.join("?").gsub("&", "&")
|
136
147
|
# sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
|
137
148
|
else
|
data/lib/email_spec/matchers.rb
CHANGED
@@ -57,7 +57,8 @@ module EmailSpec
|
|
57
57
|
|
58
58
|
def matches?(email)
|
59
59
|
@email = email
|
60
|
-
|
60
|
+
recipients = email.header[:to] || email.header[:bcc]
|
61
|
+
@actual_recipients = address_array{ recipients && recipients.addrs }.map(&:to_s).sort
|
61
62
|
@actual_recipients == @expected_recipients
|
62
63
|
end
|
63
64
|
|
@@ -49,19 +49,19 @@ end
|
|
49
49
|
#
|
50
50
|
|
51
51
|
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
|
52
|
-
unread_emails_for(address).size.
|
52
|
+
expect(unread_emails_for(address).size).to eql parse_email_count(amount)
|
53
53
|
end
|
54
54
|
|
55
55
|
Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
|
56
|
-
mailbox_for(address).size.
|
56
|
+
expect(mailbox_for(address).size).to eql parse_email_count(amount)
|
57
57
|
end
|
58
58
|
|
59
59
|
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
|
60
|
-
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.
|
60
|
+
expect(unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size).to eql parse_email_count(amount)
|
61
61
|
end
|
62
62
|
|
63
63
|
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject|
|
64
|
-
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.
|
64
|
+
expect(unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size).to eql parse_email_count(amount)
|
65
65
|
end
|
66
66
|
|
67
67
|
Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
|
@@ -98,43 +98,47 @@ end
|
|
98
98
|
#
|
99
99
|
|
100
100
|
Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
|
101
|
-
current_email.
|
101
|
+
expect(current_email).to have_subject(text)
|
102
102
|
end
|
103
103
|
|
104
104
|
Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
|
105
|
-
current_email.
|
105
|
+
expect(current_email).to have_subject(Regexp.new(text))
|
106
106
|
end
|
107
107
|
|
108
108
|
Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
|
109
|
-
current_email.default_part_body.to_s.
|
109
|
+
expect(current_email.default_part_body.to_s).to include(text)
|
110
110
|
end
|
111
111
|
|
112
112
|
Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
|
113
|
-
current_email.default_part_body.to_s.
|
113
|
+
expect(current_email.default_part_body.to_s).to match Regexp.new(text)
|
114
114
|
end
|
115
115
|
|
116
116
|
Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
|
117
|
-
current_email.
|
117
|
+
expect(current_email).to be_delivered_from(text)
|
118
|
+
end
|
119
|
+
|
120
|
+
Then /^(?:I|they) should see the email reply to "([^"]*?)"$/ do |text|
|
121
|
+
expect(current_email).to have_reply_to(text)
|
118
122
|
end
|
119
123
|
|
120
124
|
Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
|
121
|
-
current_email.
|
125
|
+
expect(current_email).to have_header(name, text)
|
122
126
|
end
|
123
127
|
|
124
128
|
Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
|
125
|
-
current_email.
|
129
|
+
expect(current_email).to have_header(name, Regexp.new(text))
|
126
130
|
end
|
127
131
|
|
128
132
|
Then /^I should see it is a multi\-part email$/ do
|
129
|
-
current_email.
|
133
|
+
expect(current_email).to be_multipart
|
130
134
|
end
|
131
135
|
|
132
136
|
Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text|
|
133
|
-
current_email.html_part.body.to_s.
|
137
|
+
expect(current_email.html_part.body.to_s).to include(text)
|
134
138
|
end
|
135
139
|
|
136
140
|
Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text|
|
137
|
-
current_email.text_part.body.to_s.
|
141
|
+
expect(current_email.text_part.body.to_s).to include(text)
|
138
142
|
end
|
139
143
|
|
140
144
|
#
|
@@ -142,28 +146,28 @@ end
|
|
142
146
|
#
|
143
147
|
|
144
148
|
Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
|
145
|
-
current_email_attachments.size.
|
149
|
+
expect(current_email_attachments.size).to eql parse_email_count(amount)
|
146
150
|
end
|
147
151
|
|
148
152
|
Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
|
149
|
-
current_email_attachments.select { |a| a.filename == filename }.size.
|
153
|
+
expect(current_email_attachments.select { |a| a.filename == filename }.size).to eql parse_email_count(amount)
|
150
154
|
end
|
151
155
|
|
152
156
|
Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
|
153
|
-
current_email_attachments[(index.to_i - 1)].filename.
|
157
|
+
expect(current_email_attachments[(index.to_i - 1)].filename).to eql filename
|
154
158
|
end
|
155
159
|
|
156
160
|
Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
|
157
|
-
current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.
|
161
|
+
expect(current_email_attachments.select { |a| a.content_type.include?(content_type) }.size).to eql parse_email_count(amount)
|
158
162
|
end
|
159
163
|
|
160
164
|
Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
|
161
|
-
current_email_attachments[(index.to_i - 1)].content_type.
|
165
|
+
expect(current_email_attachments[(index.to_i - 1)].content_type).to include(content_type)
|
162
166
|
end
|
163
167
|
|
164
168
|
Then /^all attachments should not be blank$/ do
|
165
169
|
current_email_attachments.each do |attachment|
|
166
|
-
attachment.read.size.
|
170
|
+
expect(attachment.read.size).to_not eql 0
|
167
171
|
end
|
168
172
|
end
|
169
173
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'launchy'
|
3
|
+
|
4
|
+
describe EmailSpec::EmailViewer do
|
5
|
+
describe ".open_in_browser" do
|
6
|
+
it "should open with launchy" do
|
7
|
+
expected_uri = URI("file://#{File.expand_path("a_file")}")
|
8
|
+
expect(Launchy).to receive(:open).with(expected_uri)
|
9
|
+
EmailSpec::EmailViewer.open_in_browser("a_file")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".open_in_text_editor" do
|
14
|
+
it "should open with launchy" do
|
15
|
+
expected_uri = URI("file://#{File.expand_path("a_file")}")
|
16
|
+
expect(Launchy).to receive(:open).with(expected_uri, {application: :editor})
|
17
|
+
EmailSpec::EmailViewer.open_in_text_editor("a_file")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|