email_spec 1.6.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/History.txt +18 -0
  3. data/README.md +30 -28
  4. data/examples/rails4_root/Gemfile +19 -0
  5. data/examples/rails4_root/Gemfile.lock +180 -0
  6. data/examples/rails4_root/README +5 -0
  7. data/examples/rails4_root/Rakefile +11 -0
  8. data/examples/rails4_root/app/controllers/application_controller.rb +3 -0
  9. data/examples/rails4_root/app/controllers/welcome_controller.rb +18 -0
  10. data/examples/rails4_root/app/helpers/application_helper.rb +2 -0
  11. data/examples/rails4_root/app/mailers/user_mailer.rb +39 -0
  12. data/examples/rails4_root/app/models/user.rb +2 -0
  13. data/examples/rails4_root/app/views/user_mailer/email_with_attachment.html.erb +6 -0
  14. data/examples/rails4_root/app/views/user_mailer/newsletter.html.erb +8 -0
  15. data/examples/rails4_root/app/views/user_mailer/signup.html.erb +4 -0
  16. data/examples/rails4_root/app/views/user_mailer/signup.text.erb +4 -0
  17. data/examples/rails4_root/app/views/welcome/attachments.html.erb +0 -0
  18. data/examples/rails4_root/app/views/welcome/confirm.html.erb +1 -0
  19. data/examples/rails4_root/app/views/welcome/index.html.erb +8 -0
  20. data/examples/rails4_root/app/views/welcome/newsletter.html.erb +0 -0
  21. data/examples/rails4_root/app/views/welcome/signup.html.erb +1 -0
  22. data/examples/rails4_root/attachments/document.pdf +0 -0
  23. data/examples/rails4_root/attachments/image.png +0 -0
  24. data/examples/rails4_root/config.ru +4 -0
  25. data/examples/rails4_root/config/application.rb +45 -0
  26. data/examples/rails4_root/config/boot.rb +14 -0
  27. data/examples/rails4_root/config/cucumber.yml +8 -0
  28. data/examples/rails4_root/config/database.yml +25 -0
  29. data/examples/rails4_root/config/environment.rb +6 -0
  30. data/examples/rails4_root/config/environments/development.rb +19 -0
  31. data/examples/rails4_root/config/environments/production.rb +42 -0
  32. data/examples/rails4_root/config/environments/test.rb +32 -0
  33. data/examples/rails4_root/config/initializers/backtrace_silencers.rb +7 -0
  34. data/examples/rails4_root/config/initializers/cookie_verification_secret.rb +7 -0
  35. data/examples/rails4_root/config/initializers/delayed_job.rb +1 -0
  36. data/examples/rails4_root/config/initializers/inflections.rb +10 -0
  37. data/examples/rails4_root/config/initializers/mime_types.rb +5 -0
  38. data/examples/rails4_root/config/initializers/notifier_job.rb +1 -0
  39. data/examples/rails4_root/config/initializers/rspec_generator.rb +6 -0
  40. data/examples/rails4_root/config/initializers/session_store.rb +10 -0
  41. data/examples/rails4_root/config/locales/en.yml +5 -0
  42. data/examples/rails4_root/config/routes.rb +7 -0
  43. data/examples/rails4_root/config/secrets.yml +22 -0
  44. data/examples/rails4_root/db/migrate/20090125013728_create_users.rb +11 -0
  45. data/examples/rails4_root/db/migrate/20090908054656_create_delayed_jobs.rb +20 -0
  46. data/examples/rails4_root/db/migrate/20141119224309_add_queue_to_delayed_jobs.rb +9 -0
  47. data/examples/rails4_root/db/schema.rb +35 -0
  48. data/examples/rails4_root/db/seeds.rb +7 -0
  49. data/examples/rails4_root/db/test.sqlite3 +0 -0
  50. data/examples/rails4_root/doc/README_FOR_APP +2 -0
  51. data/examples/rails4_root/features/attachments.feature +27 -0
  52. data/examples/rails4_root/features/delayed_job.feature +13 -0
  53. data/examples/rails4_root/features/errors.feature +40 -0
  54. data/examples/rails4_root/features/example.feature +93 -0
  55. data/examples/rails4_root/features/step_definitions/email_steps.rb +210 -0
  56. data/examples/rails4_root/features/step_definitions/user_steps.rb +26 -0
  57. data/examples/rails4_root/features/step_definitions/web_steps.rb +219 -0
  58. data/examples/rails4_root/features/support/env.rb +59 -0
  59. data/examples/rails4_root/features/support/env_ext.rb +4 -0
  60. data/examples/rails4_root/features/support/paths.rb +33 -0
  61. data/examples/rails4_root/lib/notifier_job.rb +5 -0
  62. data/examples/rails4_root/lib/tasks/cucumber.rake +65 -0
  63. data/examples/rails4_root/lib/tasks/rspec.rake +69 -0
  64. data/examples/rails4_root/log/development.log +0 -0
  65. data/examples/rails4_root/log/test.log +43813 -0
  66. data/examples/rails4_root/public/404.html +26 -0
  67. data/examples/rails4_root/public/422.html +26 -0
  68. data/examples/rails4_root/public/500.html +26 -0
  69. data/examples/rails4_root/public/favicon.ico +0 -0
  70. data/examples/rails4_root/public/images/rails.png +0 -0
  71. data/examples/rails4_root/public/javascripts/application.js +2 -0
  72. data/examples/rails4_root/public/javascripts/controls.js +965 -0
  73. data/examples/rails4_root/public/javascripts/dragdrop.js +974 -0
  74. data/examples/rails4_root/public/javascripts/effects.js +1123 -0
  75. data/examples/rails4_root/public/javascripts/prototype.js +4874 -0
  76. data/examples/rails4_root/public/javascripts/rails.js +109 -0
  77. data/examples/rails4_root/public/robots.txt +5 -0
  78. data/examples/rails4_root/script/cucumber +10 -0
  79. data/examples/rails4_root/script/delayed_job +5 -0
  80. data/examples/rails4_root/script/rails +9 -0
  81. data/examples/rails4_root/spec/controllers/welcome_controller_spec.rb +20 -0
  82. data/examples/rails4_root/spec/models/user_mailer_spec.rb +47 -0
  83. data/examples/rails4_root/spec/spec_helper.rb +20 -0
  84. data/examples/rails4_root/test/mailers/user_mailer_classic_test.rb +27 -0
  85. data/examples/rails4_root/test/mailers/user_mailer_spec_test.rb +29 -0
  86. data/examples/rails4_root/test/test_helper.rb +10 -0
  87. data/{rails_generators → examples/rails4_root/vendor/plugins/email_spec/rails_generators}/email_spec/email_spec_generator.rb +0 -0
  88. data/{rails_generators → examples/rails4_root/vendor/plugins/email_spec/rails_generators}/email_spec/templates/email_steps.rb +22 -18
  89. data/examples/sinatra_root/Gemfile +15 -0
  90. data/examples/sinatra_root/Gemfile.lock +95 -0
  91. data/examples/sinatra_root/config.ru +4 -0
  92. data/examples/sinatra_root/features/errors.feature +40 -0
  93. data/examples/sinatra_root/features/example.feature +93 -0
  94. data/examples/sinatra_root/features/step_definitions/email_steps.rb +210 -0
  95. data/examples/sinatra_root/features/step_definitions/user_steps.rb +26 -0
  96. data/examples/sinatra_root/features/step_definitions/web_steps.rb +219 -0
  97. data/examples/sinatra_root/features/support/env.rb +21 -0
  98. data/examples/sinatra_root/features/support/paths.rb +29 -0
  99. data/examples/sinatra_root/lib/example_sinatra_app.rb +45 -0
  100. data/features/rails4_app.feature +32 -0
  101. data/features/sinatra_app.feature +14 -0
  102. data/features/step_definitions/app_steps.rb +58 -0
  103. data/features/support/env.rb +16 -0
  104. data/lib/email_spec.rb +1 -1
  105. data/lib/email_spec/deliveries.rb +0 -1
  106. data/lib/email_spec/email_viewer.rb +1 -1
  107. data/lib/email_spec/helpers.rb +16 -5
  108. data/lib/email_spec/matchers.rb +2 -1
  109. data/lib/email_spec/version.rb +3 -0
  110. data/lib/generators/email_spec/steps/templates/email_steps.rb +24 -20
  111. data/spec/email_spec/email_viewer_spec.rb +20 -0
  112. data/spec/email_spec/helpers_spec.rb +316 -0
  113. data/spec/email_spec/mail_ext_spec.rb +34 -0
  114. data/spec/email_spec/matchers_spec.rb +513 -0
  115. data/spec/spec_helper.rb +24 -0
  116. metadata +161 -150
  117. data/lib/email_spec/background_processes.rb +0 -45
  118. 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
