Skip to content

Commit

Permalink
'Then show me the email' works as expected now [#18 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Apr 5, 2010
1 parent e819a3b commit c4f3db0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
pkg
doc/*
.yardoc
webrat*
pickle-email*
cucumber_test_app
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
== 0.2.8 - 5 Apr 2010

* 1 minor improvement
* 'Then show me the email' works as expected now [#18]

== 0.2.7 - 5 Apr 2010

* 1 minor improvement
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -30,7 +30,7 @@ end
namespace :rcov do
desc "Verify RCov threshold for #{PluginName}"
RCov::VerifyTask.new(:verify => :rcov) do |t|
t.threshold = 99.23
t.threshold = 98.67
t.index_html = File.join(File.dirname(__FILE__), 'doc/coverage/index.html')
end
end
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2.7
0.2.8
4 changes: 4 additions & 0 deletions features/email/email.feature
Expand Up @@ -58,3 +58,7 @@ Feature: I can test emails are sent
Then 1 email should be delivered to the user
And I follow "example page" in the email
Then I should be at the user's page

Scenario: Save and open email
Given an email "Gday" with body: "Gday Mate" is delivered to fred@gmail.com
Then show me the email
9 changes: 8 additions & 1 deletion lib/pickle/email.rb
Expand Up @@ -30,11 +30,18 @@ def click_first_link_in_email(email)
end

protected
def open_in_browser(path) # :nodoc
require "launchy"
Launchy::Browser.run(path)
rescue LoadError
warn "Sorry, you need to install launchy to open emails: `gem install launchy`"
end

# Saves the emails out to RAILS_ROOT/tmp/ and opens it in the default
# web browser if on OS X. (depends on webrat)
def save_and_open_emails
emails_to_open = @emails || emails
filename = "webrat-email-#{Time.now.to_i}.html"
filename = "pickle-email-#{Time.now.to_i}.html"
File.open(filename, "w") do |f|
emails_to_open.each_with_index do |e, i|
f.write "<h1>Email #{i+1}</h1><pre>#{e}</pre><hr />"
Expand Down
5 changes: 2 additions & 3 deletions spec/pickle/email_spec.rb
Expand Up @@ -102,7 +102,6 @@

describe "#save_and_open_emails" do
before do
stub!(:open_in_browser)
stub!(:emails).and_return(["Contents of Email 1"])
@now = "2008-01-01".to_time
Time.stub!(:now).and_return(@now)
Expand All @@ -124,11 +123,11 @@

it "should create a file in Rails/tmp with the emails in it" do
save_and_open_emails
File.read("webrat-email-#{@now.to_i}.html").should == "<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />"
File.read("pickle-email-#{@now.to_i}.html").should == "<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />"
end

it "should call open_in_browser on created tmp file" do
should_receive(:open_in_browser).with("webrat-email-#{@now.to_i}.html")
should_receive(:open_in_browser).with("pickle-email-#{@now.to_i}.html")
save_and_open_emails
end
end
Expand Down

0 comments on commit c4f3db0

Please sign in to comment.