bmabey-email_spec 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Rakefile +13 -3
- data/examples/rails_root/db/schema.rb +2 -4
- data/examples/rails_root/features/example.feature +3 -2
- data/lib/email_spec/helpers.rb +22 -15
- data/lib/email_spec/matchers.rb +1 -1
- data/spec/email_spec/matchers_spec.rb +6 -0
- metadata +2 -3
data/History.txt
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
(In Git)
|
2
2
|
|
3
3
|
=== New features
|
4
|
+
=== Bufixes
|
5
|
+
|
6
|
+
== 0.1.0 2008-3-25
|
7
|
+
=== New features
|
8
|
+
* Change Rakefile to run all specs and features, as well as prepare the db (Mischa Fierer)
|
9
|
+
* Allow for array to be passed into deliver_to matcher. (Diego Carrion)
|
4
10
|
* Added matcher for checking if a collection of emails includes an email with a particular subject (Luke Melia, Noah Davis)
|
5
11
|
* Introduced hook to convert objects to email addresses (Luke Melia and Lee Bankewitz)
|
6
12
|
|
@@ -18,6 +24,7 @@
|
|
18
24
|
end
|
19
25
|
|
20
26
|
=== Bufixes
|
27
|
+
* Revert parse_email_for_link helper method to allow for text links as well as explicit link finding. (Mischa Fierer)
|
21
28
|
* Isolated variances between using email-spec with an ARMailer project. (Luke Melia)
|
22
29
|
|
23
30
|
|
data/Rakefile
CHANGED
@@ -33,9 +33,19 @@ task :generate do
|
|
33
33
|
system "cd #{current_dir}/examples/rails_root && ./script/generate email_spec"
|
34
34
|
end
|
35
35
|
|
36
|
-
task :
|
37
|
-
|
36
|
+
task :migrate do
|
37
|
+
system("cd examples/rails_root/ && rake db:test:prepare")
|
38
38
|
end
|
39
39
|
|
40
|
-
task :
|
40
|
+
task :features => :generate do
|
41
|
+
system("cucumber examples/rails_root/")
|
42
|
+
puts "4 steps should fail.\n\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
task :specs do
|
46
|
+
system("spec examples/rails_root -c --format nested")
|
47
|
+
system("spec spec -c --format nested")
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => [:migrate, :features, :specs]
|
41
51
|
|
@@ -12,10 +12,8 @@
|
|
12
12
|
ActiveRecord::Schema.define(:version => 20090125013728) do
|
13
13
|
|
14
14
|
create_table "users", :force => true do |t|
|
15
|
-
t.string
|
16
|
-
t.string
|
17
|
-
t.string "confirm_code"
|
18
|
-
t.datetime "confirmed_at"
|
15
|
+
t.string "email"
|
16
|
+
t.string "name"
|
19
17
|
end
|
20
18
|
|
21
19
|
end
|
@@ -26,7 +26,7 @@ Scenario: A new person signs up imperatively
|
|
26
26
|
And I should see "Quentin Jones" in the email
|
27
27
|
And I should see "Account confirmation" in the subject
|
28
28
|
|
29
|
-
When I follow "confirm" in the email
|
29
|
+
When I follow "Click here to confirm your account!" in the email
|
30
30
|
Then I should see "Confirm your new account"
|
31
31
|
|
32
32
|
|
@@ -43,7 +43,7 @@ Scenario: slightly more declarative, but still mostly imperative
|
|
43
43
|
When I open the email
|
44
44
|
Then I should see "Account confirmation" in the subject
|
45
45
|
|
46
|
-
When I follow "confirm" in the email
|
46
|
+
When I follow "http:///confirm" in the email
|
47
47
|
Then I should see "Confirm your new account"
|
48
48
|
|
49
49
|
|
@@ -56,3 +56,4 @@ Scenario: slightly more declarative, but still mostly imperative
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
+
|
data/lib/email_spec/helpers.rb
CHANGED
@@ -95,27 +95,34 @@ module EmailSpec
|
|
95
95
|
email_spec_hash[:current_email] = email
|
96
96
|
end
|
97
97
|
|
98
|
-
def parse_email_for_link(email,
|
99
|
-
email.should have_body_text(
|
100
|
-
|
98
|
+
def parse_email_for_link(email, text_or_regex)
|
99
|
+
email.should have_body_text(text_or_regex)
|
100
|
+
|
101
|
+
url = parse_email_for_explicit_link(email, text_or_regex)
|
102
|
+
url ||= parse_email_for_anchor_text_link(email, text_or_regex)
|
103
|
+
|
104
|
+
raise "No link found matching #{text_or_regex.inspect} in #{email}" unless url
|
105
|
+
url
|
106
|
+
end
|
107
|
+
|
108
|
+
# e.g. confirm in http://confirm
|
109
|
+
def parse_email_for_explicit_link(email, regex)
|
101
110
|
regex = /#{Regexp.escape(regex)}/ unless regex.is_a?(Regexp)
|
102
111
|
url = links_in_email(email).detect { |link| link =~ regex }
|
103
|
-
|
104
|
-
URI::parse(url).request_uri
|
105
|
-
#
|
106
|
-
# if link_text =~ %r{^/.*$}
|
107
|
-
# # if it's an explicit link
|
108
|
-
# link_text
|
109
|
-
# elsif email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
|
110
|
-
# # if it's an anchor tag
|
111
|
-
# URI.split($~[1])[5..-1].compact!.join("?").gsub("&", "&")
|
112
|
-
# # sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
|
113
|
-
# # TODO: outsource this kind of parsing to webrat or someone else
|
114
|
-
# end
|
112
|
+
URI::parse(url).request_uri if url
|
115
113
|
end
|
116
114
|
|
115
|
+
# e.g. Click here in <a href="http://confirm">Click here</a>
|
116
|
+
def parse_email_for_anchor_text_link(email, link_text)
|
117
|
+
email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
|
118
|
+
URI.split($~[1])[5..-1].compact!.join("?").gsub("&", "&")
|
119
|
+
# sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
|
120
|
+
end
|
121
|
+
|
122
|
+
|
117
123
|
def convert_address(address)
|
118
124
|
AddressConverter.instance.convert(address)
|
119
125
|
end
|
120
126
|
end
|
121
127
|
end
|
128
|
+
|
data/lib/email_spec/matchers.rb
CHANGED
@@ -32,7 +32,7 @@ module EmailSpec
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def deliver_to(*expected_email_addresses_or_objects_that_respond_to_email)
|
35
|
-
DeliverTo.new(expected_email_addresses_or_objects_that_respond_to_email)
|
35
|
+
DeliverTo.new(expected_email_addresses_or_objects_that_respond_to_email.flatten)
|
36
36
|
end
|
37
37
|
|
38
38
|
alias :be_delivered_to :deliver_to
|
@@ -59,6 +59,12 @@ describe EmailSpec::Matchers do
|
|
59
59
|
deliver_to("karen@yahoo.com").should_not match(email)
|
60
60
|
end
|
61
61
|
|
62
|
+
it "should match when an array of emails is exact same as all of the email's recipients" do
|
63
|
+
addresses = ["james@yahoo.com", "karen@yahoo.com"]
|
64
|
+
email = mock_email(:to => addresses)
|
65
|
+
deliver_to(addresses).should match(email)
|
66
|
+
end
|
67
|
+
|
62
68
|
it "should use the passed in objects :email method if not a string" do
|
63
69
|
email = mock_email(:to => "jimmy_bean@yahoo.com")
|
64
70
|
user = mock("user", :email => "jimmy_bean@yahoo.com")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmabey-email_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Mabey
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-
|
14
|
+
date: 2009-03-25 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -79,7 +79,6 @@ files:
|
|
79
79
|
- examples/rails_root/config/routes.rb
|
80
80
|
- examples/rails_root/cucumber.yml
|
81
81
|
- examples/rails_root/db
|
82
|
-
- examples/rails_root/db/development.sqlite3
|
83
82
|
- examples/rails_root/db/migrate
|
84
83
|
- examples/rails_root/db/migrate/20090125013728_create_users.rb
|
85
84
|
- examples/rails_root/db/schema.rb
|