@@ -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'
@@ -79,7 +79,6 @@ module EmailSpec
79
79
  def mailer; ActionMailer::Base; end
80
80
  include EmailSpec::MailerDeliveries
81
81
  end
82
- include EmailSpec::BackgroundProcesses::Compatibility
83
82
  end
84
83
  end
85
84
 
@@ -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 3 / Mail
38
+ else # Rails 4 / Mail
39
39
  f.write(text_part.header.to_s + "\n")
40
40
  end
41
41
 
@@ -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
- raise RSpec::Expectations::ExpectationNotMetError, "Expected an open email but none was found. Did you forget to call open_email?" unless email
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
- mailbox_for(address) - read_emails_for(address)
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::Expectations::PositiveExpectationHandler.handle_matcher(email, matcher)
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=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
145
+ if textify_images(email.default_part_body) =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?(.*?)#{link_text}(.*?)[^<]*?</a>}
135
146
  URI.split($1)[5..-1].compact!.join("?").gsub("&amp;", "&")
136
147
  # sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
137
148
  else
@@ -57,7 +57,8 @@ module EmailSpec
57
57
 
58
58
  def matches?(email)
59
59
  @email = email
60
- @actual_recipients = address_array{ email.header[:to].addrs }.map(&:to_s).sort
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
 
@@ -0,0 +1,3 @@
1
+ module EmailSpec
2
+ VERSION = '2.0.0'
3
+ end
@@ -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.should == parse_email_count(amount)
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.should == parse_email_count(amount)
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.should == parse_email_count(amount)
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.should == parse_email_count(amount)
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.should have_subject(text)
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.should have_subject(Regexp.new(text))
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.should include(text)
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.should =~ Regexp.new(text)
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.should be_delivered_from(text)
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.should have_header(name, text)
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.should have_header(name, Regexp.new(text))
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.should be_multipart
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.should include(text)
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.should include(text)
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.should == parse_email_count(amount)
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.should == parse_email_count(amount)
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.should == 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.should == parse_email_count(amount)
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.should include(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.should_not == 0
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