mischa-email_spec 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -41,7 +41,15 @@ task :install_gem => [:clean, :package] do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# Testing
|
44
|
-
|
44
|
+
|
45
|
+
desc "Run the generator on the tests"
|
46
|
+
task :generate do
|
47
|
+
system "mkdir -p spec/rails_root/vendor/plugins/email_spec"
|
48
|
+
system "cp -R generators spec/rails_root/vendor/plugins/email_spec"
|
49
|
+
system "cd spec/rails_root; ./script/generate email_spec"
|
50
|
+
end
|
51
|
+
|
52
|
+
task :features => [:generate] do
|
45
53
|
system("cd spec/rails_root; rake features; cd ../..")
|
46
54
|
end
|
47
55
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# This generator adds email steps to the step definitions directory
|
2
2
|
class EmailSpecGenerator < Rails::Generator::Base
|
3
|
-
#DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
4
|
-
# Config::CONFIG['ruby_install_name'])
|
5
3
|
def manifest
|
6
4
|
record do |m|
|
7
5
|
m.directory 'features/step_definitions'
|
@@ -1,29 +1,26 @@
|
|
1
|
+
#Commonly used email steps
|
2
|
+
|
3
|
+
# Use this step to reset the e-mail queue within a scenario.
|
4
|
+
# This is done automatically before each scenario.
|
1
5
|
Given /^(?:a clear email queue|no emails have been sent)$/ do
|
2
6
|
reset_mailer
|
3
7
|
end
|
4
8
|
|
5
|
-
#
|
6
|
-
#
|
9
|
+
# Use this step to open the most recently sent e-mail.
|
7
10
|
When /^I open the email$/ do
|
8
|
-
open_last_email
|
11
|
+
open_last_email
|
9
12
|
end
|
10
13
|
|
11
|
-
When /^I follow "(.*)" in the email$/ do |
|
12
|
-
|
13
|
-
link = parse_email_for_link(current_email, link_text)
|
14
|
-
visit(link)
|
14
|
+
When /^I follow "(.*)" in the email$/ do |link|
|
15
|
+
visit_in_email(link)
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
link = parse_email_for_link(current_email, link_text)
|
20
|
-
visit(link)
|
18
|
+
Then /^"([^']*?)" should receive (\d+) emails?$/ do |email, n|
|
19
|
+
unread_emails_for(email).size.should == n.to_i
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
Then /^"([^']*?)" should receive (\d+) emails?$/ do |email, n|
|
26
|
-
unread_emails_for(email).size.should == n.to_i
|
22
|
+
Then /^I should receive (\d+) emails?$/ do |n|
|
23
|
+
unread_emails_for(current_email).size.should == n.to_i
|
27
24
|
end
|
28
25
|
|
29
26
|
Then /^"([^']*?)" should have (\d+) emails?$/ do |email, n|
|
@@ -35,13 +32,13 @@ Then /^"([^']*?)" should not receive an email$/ do |email|
|
|
35
32
|
end
|
36
33
|
|
37
34
|
Then /^I should see "(.*)" in the subject$/ do |text|
|
38
|
-
raise ArgumentError, "To check the subject, you must first open an e-mail" if current_email.nil?
|
39
|
-
current_email.should_not be_nil
|
35
|
+
# raise ArgumentError, "To check the subject, you must first open an e-mail" if current_email.nil?
|
36
|
+
# current_email.should_not be_nil
|
40
37
|
current_email.subject.should =~ Regexp.new(text)
|
41
38
|
end
|
42
39
|
|
43
40
|
Then /^I should see "(.*)" in the email$/ do |text|
|
44
|
-
current_email.should_not be_nil
|
41
|
+
# current_email.should_not be_nil
|
45
42
|
current_email.body.should =~ Regexp.new(text)
|
46
43
|
end
|
47
44
|
|
@@ -17,6 +17,10 @@ module EmailSpec
|
|
17
17
|
def reset_mailer
|
18
18
|
ActionMailer::Base.deliveries.clear
|
19
19
|
end
|
20
|
+
|
21
|
+
def visit_in_email(link_text)
|
22
|
+
visit(parse_email_for_link(current_email, link_text))
|
23
|
+
end
|
20
24
|
|
21
25
|
def open_email(email_address, opts={})
|
22
26
|
if opts[:with_subject]
|
@@ -34,6 +38,7 @@ module EmailSpec
|
|
34
38
|
|
35
39
|
def open_last_email
|
36
40
|
email = ActionMailer::Base.deliveries.last
|
41
|
+
raise "Last email was nil" unless email #TODO: fix
|
37
42
|
read_emails_for(email.to) << email if email
|
38
43
|
@email_spec_hash[:current_emails][email.to] = email
|
39
44
|
@email_spec_hash[:current_email] = email
|
@@ -62,7 +67,9 @@ module EmailSpec
|
|
62
67
|
link_text
|
63
68
|
elsif mail.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
|
64
69
|
# if it's an anchor tag
|
65
|
-
URI.split($~[1])[5..-1].compact!.join("?")
|
70
|
+
URI.split($~[1])[5..-1].compact!.join("?").gsub("&", "&")
|
71
|
+
# sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
|
72
|
+
# TODO: outsource this kind of parsing to webrat or someone else
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
data/lib/email_spec.rb
CHANGED